我的問題是真的類似Spring JMS(ActiveMQ) delayed delivery of messages但更相關的彈簧開機自動配置者的ActiveMQ延遲的消息的傳遞在春季啓動
我試圖使用jmsTemplate.setDeliveryDelay
方法,但它拋出一個java.lang.IllegalStateException: setDeliveryDelay requires JMS 2.0
我試圖從http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html找到合適的屬性,但找不到broker schedulerSupport選項。
目前,我的application.properties是空的,我的JmsListenerContainerFactory定義如下
@Bean
public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory,
DefaultJmsListenerContainerFactoryConfigurer configurer) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
configurer.configure(factory, connectionFactory);
return factory;
}
而且我POM只包含
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
隨着1.4彈簧引導啓動父.1.RELEASE
問題是:是否可以使用SpringBoot配置將schedulerSupport設置爲true?
在需要它的情況下,這裏是我的發件人
public void send(String message) {
System.out.println("Im sending this message " + message);
jmsTemplate.setDeliveryDelay(5000);
jmsTemplate.convertAndSend(Beans.QUEUE_NAME, message);
}
和接收器
@JmsListener(destination = Beans.QUEUE_NAME, containerFactory = "myFactory")
public void receiveMessage(String message) {
System.out.println("Received this message <" + message + ">");
}
在此先感謝
更新:我試圖把它的消息屬性,像文檔http://activemq.apache.org/delay-and-schedule-message-delivery.html,但它不起作用
@Bean
public MessageConverter messageConverter() {
MessageConverter converter = new MessageConverter(){
@Override
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
if (!(object instanceof MyPojo)) {
throw new MessageConversionException("not agreed Pojo!");
}
MyPojo pojo = (MyPojo) object;
Message message = session.createTextMessage(pojo.getMessage());
message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, pojo.getScheduledWait());
return message;
}
@Override
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
return message;
}
};
return converter;
}
你解決了這個問題嗎? – Mikhail
我在下面回答了我自己的問題(這是第二個問題)。最後我用另一個首發(artemis)。 –