Search code examples
javajettycometcometd

Preventing local reception of published messages


The setup:

One server class (extension of AbstractService) One cometd client (custom C implementation, but irrelevant for this question)

The small question: If my server class publishes to it's own channel, it's handleMessage function gets called. In general, I don't really desire this, but I can work around it (the server doesn't need to know when the server sends messages). Can I use ServerSession.deliver instead of publish?

The real question: On my client, I send a message to the server on the server class' channel. The server's handleMessage function gets called, however the message also gets sent back to the originating client. Is there a way to configure the server such that messages are not sent back to the originating client?

I saw the Extension class, but this seems to operate just one level above sending messages to separate clients (if I kill a message here, it doesn't get sent to any clients, including the server).

Any ideas? Thanks in advance!


Solution

  • If the message is sent back to the original sender, then it's likely subscribed to that channel.

    You did not specify the channel's name, but you should understand the different between broadcast channels and service channels, see here.

    If your client publishes to a service channel, the message arrives to the server and it's not broadcasted to subscribers, while if your client publishes to a broadcast channel, the server broadcasts it to subscribers (among which your client), so that is likely why your client gets the message back.

    ServerSession.deliver() can be used to perform message delivery (on any channel) to specific clients (as opposed to broadcast to all subscribers).

    If your client does not need the message to be broadcasted, then normally the best solution is to use a service channel.