<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</dependency>
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.RedeliveryPolicy;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.core.JmsTemplate;
@Configuration
public class MessageConfig {
@Bean
public ActiveMQQueue queue(){
return new ActiveMQQueue("m2m_queue");
}
@Bean
public ActiveMQTopic topic(){
return new ActiveMQTopic("topic_queue");
}
/**
* 消息重试配置项
* @return
*/
@Bean
public RedeliveryPolicy redeliveryPolicy(){
RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
redeliveryPolicy.setUseExponentialBackOff(true);//是否在每次失败重发是,增长等待时间
redeliveryPolicy.setMaximumRedeliveryDelay(-1);//设置重发最大拖延时间,-1 表示没有拖延,只有setUseExponentialBackOff(true)时生效
redeliveryPolicy.setMaximumRedeliveries(10);//重发次数
redeliveryPolicy.setInitialRedeliveryDelay(1);//重发时间间隔
redeliveryPolicy.setBackOffMultiplier(2);//第一次失败后重发前等待500毫秒