2.3. 在浏览器中部署客户端
红帽构建的 Rhea 可在网页浏览器中运行。NPM 软件包在以下位置包含名为 rhea.js 的文件,该文件可用于基于浏览器的应用:
/usr/local/lib/node_modules/@redhat/rhea/dist/rhea.js
将 rhea.js 文件复制到 Web 服务器公开的位置,并使用 HTML < script> 元素引用它,如下例所示:
示例:在浏览器中运行客户端
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<script src="rhea.js"></script>
</head>
<body>
<script>
const rhea = require("rhea");
const container = rhea.create_container();
container.on("message", (event) => {
console.log(event.message.body);
});
const ws = container.websocket_connect(WebSocket);
const details = ws("ws://example.net:5673", ["binary", "AMQPWSB10", "amqp"])
const conn = container.connect({"connection_details": details});
conn.open_receiver("notifications");
</script>
</body>