11# STOMP protocol via WebSocket for Android
22
3- [ ![ Release] ( https://jitpack.io/v/NaikSoftware /StompProtocolAndroid.svg )] ( https://jitpack.io/#NaikSoftware /StompProtocolAndroid )
3+ [ ![ Release] ( https://jitpack.io/v/forresthopkinsa /StompProtocolAndroid.svg )] ( https://jitpack.io/#forresthopkinsa /StompProtocolAndroid )
44
55## Overview
66
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).
7+ ** Note that this is a FORK of a project by NaikSoftware! This version is purely to avoid using RetroLambda!**
108
11- Add library as gradle dependency
9+ This library provides support for [ STOMP protocol] ( https://stomp.github.io/ ) over Websockets.
10+
11+ At now library works only as client for any backend that supports STOMP, such as
12+ NodeJS (e.g. using StompJS) or Spring Boot ([ with WebSocket support] ( https://spring.io/guides/gs/messaging-stomp-websocket/ ) ).
13+
14+ Add library as gradle dependency (Versioning info [ here] ( https://jitpack.io/#forresthopkinsa/StompProtocolAndroid ) ):
1215
1316``` gradle
1417repositories {
1518 jcenter()
1619 maven { url "https://jitpack.io" }
1720}
1821dependencies {
19- compile 'com.github.NaikSoftware :StompProtocolAndroid:{latest version}'
22+ compile 'com.github.forresthopkinsa :StompProtocolAndroid:{latest version}'
2023}
2124```
2225
26+ You can use this library two ways:
27+
28+ - Using the old JACK toolchain
29+ - If you have Java 8 compatiblity and Jack enabled, this library will work for you
30+ - Using the new Native Java 8 support
31+ - As of this writing, you must be using Android Studio Canary to use this feature.
32+ - You can find more info on the [ Releases Page] ( https://github.com/forresthopkinsa/StompProtocolAndroid/releases )
33+
34+ However, * this fork is NOT compatible with Retrolambda.*
35+ If you have RL as a dependency, then you should be using the [ upstream version] ( https://github.com/NaikSoftware/StompProtocolAndroid ) of this project!
36+
2337## Example backend (Spring Boot)
2438
25- ** WebSocketConfig.groovy **
26- ``` groovy
39+ ** WebSocketConfig.java **
40+ ``` java
2741@Configuration
2842@EnableWebSocket
2943@EnableWebSocketMessageBroker
3044class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
3145
3246 @Override
33- void configureMessageBroker(MessageBrokerRegistry config) {
34- config.enableSimpleBroker("/topic", "/queue", "/exchange");
35- // config.enableStompBrokerRelay ("/topic", "/queue", "/exchange"); // Uncomment for external message broker (ActiveMQ, RabbitMQ)
36- config.setApplicationDestinationPrefixes("/topic", "/queue"); // prefix in client queries
37- config.setUserDestinationPrefix ("/user ");
47+ public void configureMessageBroker (MessageBrokerRegistry config ) {
48+ // We're using Spring's built-in message broker, with prefix "/topic"
49+ config. enableSimpleBroker (" /topic" );
50+ // This is the prefix for client requests
51+ config. setApplicationDestinationPrefixes (" /app " );
3852 }
3953
4054 @Override
41- void registerStompEndpoints(StompEndpointRegistry registry) {
42- registry.addEndpoint("/example-endpoint").withSockJS()
55+ public void registerStompEndpoints (StompEndpointRegistry registry ) {
56+ registry. addEndpoint(" /example-endpoint" );
4357 }
4458}
4559```
4660
47- ** SocketController.groovy**
48- ``` groovy
49- @Log4j
61+ ** SocketController.java**
62+ ``` java
5063@RestController
5164class SocketController {
5265
53- @MessageMapping('/hello-msg-mapping ')
66+ @MessageMapping (' /hello' )
5467 @SendTo (' /topic/greetings' )
55- EchoModel echoMessageMapping(String message) {
56- log.debug("React to hello-msg-mapping")
57- return new EchoModel(message.trim())
68+ public String greeting (String name ) {
69+ return " Hello, " + name + " !" ;
5870 }
5971}
6072```
@@ -65,24 +77,30 @@ Check out the full example server https://github.com/NaikSoftware/stomp-protocol
6577
6678** Basic usage**
6779``` java
68- import org.java_websocket.WebSocket ;
69-
70- private StompClient mStompClient;
80+ import okhttp3.OkHttpClient ;
81+ import okhttp3.Request ;
82+ import okhttp3.Response ;
83+ import okhttp3.WebSocket ;
84+ import okhttp3.WebSocketListener ;
7185
7286 // ...
7387
74- mStompClient = Stomp . over(WebSocket . class, " ws ://10.0.2.2:8080 /example-endpoint/websocket " );
75- mStompClient . connect();
88+ StompClient client = Stomp . over(WebSocket . class, " http ://localhost /example-endpoint" );
89+ client . connect();
7690
77- mStompClient . topic(" /topic/greetings" ). subscribe(topicMessage - > {
78- Log . d (TAG , topicMessage . getPayload());
91+ client . topic(" /topic/greetings" ). subscribe(message - > {
92+ Log . i (TAG , " Received message: " + message . getPayload());
7993 });
8094
81- mStompClient. send(" /topic/hello-msg-mapping" , " My first STOMP message!" ). subscribe();
95+ client. send(" /app/hello" , " world" ). subscribe(
96+ aVoid - > Log . d(TAG , " Sent data!" ),
97+ error - > Log . e(TAG , " Encountered error while sending data!" , error)
98+ );
8299
83100 // ...
84-
85- mStompClient. disconnect();
101+
102+ // close socket connection when finished or exiting
103+ client. disconnect();
86104
87105```
88106
@@ -91,30 +109,47 @@ See the full example https://github.com/NaikSoftware/StompProtocolAndroid/tree/m
91109Method ` Stomp.over ` consume class for create connection as first parameter.
92110You must provide dependency for lib and pass class.
93111At now supported connection providers:
94- - ` org.java_websocket.WebSocket.class ` ('org.java-websocket:Java-WebSocket:1.3.0 ')
95- - ` okhttp3.WebSocket.class ` ('com.squareup.okhttp3:okhttp:3.8.0 ')
112+ - ` org.java_websocket.WebSocket.class ` ('org.java-websocket:Java-WebSocket:1.3.2 ')
113+ - ` okhttp3.WebSocket.class ` ('com.squareup.okhttp3:okhttp:3.8.1 ')
96114
97115You can add own connection provider. Just implement interface ` ConnectionProvider ` .
98116If you implement new provider, please create pull request :)
99117
100118** Subscribe lifecycle connection**
101119``` java
102- mStompClient . lifecycle(). subscribe(lifecycleEvent - > {
120+ client . lifecycle(). subscribe(lifecycleEvent - > {
103121 switch (lifecycleEvent. getType()) {
104-
105122 case OPENED :
106123 Log . d(TAG , " Stomp connection opened" );
107124 break ;
108-
109- case ERROR :
110- Log . e(TAG , " Error" , lifecycleEvent. getException());
111- break ;
112-
113125 case CLOSED :
114126 Log . d(TAG , " Stomp connection closed" );
115127 break ;
128+ case ERROR :
129+ Log . e(TAG , " Stomp connection error" , lifecycleEvent. getException());
130+ break ;
116131 }
117132});
118133```
119134
120- Library support just send & receive messages. ACK messages, transactions not implemented yet.
135+ ** Custom client**
136+
137+ You can use a custom HttpClient (for example, if you want to allow untrusted HTTPS) using the four-argument overload of Stomp.over, like so:
138+
139+ ``` java
140+ client = Stomp . over(WebSocket . class, address, null , unsafeClient);
141+ ```
142+
143+ Yes, it's safe to pass ` null ` for either (or both) of the last two arguments. That's exactly what the shorter overloads do.
144+
145+ ** Support**
146+
147+ Right now, the library only supports sending and receiving messages. ACK messages and transactions are not implemented yet.
148+
149+ ** Additional Reading**
150+
151+ - [ Spring + Websockets + STOMP] ( https://spring.io/guides/gs/messaging-stomp-websocket/ )
152+ - [ STOMP Protocol] ( http://stomp.github.io/ )
153+ - [ Spring detailed documentation] ( https://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html#websocket-stomp )
154+ - [ Create an Unsafe OkHttp Client] ( https://gist.github.com/grow2014/b6969d8f0cfc0f0a1b2bf12f84973dec )
155+ - (for developing with invalid SSL certs)
0 commit comments