我对spring jms SessionAwareMessageListener
当我将RedeliveryPolicy
添加到ActiveMQConnectionFactory
时,我的消息是正确的重新传递,但所有下一条消息(新消息)都被卡住而不消耗(未调用类侦听器)
请帮助,我的代码中有什么问题?
我的JmsPublisher:
@Component
public class DocumentMsgSender {
@Autowired
private JmsTemplate jmsTemplate;
public void send(DocumentMsgTemplate message) throws JMSException {
jmsTemplate.send(new DocMsgCreator(message));
}
class DocMsgCreator implements MessageCreator {
DocumentMsgTemplate message;
public DocMsgCreator(DocumentMsgTemplate message) {
this.message = message;
}
@Override
public Message createMessage(Session s) throws JMSException {
Message resultMessage = s.createObjectMessage(message);
resultMessage.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
resultMessage.setJMSPriority(9);
return resultMessage;
}
}
}
My Jms listner:
@Service
public class DocumentMsgListener implements SessionAwareMessageListener<Message> {
@Autowired
private JmsTemplate sendDocJmsTemplate;
public void onMessage(Message message, Session session) throws JMSException {
throw new RuntimeException("ERROR");
}
}
我的ActiveMQConnectionFactory是
@Bean
public ActiveMQConnectionFactory connectionFactory() {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(env.getProperty("activemq.url"));
connectionFactory.setRedeliveryPolicy(getRedeliveryPolicy());
connectionFactory.setMessagePrioritySupported(true);
return connectionFactory;
}
RedeliveryPolicy
private RedeliveryPolicy getRedeliveryPolicy() {
RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
redeliveryPolicy.setInitialRedeliveryDelay(900000L);
redeliveryPolicy.setRedeliveryDelay(900000L);
redeliveryPolicy.setMaximumRedeliveries(48);
return redeliveryPolicy;
}
我的DefaultMessageListenerContainer是
@Bean
@Autowired
public DefaultMessageListenerContainer listenerContainer(DocumentMsgListener messageListener) {
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
container.setConnectionFactory(connectionFactory());
container.setDestinationName("testQueue");
container.setMessageListener(messageListener);
container.setSessionTransacted(true);
return container;
}
我的JmsTemplate:
@Bean
public JmsTemplate jmsTemplate() {
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory());
jmsTemplate.setDefaultDestinationName("testQueue");
jmsTemplate.setDeliveryPersistent(true);
jmsTemplate.setExplicitQosEnabled(true);
return jmsTemplate;
}
答案 0 :(得分:0)
connectionFactory.setNonBlockingRedelivery(真);