0

In this piece of code I'm trying to set up a redelivery police only only for the messages in a specific topic:

    RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
    emailByFolioRedeliveryPolicy.setInitialRedeliveryDelay(5000);
    emailByFolioRedeliveryPolicy.setRedeliveryDelay(5000);
    emailByFolioRedeliveryPolicy.setUseExponentialBackOff(false);
    emailByFolioRedeliveryPolicy.setBackOffMultiplier(10);
    emailByFolioRedeliveryPolicy.setMaximumRedeliveries(3);

    PooledConnectionFactory connPool = new PooledConnectionFactory();
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");

    RedeliveryPolicyMap redeliveryPolicyMap = connectionFactory.getRedeliveryPolicyMap();
    redeliveryPolicyMap.put(new ActiveMQTopic("VirtualTopic.firstTopic"), redeliveryPolicy );

    connPool.setConnectionFactory(connectionFactory);
    connPool.setCreateConnectionOnStartup(true);
    connPool.setMaxConnections(20);
    return connPool;

The problem is that the messages being sent to another topic (VirtualTopic.secondTopic) are also impacted for this policy, because I can see the listener on the second topic is processing redelivered messages. In the RedeliveryPolicyMap I'm adding the policy specifying the Destination. But for some reason I can not get it working as expected.

The expected is:

  • A new message A is posted to "VirtualTopic.firstTopic"
  • A new message B is posted to "VirtualTopic.secondTopic"
  • The listener "Consume.FIRST.VirtualTopic.firstTopic" on "VirtualTopic.firstTopic" will process the message A.
  • The listener "Consume.SECOND.VirtualTopic.firstTopic" on "VirtualTopic.secondTopic" will process the message B.
  • If the FIRST listener fails, will retry in 15 minutes.
  • If the SECOND listener fails, nothing happens. The message will end up in the Dead Letter Queue.

I took the configuration from this page:

http://activemq.apache.org/redelivery-policy.html

Does anybody has accomplished something like this? Thanks.

Perimosh
  • 2,304
  • 3
  • 20
  • 38

1 Answers1

0

Policies are set at the ActiveMQConnectionFactory or ActiveMQConnection level - if your policies are different, you need to use different connection factories in your project accordingly. In the case you mentioned, you need to define 2 seperate ActiveMQ connection factories with their own redelivery policies. Hope it helps

ali haider
  • 19,175
  • 17
  • 80
  • 149
  • We have that approach in our list of possible solutions. I will let you know once I try that solution. Thanks. – Perimosh Jul 31 '15 at 19:58
  • Thanks for your help. I have used two different connections. The first connection, is the pre existing one we were using in the past. The second is the new one, and this one is being set with the redelivery police. PooledConnectionFactory connPool = new PooledConnectionFactory(); ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616"); RedeliveryPolicyMap redeliveryPolicyMap = activeMQConnectionFactory.getRedeliveryPolicyMap(); redeliveryPolicyMap.setDefaultEntry(returnReDeveliveryPolicy()); – Perimosh Aug 04 '15 at 13:44
  • great- best of luck!! – ali haider Aug 04 '15 at 17:51