Open jodinathan opened 5 years ago
Hi @jodinathan, I was in the same pool a couple of days back, this plugin now seems to be unmaintained.
The closest I could make it work was using an external file mentioned in this comment. (https://github.com/rikulo/stomp/issues/19#issuecomment-448307251). Here is an example, please see if this helps you // Add these two dependencies
stomp: ^0.8.0 web_socket_channel: ^1.0.12
//Import custom.dart file provided in the above comment eg: import './src/utils/custom.dart' as custom;
Then you can use the plugin as follows:
custom .connect("ws://localhost:8080/gs-guide-websocket") .then((StompClient client) { client.subscribeString("uniqueId", "/topic/greetings", (Map<String, String> headers, String message) { print("Recieve $message"); }); client.sendString("/app/hello", '{"name" : "Saurabh"}', headers: {'content-type': 'application/json'}); });
Here the path "/gs-guide-websocket" is the stomp endpoint configured in the server (https://spring.io/guides/gs/messaging-stomp-websocket/). Replace localhost:8080 with your server url. The "uniqueId" helps you to unsubscribe the endpoint.
Please note: This plugin does not support heartbeat functionality so the websocket connection gets disconnected in few seconds, I am yet to figure out a workaround for this.
@saurabhgour I dug the code and the lib supports server-side heartbeat. I am using RabbitMQ but I think spring probably work.
_numsListen() {
String url = 'ws://127.0.0.1:15674/ws';
print('Connecting to the stomp server: $url');
stomp.connect(url,
login: 'guest', passcode: 'guest', onDisconnect: (e){
print('DISCONNECTING STOMP');
_numsListen();
}, heartbeat: [0, 10000]).then((StompClient client) {
client.subscribeString(unid, '/exchange/$pointsKey',
(Map<String, String> headers, String message) {
print("Recieve $message");
});
}, onError: (e){
print('ERROR STOMP, $e');
Future.delayed(Duration(seconds: 1)).then((e) => _numsListen());
});
}
@jodinathan Hey, is the recursive call to _numsListen() needed here? Should'nt the hearbeat functionality make sure that the socket does not get disconnected?
@saurabhgour, it prevents from disconnecting by inactivity timeout, not internet disconnections
I know it is obvious to you what
String id
is in thesubscribeString(id, dest, fn)
is, however, for me that is very new to stomp stuff (and rabbitmq altogether), I have to dig source and guess what it is.Is ID a uniqueId that I must generate?