147.9. 将消息发送到连接到 vertx-websocket 服务器消费者的对等点
注意
本节仅在生成由 camel-vertx-websocket 使用者托管的 WebSocket 时应用。在向外部托管的 WebSocket 生成消息时,它不相关。
要向 vertx-websocket 服务器使用者托管的 WebSocket 发送消息,请使用 sendToAll=true
端点选项,或 CamelVertxWebsocket.sendToAll
标头。
from("vertx-websocket:localhost:8080/chat") .log("Got WebSocket message ${body}"); from("direct:broadcastMessage") .setBody().constant("This is a broadcast message!") .to("vertx-websocket:localhost:8080/chat?sendToAll=true");
或者,您可以使用 CamelVertxWebsocket.connectionKey
标头将消息发送到特定的对等点。可将多个 peer 指定为用逗号分开的列表。
connectionKey
的值可以在 vertx-websocket consumer 上触发事件时确定,其中标识 peer 的唯一键将通过 CamelVertxWebsocket.connectionKey
标头传播。
from("vertx-websocket:localhost:8080/chat") .log("Got WebSocket message ${body}"); from("direct:broadcastMessage") .setBody().constant("This is a broadcast message!") .setHeader(VertxWebsocketConstants.CONNECTION_KEY).constant("key-1,key-2,key-3") .to("vertx-websocket:localhost:8080/chat");