You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by hengyunabc <he...@gmail.com> on 2013/06/18 10:37:20 UTC

How to filter message in virtual destinations?

My Message is TextMessage, and it's content is JSON string.
I know that use selector and filtered destinations can filter message. 
http://activemq.apache.org/virtual-destinations.html
But I don't want to set the jms message property.

I have read these pages:
http://activemq.apache.org/interceptors.html
http://activemq.apache.org/developing-plugins.html

I alse read some source under the package
"org.apache.activemq.broker.region.virtual".
I didn't found a easy way to filter the message.
I just want to define a class with a filter function, so I can do anything
what I want. For example:

class Myfilter implements Filter{
    public boolean doFilter(Message msg){
         ...
    }
}

Is there anybody tell me how to do it?



--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-filter-message-in-virtual-destinations-tp4668296.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: How to filter message in virtual destinations?

Posted by Jakub Korab <ja...@gmail.com>.
Your best bet if you want to filter based on message content is to use a
Camel route to consume from one queue, filter the messages it is interested
in (http://camel.apache.org/message-filter.html) and place them on another
queue for consumption. This allows for any type of custom filtering, and
will not interfere with the normal processing of messages in ActiveMQ as a
plugin might.

Hope that helps,

Jakub



--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-filter-message-in-virtual-destinations-tp4668296p4668302.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Re:Re: Re:Re: How to filter message in virtual destinations?

Posted by hengyunabc <he...@gmail.com>.
Without virtual topic, the camel.xml :

	<route id="route_coreservice_datachange"
errorHandlerRef="transactionErrorHandler1">
		<description>coreservice.datachange Route</description>
		<from
		
uri="jms1:topic:VirtualTopic.Orders?clientId=client1&amp;durableSubscriptionName=bar1"
/>
			  <transacted />
		<to uri="jms1:queue:q.A" />
	</route>

With virtual topic, the camel.xml:

	<route id="route_coreservice_datachange"
errorHandlerRef="transactionErrorHandler1">
		<description>coreservice.datachange Route</description>
		<from
			uri="jms1:queue:Consumer.A.VirtualTopic.Orders " />
			  <transacted />
		<to uri="jms1:queue:q.A" />
	</route>

I can take far away from "unique subscriber name", "clientId".  
The camel.xml will be small and clear. 
In fact, I think that it is hard to configure a right camel.xml while it
contains "subscriber name", "clientId". 



--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-filter-message-in-virtual-destinations-tp4668296p4668453.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re:Re: Re:Re: How to filter message in virtual destinations?

Posted by SuoNayi <su...@163.com>.
So what's the difference between the "Consumer.A.VirtualTopic.Orders" queue  and the "q.A" queue?
There is no need to use the Virutal Topic as well.Just push all messages to one queue and use a 
consumer/camel route to pick up & filter & forward messages to other different queues.

At 2013-06-21 16:42:53,hengyunabc <he...@gmail.com> wrote:
>Maybe can filter message in class: VirtualTopicInterceptor, but I don't want
>to do it...
>
>Now my plan is  Virtual Destinations + camel:
>
>Producer:
>send message to topic: VirtualTopic.Orders;
>
>Camel:
>forward message from queue "Consumer.A.VirtualTopic.Orders " to "q.A"
>forward message from queue "Consumer.B.VirtualTopic.Orders " to "q.B"
>If I need, filter message through camel route.
>
>Consumer:
>receive message from queue "q.A"
>receive message from queue "q.B"
>
>So, I can far away from "unique subscriber name", "clientId".
>
>
>
>
>--
>View this message in context: http://activemq.2283324.n4.nabble.com/How-to-filter-message-in-virtual-destinations-tp4668296p4668444.html
>Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Re:Re: How to filter message in virtual destinations?

Posted by hengyunabc <he...@gmail.com>.
Maybe can filter message in class: VirtualTopicInterceptor, but I don't want
to do it...

Now my plan is  Virtual Destinations + camel:

Producer:
send message to topic: VirtualTopic.Orders;

Camel:
forward message from queue "Consumer.A.VirtualTopic.Orders " to "q.A"
forward message from queue "Consumer.B.VirtualTopic.Orders " to "q.B"
If I need, filter message through camel route.

Consumer:
receive message from queue "q.A"
receive message from queue "q.B"

So, I can far away from "unique subscriber name", "clientId".




--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-filter-message-in-virtual-destinations-tp4668296p4668444.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re:Re: How to filter message in virtual destinations?

Posted by SuoNayi <su...@163.com>.
You can not add/remove/configure broker plugin in runtime as well.
Jakub's approach is surely worth a try.




At 2013-06-20 17:22:03,hengyunabc <he...@gmail.com> wrote:
>I don't know how to discard a message in BrokerFilter...
>
>class MyBrokerFilter extends BrokerFilter {
>    public void send(ProducerBrokerExchange producerExchange, Message
>messageSend) throws Exception {
>       
>if("discardQueueName".equals(messageSend.getDestination().getPhysicalName())){
>            //do nothing?  Or throw a Exception?
>            return;
>        }
>    }
>}
>
>It seems wrong...
>
>
>
>--
>View this message in context: http://activemq.2283324.n4.nabble.com/How-to-filter-message-in-virtual-destinations-tp4668296p4668406.html
>Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: How to filter message in virtual destinations?

Posted by hengyunabc <he...@gmail.com>.
I don't know how to discard a message in BrokerFilter...

class MyBrokerFilter extends BrokerFilter {
    public void send(ProducerBrokerExchange producerExchange, Message
messageSend) throws Exception {
       
if("discardQueueName".equals(messageSend.getDestination().getPhysicalName())){
            //do nothing?  Or throw a Exception?
            return;
        }
    }
}

It seems wrong...



--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-filter-message-in-virtual-destinations-tp4668296p4668406.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: How to filter message in virtual destinations?

Posted by Hiram Chirino <ch...@gmail.com>.
You might be able to implement with a broker plugin. Have the plugin add a custom filter to the consumer based on extra data you stuff into the consumer options. 

Sent from my iPhone

On Jun 19, 2013, at 4:34 PM, hengyunabc <he...@gmail.com> wrote:

> For example, my message type JSON string, I just need a JSONMessageFilter
> class.
> The filter can add or disable or change in runtime. The ActiveMQ don't need
> to restart.
> I hope that it can work like camel route.
> We can add/remove/configure camel route in runtime.
> 
> 
> 
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/How-to-filter-message-in-virtual-destinations-tp4668296p4668386.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: How to filter message in virtual destinations?

Posted by hengyunabc <he...@gmail.com>.
For example, my message type JSON string, I just need a JSONMessageFilter
class.
The filter can add or disable or change in runtime. The ActiveMQ don't need
to restart.
I hope that it can work like camel route.
We can add/remove/configure camel route in runtime.



--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-filter-message-in-virtual-destinations-tp4668296p4668386.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: How to filter message in virtual destinations?

Posted by Christian Posta <ch...@gmail.com>.
So every time a new consumer comes on board, they have to create a new
filter, new jar, and restart activemq?


On Wed, Jun 19, 2013 at 3:54 PM, hengyunabc <he...@gmail.com> wrote:

> What I want is different filters for each subscriber.
> The consumer can define their filter class, make a jar file, place in the
> ActiveMQ lib path.
>
> Producer send message to the topic "VirtualTopic.Orders".
> ConsumerA, queue: Consumer.B.VirtualTopic.Orders
> ConsumerB, queue: Consumer.B.VirtualTopic.Orders
>
> I want to configure different filters for ConsumerA and ConsumerB.
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/How-to-filter-message-in-virtual-destinations-tp4668296p4668384.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Re: How to filter message in virtual destinations?

Posted by hengyunabc <he...@gmail.com>.
What I want is different filters for each subscriber.
The consumer can define their filter class, make a jar file, place in the
ActiveMQ lib path.

Producer send message to the topic "VirtualTopic.Orders".
ConsumerA, queue: Consumer.B.VirtualTopic.Orders
ConsumerB, queue: Consumer.B.VirtualTopic.Orders

I want to configure different filters for ConsumerA and ConsumerB.



--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-filter-message-in-virtual-destinations-tp4668296p4668384.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: How to filter message in virtual destinations?

Posted by Christian Posta <ch...@gmail.com>.
Tell more about your use case.

You will have the same filter for every subscriber to the virtual topic? Or
different filters for each subscriber? How should the filter be specified?
In advance on the broker? Or let the consumer specify?


On Tue, Jun 18, 2013 at 10:27 PM, hengyunabc <he...@gmail.com> wrote:

> Thank to Jakub and ceposta.
>
> I know that camel can filter Message.
> But I need to transfer message from a topic to many queues.
> So If use camel route, I have to configure a unique durable subscribe name
> for every queue! The camel.xml will be more and more lager and confused.
>
> If I want to transfer message from a topic to many queue, Virtual Topic do
> not need any configuration.
> Convention over configuration, I like it.
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/How-to-filter-message-in-virtual-destinations-tp4668296p4668335.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Re: How to filter message in virtual destinations?

Posted by hengyunabc <he...@gmail.com>.
Thank to Jakub and ceposta.

I know that camel can filter Message.
But I need to transfer message from a topic to many queues.
So If use camel route, I have to configure a unique durable subscribe name
for every queue! The camel.xml will be more and more lager and confused.

If I want to transfer message from a topic to many queue, Virtual Topic do
not need any configuration. 
Convention over configuration, I like it. 



--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-filter-message-in-virtual-destinations-tp4668296p4668335.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: How to filter message in virtual destinations?

Posted by Christian Posta <ch...@gmail.com>.
Have you looked at http://camel.apache.org/message-filter.html ?


On Tue, Jun 18, 2013 at 4:37 AM, hengyunabc <he...@gmail.com> wrote:

> My Message is TextMessage, and it's content is JSON string.
> I know that use selector and filtered destinations can filter message.
> http://activemq.apache.org/virtual-destinations.html
> But I don't want to set the jms message property.
>
> I have read these pages:
> http://activemq.apache.org/interceptors.html
> http://activemq.apache.org/developing-plugins.html
>
> I alse read some source under the package
> "org.apache.activemq.broker.region.virtual".
> I didn't found a easy way to filter the message.
> I just want to define a class with a filter function, so I can do anything
> what I want. For example:
>
> class Myfilter implements Filter{
>     public boolean doFilter(Message msg){
>          ...
>     }
> }
>
> Is there anybody tell me how to do it?
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/How-to-filter-message-in-virtual-destinations-tp4668296.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta