Hi Mark,
        you have to keep connection keys from each client in a map or list,
then you need to send same data to the producer with different connection key.

here is how you can get the connection key from each client. whenever a client 
makes a connection with your websocket consumer you will get a connection key.

Apache camel websocket consumer example.
     from("direct:Consumer1")
    .process(new Processor() {
     public void process(Exchange exchange) throws Exception {
       Map<String, Object> headers=exchange.getIn().getHeaders();
    //you will get a unique connection key from the exchange header.This would 
be unique for each client.
    //store this key somewhere, to send messages to particular client.
    String 
uniqueConnectionKey=headers.get("websocket.connectionKey").toString();
          //you can get message from the client like below.
          String dataFromClient=exchange.getIn().getBody().toString();
  
   }
}).end();

Apache camel websocket producer example:
      from("direct:Producer1").
      //we will use this connectionKey for uniquely identifying each connection 
from the client.
      setHeader(WebsocketConstants.CONNECTION_KEY, header("connectionKey")).
      to("websocket://{host}:{port}/camel-websocket?sendToAll=false").end();

here is the sample for producer template.
ProducerTemplate template=camelContext.createProducerTemplate();

repeat this step with same message and different connection key:
template.sendBodyAndHeader("direct:Producer1", {message}, "connectionKey", 
{connectionkey});

I hope this would help

-----Original Message-----
From: "Mark" <elihusma...@gmail.com>
Sent: Tuesday, October 18, 2016 10:51am
To: users@camel.apache.org
Subject: send same message to multiple, not all, websocket clients

I am receiving messages of data that I am processing with Camel, similar to
a chat system.  Clients may "subscribe" to the data feed which will require
me to send the messages to the clients that subscribe to that message type
over websockets.  How can I implement this websocket communication using
Camel since the current implementation only allows for one connection key
per message?  Would I somehow duplicate the message and set a different
connection key for each message?


Reply via email to