Skip to content

Commit 4f7e7a8

Browse files
committed
Add readme
1 parent 72b6960 commit 4f7e7a8

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Nickolay
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# STOMP protocol via WebSocket for Android
2+
3+
[![Release](https://jitpack.io/v/NaikSoftware/StompProtocolAndroid.svg)](https://jitpack.io/#NaikSoftware/StompProtocolAndroid)
4+
5+
## Overview
6+
7+
This library provide support for STOMP protocol https://stomp.github.io/
8+
At now library works only as client for backend with support STOMP, such as
9+
NodeJS (stompjs or other) or Spring Boot (SockJS).
10+
11+
Add library as gradle dependency
12+
13+
```gradle
14+
repositories {
15+
jcenter()
16+
maven { url "https://jitpack.io" }
17+
}
18+
dependencies {
19+
compile 'com.github.NaikSoftware:StompProtocolAndroid:{latest version}'
20+
}
21+
```
22+
23+
## Example backend (Spring Boot)
24+
25+
**WebSocketConfig.groovy**
26+
```groovy
27+
@Configuration
28+
@EnableWebSocketMessageBroker
29+
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
30+
31+
@Override
32+
public void configureMessageBroker(MessageBrokerRegistry config) {
33+
config.enableSimpleBroker("/topic");
34+
config.setApplicationDestinationPrefixes("/app");
35+
}
36+
37+
@Override
38+
public void registerStompEndpoints(StompEndpointRegistry registry) {
39+
registry.addEndpoint("/hello")/*.setAllowedOrigins('*')*/.withSockJS();
40+
}
41+
42+
}
43+
```
44+
45+
**HelloSockController.groovy**
46+
``` groovy
47+
@RestController
48+
class HelloSockController {
49+
50+
@MessageMapping("/hello")
51+
@SendTo("/topic/greetings")
52+
def greeting(String msg) throws Exception {
53+
println("Receive greeting ${msg}")
54+
"ECHO: " + msg;
55+
}
56+
}
57+
```
58+
59+
## Example library usage
60+
61+
**Basic usage**
62+
``` java
63+
private StompClient mStompClient;
64+
65+
// ...
66+
67+
mStompClient = Stomp.over(WebSocket.class, "ws://localhost:8080/app/hello/websocket");
68+
mStompClient.connect();
69+
70+
mStompClient.topic("/topic/greetings").subscribe(topicMessage -> {
71+
Log.d(TAG, topicMessage.getPayload());
72+
});
73+
74+
mStompClient.send("/app/hello", "My first STOMP message!").subscribe();
75+
76+
// ...
77+
78+
mStompClient.disconnect();
79+
80+
```
81+
82+
Method `Stomp.over` consume class for create connection as first parameter.
83+
You must provide dependency for lib and pass class.
84+
At now supported connection providers:
85+
- WebSocket.class ('org.java-websocket:Java-WebSocket:1.3.0')
86+
87+
You can add own connection provider. Just implement interface `ConnectionProvider`.
88+
If you implement new provider, please create pull request :)
89+
90+
**Subscribe lifecycle connection**
91+
``` java
92+
mStompClient.lifecycle().subscribe(lifecycleEvent -> {
93+
switch (lifecycleEvent.getType()) {
94+
95+
case OPENED:
96+
Log.d(TAG, "Stomp connection opened");
97+
break;
98+
99+
case ERROR:
100+
Log.e(TAG, "Error", lifecycleEvent.getException());
101+
break;
102+
103+
case CLOSED:
104+
Log.d(TAG, "Stomp connection closed");
105+
break;
106+
}
107+
});
108+
```
109+
110+
Library support just send & receive messages. ACK messages, transactions not implemented yet.

0 commit comments

Comments
 (0)