如何在另一个现有DLQ上创建DLQ并设置重新交付策略等?

时间:2018-07-02 05:16:40

标签: activemq

问题陈述要求从现有DLQ中读取消息,并在DLQ上定义重新交付策略以为现有DLQ创建DLQ。

公共类DLQonDLQ {

公共静态void main(最终String [] args)抛出异常{

      ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616"); 
      ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection("admin","admin");

      RedeliveryPolicy policy = connection.getRedeliveryPolicy();

      policy.setInitialRedeliveryDelay(500);
      policy.setBackOffMultiplier(2);
      policy.setUseExponentialBackOff(true);
      policy.setMaximumRedeliveries(2);

      Session session = connection.createSession(true, 0);

      Queue queue = session.createQueue("DLQ.exampleQueue");

      MessageConsumer messageConsumer = session.createConsumer(queue);

      connection.start();

      TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
      System.out.println("1st delivery from " + queue.getQueueName() + ": " + messageReceived.getText());
      session.rollback();

0 个答案:

没有答案