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

Unable to subscribe on topic using @stomp/stompjs #18

Closed
akarasev opened this issue Oct 23, 2018 · 5 comments
Closed

Unable to subscribe on topic using @stomp/stompjs #18

akarasev opened this issue Oct 23, 2018 · 5 comments

Comments

@akarasev
Copy link

Hello,

I'm not sure if this is an issue with stomp-js, but I'm unable to subscribe on any topic.

Could you please help me to resolve the problem?

Thanks!

@kum-deepak
Copy link
Member

You definitely do not have a network connectivity issue, the broker has sent a reasonable response (the CONNECTED frame).

I need some basic details - which broker and which browser are you using?

Please create a minimal sample showing this problem to help in resolving this.

@akarasev
Copy link
Author

akarasev commented Oct 24, 2018

@kum-deepak thanks for your response!

Here is the sample .

Broker is Spring's simple broker.

Browser is Google Chrome 70.0.3538.67.

I'm able to publish messages there, but subscription still doesn't work for me.

Kindly let me know, if you'll see any problem there.

@kum-deepak
Copy link
Member

There was a mixup in syntax, part of the syntax is v4 syntax while part is v5. I have converted totally to v5 syntax and it seems to work.

Modified code:

  componentDidMount() {
    console.log('Component did mount');
    // The compat mode syntax is totally different, converting to v5 syntax
    // Client is imported from '@stomp/stompjs'
    this.client = new Client();

    this.client.configure({
      brokerURL: 'ws://localhost:8080/stomp',
      onConnect: () => {
        console.log('onConnect');

        this.client.subscribe('/queue/now', message => {
          console.log(message);
          this.setState({serverTime: message.body});
        });

        this.client.subscribe('/topic/greetings', message => {
          alert(message.body);
        });
      },
      // Helps during debugging, remove in production
      debug: (str) => {
        console.log(new Date(), str);
      }
    });

    this.client.activate();
  }

@kum-deepak
Copy link
Member

Please see akarasev/stomp-spring-react#1

Let me know if it works for you. Also, can I use your code as base for a sample?

@akarasev
Copy link
Author

Works like a charm!

Use my code whatever you need and thank you very much!

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