'Unable to open direct websocket connection (without stomp) to amazonmq
I'm trying to connect to the WebSocket endpoint on AmazonMQ (ActiveMQ) from a webpage (hosted on HTTPS).
let wsURL = "wss://url_to_mq:61619";
let wssConn = new WebSocket(wsURL);
This reports a failure to connect to the WebSocket.
On AmazonMQ, I defined port 61619 to be open to all IPs in the security group.
How can I utilize the wss endpoint from the AmazonMQ dashboard to directly connect from my website to ActiveMQ?
Solution 1:[1]
After further exploration, it appears that only stomp fully negotiates (and authenticates) the connection of a Websocket from a js-based frontend to an Amazonmq (ActiveMQ) backend. The WSS endpoints are passed directly to the stomp client in the following manner given that stomp.js is added to the page:
var client = Stomp.client(WS_URL);
let login = "username";
let passcode = "password";
function connectCallback() {
console.log("Connected.");
}
function errorCallback(error) {
console.log(error, "Error Connecting.");
}
function closeEventCallback () {
console.log("Closed.");
}
client.connect(login, passcode, connectCallback, errorCallback,
closeEventCallback);
I hope this helps the next individual seeking this solution and may be confused as to why the WSS endpoints do not directly work with a direct WebSocket instantiation.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
