jmsactivemq-classicpublish-subscribep2p

ActiveMQ - Combining Publish-Subscribe and peer-to-peer


Is there a way to implement a topology with ActiveMQ, where P is a publisher, s_a is a subscriber of service A and s_b1 and s_b2 are subscribers of service B. The latter are set in a cluster for load balancing (so s_b1 or s_b2 gets a message but not both).

Is there a way to combine publish-subscribe with a peer-to-peer messaging so one of the subscribers would be a queue which two consumers are listening on?


Solution

  • Yes this can be done.

    You may want to look at Apache ActiveMQ Artemis which implements JMS 2.0 and support what you ask for out of the box. JMS 2.0 allows multiple subscribers per topic to load balance a cluster.

    For ActiveMQ and JMS 1.0 you can use Virtual Destinations instead. They work with naming conventions.

    If you name your topic: VirtualTopic.StockPrice and publish messages to it, you will be able to consume from queues named Consumer.Consumer1.VirtualTopic.StockPrice, Consumer.Consumer2.VirtualTopic.StockPrice etc. Consumer1 can be anything.

    You can reconfigure ActiveMQ to use other names for Virtual Destinations (prefix, suffix etc).