Created
September 8, 2020 16:32
-
-
Save riccardodivirgilio/b92c367e790d525d12bb9ecacf856f99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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