I'm designing a system using comet where there is a common channel where data getting published. I need to filter the data using some conditions based on client subscription details. Can anyone tell how I can do this? I thought I can do this using DataFilter.
Channel.addDataFilter(DataFilter filter);
Is this the correct way? If so any sample code to achieve this please?
There is no Channel.addDataFilter(DataFilter)
method, but you can achieve the same results in a different way.
First, have a look at the available DataFilter
implementations already available.
Then it's enough that you add a DataFilterMessageListener
to the channel you want to filter data on, and specify one or more DataFilter
to the DataFilterMessageListener
.
You can find an example of this in the CometD demos shipped with the CometD distribution, for example here.
The right way to add the DataFilterMessageListener
is during channel initialization, as it is done in the example linked above through a @Configure
annotation, or equivalently via ServerChannel.Initializer
.
Finally, have a look at how messages are processed on the server from the documentation: http://docs.cometd.org/reference/#concepts_message_processing.
It is important to understand that modifications made by DataFilter
are seen by all subscribers.