Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zhongl/stompize
A java STOMP framework.
https://github.com/zhongl/stompize
Last synced: 5 days ago
JSON representation
A java STOMP framework.
- Host: GitHub
- URL: https://github.com/zhongl/stompize
- Owner: zhongl
- License: apache-2.0
- Created: 2013-02-27T03:01:18.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2021-02-27T06:02:35.000Z (almost 4 years ago)
- Last Synced: 2024-11-01T20:03:32.492Z (about 2 months ago)
- Language: Java
- Size: 106 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Code as Specification.
Stompize is a java [STOMP][1] framework, it could help you build or enhance your [STOMP][1] application more easier and readable.
For example, suppose your [STOMP][1] specification has defined two command: `SEND` and `RECEIPT`, you can write java code like below without any document:
```java
public interface Stomp extends Specification {
@Command(optionals = {Transaction.class, Receipt.class})
void send(Destination destination, Text content, Header... optionals);@Command
void receipt(ReceiptId receiptId);class Text extends Content { ... }
class Destination extends Header { ... }
class Transaction extends Header { ... }
class Receipt extends Header { ... }
class ReceiptId extends Header { ... }
}
```Then, you can code the `Client`:
```java
public abstract class Client extends Stompizeble implements Stomp {private final Function channel; // channel to communicate with server.
protected Client(Function channel) { this.channel = channel; }
@Override
public void receipt(@Optional("receipt-id") String id) {
channel.apply(join("RECEIPT", receiptId)); // receive receipt from server.
}@Override
protected void out(String command, Iterable headers, Content> content) {
channel.apply(...); // send a frame to server
}}
```Caution, `Client` is `abstract`, because Stompize will help you override abstract methods declared at `Stomp`, eg: send(...).
A simple unit test could let you figure it out:
```java
@Test
public void shouldOutputFrameWithContent() throws Exception {
Function output = mock(Function.class);
Stomp client = Stompize.create(Stomp.class, Client.class, output);Destination d = new Destination("d");
client.send(d, new Stomp.Text("content"));verify(output).apply("[SEND, [[\ndestination:d], \n\ncontent\u0000]]");
}@Test
public void shouldCallbackCommand() throws Exception {
Function output = mock(Function.class);
Stompizeble stompizeble = (Stompizeble) Stompize.create(Stomp.class, Client.class, output);stompizeble.apply("RECEIPT", Collections.singletonMap("receipt-id","1"), null);
verify(output).apply("[RECEIPT, 1]");
}```
Easy right?! So let's stompize your application!
You can get more help from unit test cases:
- [core](https://github.com/zhongl/stompize/tree/master/core/src/test/java/com/github/zhongl/stompize)
- [stomp](https://github.com/zhongl/stompize/tree/master/stomp/src/test/java/com/github/zhongl/stompize)[1]:http://stomp.github.com/index.html