问题陈述要求从现有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();