Skip to content

Instantly share code, notes, and snippets.

@riccardodivirgilio
Created September 8, 2020 16:32
Show Gist options
  • Save riccardodivirgilio/b92c367e790d525d12bb9ecacf856f99 to your computer and use it in GitHub Desktop.
Save riccardodivirgilio/b92c367e790d525d12bb9ecacf856f99 to your computer and use it in GitHub Desktop.
const StompJs = require("@stomp/stompjs");
const client = new StompJs.Client({
brokerURL: "ws://localhost:15674/ws",
connectHeaders: {
login: "user_1",
passcode:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtb2RlIiA6ICJydyIsICJjaGFubmVsIiA6ICIxIiwgInJvbGUiIDogIndlYnVzZXIiLCAidXNlcl9pZCIgOiAxLCAiZXhwIiA6IDE1OTkzNDUzNzJ9.HLYr22YUZ6XjocHo0EuxuWuhX6AT7qygOrkB4GZo1nY"
},
debug: str => console.log(str),
reconnectDelay: 5000,
heartbeatIncoming: 4000,
heartbeatOutgoing: 4000
});
client.onConnect = function() {
// Do something, all subscribes must be done is this callback
// This is needed because this will be executed after a (re)connect
client.subscribe("/exchange/amq.topic/#.user-1.#", e => console.log(e));
};
client.onStompError = frame => {
// Will be invoked in case of error encountered at Broker
// Bad login/passcode typically will cause an error
// Complaint brokers will set `message` header with a brief message. Body may contain details.
// Compliant brokers will terminate the connection after any error
console.log("Broker reported error: " + frame.headers["message"]);
console.log("Additional details: " + frame.body);
};
client.activate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment