I'm trying to send AMQP 1.0 messages to a running Qpid Broker-J instance from within the browser with rhea.js. I was able to send and receive messages with the node.js version.
I think I'll have to add/activate the Websocket Plugin, I just can't find any documentation on where and how to do that.
Has anybody done that so far?
Here is my browser version snippet:
var server = "ws://localhost:5673";
var client = require("rhea");
client.options.username = "guest";
client.options.password = "guest";
client.on("message", function (context) {
console.log(context.message.body);
});
var ws = client.websocket_connect(WebSocket);
var connection = client.connect({"connection_details":ws(server, ["binary", "AMQPWSB10", "amqp"]), "reconnect":false});
connection.open_receiver("examples");
var sender = connection.open_sender("examples");
function send(body) {
sender.send({ body });
}
function sendMessage() {
console.log("sendMessage");
const message = document.getElementById("message").value;
send(message);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/rhea.js"></script>
</head>
<body>
<div>
<input type="text" id="message" />
<button type="button" onClick="sendMessage()" />send</button>
</div>
</body>
</html>
Using this script I receive Error during Websocket handshake
:
WebSocket connection to 'ws://localhost:5673/' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET