Selectively prevent sending published message back to original.

10 views
Skip to first unread message

Glenn Thompson

unread,
Oct 3, 2019, 5:27:30 PM10/3/19
to cometd...@googlegroups.com
Hi all,

Until a couple weeks ago I hadn't used CometD since version 2.x

Back then I had a case where I used a dequeue listener to remove messages as they were being sent to the client.  It was a security requirement I had to deal with. It worked but I never felt comfortable using it.

Fast forward to today using 4.0.4.

I have a situation where I want to publish and subscribe to the same channel but I would like to prevent a client form receiving their own published messages.

I understand that this may be a bit of an anti-pattern.  But it does seem like a reasonable use case.

So far, I've tired 2 things:

First, I tried using a service channel that would deliver messages to all subscribers except to the source of the message.  It appears that while subscription is allowed on service channels, Cometd doesn't maintain the subscription.  So I couldn't find a populated set of subscribers to iterate over.  A closer reading of the docs indicated that subscribe, while allowed on service channels, is a noop on service channels.  So I guess that means subscriptions aren't maintained. That made sense when I thought about it.  So I moved on.

Second, I tried my hand at a server side extension.  Only the outgoing and send methods have access to the from and to sessions.  That seems consistent with me using deque listener for similar stuff in the past.  Within this path I've tried both outgoing and send methods.  Through use of logging and debugging I appear to detect the proper conditions for removal but nothing I tried actually prevented the publishing client from receiving their own messages. implementing outgoing I tried setting promise.succeed to null and false. For send I returned false. Neither worked for me.  I did start pouring over the source.  I'm a little lost in the foldleft loop to be honest:-)

There are more details I can share.  However, is this something I should be able to do with Extensions?

I noticed the use of dequeue listeners in the unit tests so maybe I'll try that route.  Using a dequeue listener makes me feel a little like I've invited myself into cometd's living room.

Any suggestions would be much appreciated.

Thanks,
Glenn


Simone Bordet

unread,
Oct 3, 2019, 6:05:43 PM10/3/19
to cometd-users
Hi,

On Thu, Oct 3, 2019 at 11:27 PM Glenn Thompson <gatma...@gmail.com> wrote:
>
> Hi all,
>
> Until a couple weeks ago I hadn't used CometD since version 2.x
>
> Back then I had a case where I used a dequeue listener to remove messages as they were being sent to the client. It was a security requirement I had to deal with. It worked but I never felt comfortable using it.
>
> Fast forward to today using 4.0.4.
>
> I have a situation where I want to publish and subscribe to the same channel but I would like to prevent a client form receiving their own published messages.

This should be doable by setting "broadcastToPublisher" to false
(defaults to true).
https://docs.cometd.org/current4/reference/#_java_server_configuration_bayeux

--
Simone Bordet
----
http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.

Glenn Thompson

unread,
Oct 3, 2019, 6:23:18 PM10/3/19
to cometd...@googlegroups.com
Thankyou!

I can't believe I missed that.

That appears to be for all channels.  I was trying to set the behavior in the config callback for a channel.  Is that possible?

Thanks again.

Glenn

--
--
You received this message because you are subscribed to the Google Groups "cometd-users" group.
To post to this group, send email to cometd...@googlegroups.com
To unsubscribe from this group, send email to cometd-users...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cometd-users

Visit the CometD website at http://www.cometd.org

---
You received this message because you are subscribed to the Google Groups "cometd-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cometd-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cometd-users/CAFWmRJ24r2W7EGiPEG-t1Hj6FMDv6tfLhZtF%2Bqw9cEWKMfEUSg%40mail.gmail.com.

Simone Bordet

unread,
Oct 3, 2019, 6:53:18 PM10/3/19
to cometd-users
Hi,

On Fri, Oct 4, 2019 at 12:23 AM Glenn Thompson <gatma...@gmail.com> wrote:
> That appears to be for all channels. I was trying to set the behavior in the config callback for a channel. Is that possible?

"broadcastToPublisher" can be set at BayeuxServer level, or at
ServerSession level, so you can configure that for a single session.
It's currently not supported at the channel level, but I believe it
would make sense.
Would you mind opening an issue about this at
https://github.com/cometd/cometd/issues?

I also notice that ServerSession.Extension does not have the right
signature to implement this use case :(

For now, you can use a ServerSession.MessageListener:

class FilteringMessageListener implements ServerSession.MessageListener {
private final List<String> channelsToFilter;

boolean onMessage(ServerSession session, ServerSession sender,
ServerMessage message) {
if (sender == session && channelsToFilter.contains(message.getChannel())) {
return false;
}
return true;
}
}

You can add this listener (a single instance) to every ServerSession
that gets created from a BayeuxServer.SessionListener.

Thanks!

Glenn Thompson

unread,
Oct 3, 2019, 6:53:45 PM10/3/19
to cometd...@googlegroups.com
Okay that works for sure.  It's a property  on BayeuxServerImpl as well as ServerSessionImpl.  So I was able to set it in a listener as well.  The only issue I see is that I can't limit that behavior to specific channels.

Any ideas in that regard? 

Thanks for the help.  I'll keep digging.

Glenn

Glenn Thompson

unread,
Oct 3, 2019, 7:06:24 PM10/3/19
to cometd...@googlegroups.com
Thank you Simone!

I will file an issue shortly. And thanks for the incredibly quick response.

Thanks again,
Glenn

--
--
You received this message because you are subscribed to the Google Groups "cometd-users" group.
To post to this group, send email to cometd...@googlegroups.com
To unsubscribe from this group, send email to cometd-users...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cometd-users

Visit the CometD website at http://www.cometd.org

---
You received this message because you are subscribed to the Google Groups "cometd-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cometd-users...@googlegroups.com.

Glenn Thompson

unread,
Oct 3, 2019, 7:37:07 PM10/3/19
to cometd...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages