Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples do not work #26

Open
jodinathan opened this issue Apr 2, 2019 · 4 comments
Open

Examples do not work #26

jodinathan opened this issue Apr 2, 2019 · 4 comments

Comments

@jodinathan
Copy link

I know it is obvious to you what String id is in the subscribeString(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?

@saurabhgour
Copy link

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. (#19 (comment)). 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.

@jodinathan
Copy link
Author

@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());
    });
  }

@saurabhgour
Copy link

@jodinathan Hey, is the recursive call to _numsListen() needed here? Should'nt the hearbeat functionality make sure that the socket does not get disconnected?

@jodinathan
Copy link
Author

jodinathan commented Apr 3, 2019

@saurabhgour, it prevents from disconnecting by inactivity timeout, not internet disconnections

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants