gradle springboot 整合activeMQ

本文详细介绍如何在Spring Boot项目中整合ActiveMQ消息中间件,包括配置Gradle依赖及application.properties参数设置。并通过示例代码展示了如何定义生产者与消费者的实现方式,包括队列消息与主题消息的发送与接收。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

gradle.xml配置

compile group: 'org.springframework.boot', name: 'spring-boot-starter-activemq', version: '1.4.0.RELEASE'

compile group: 'org.apache.activemq', name: 'activemq-pool', version: '5.13.4'

application.properties配置

    spring.activemq.broker-url=tcp://192.168.3.88:61616
    spring.activemq.user=admin
    spring.activemq.password=admin
    spring.activemq.pool.enabled=true
    spring.activemq.pool.max-connections=50
    spring.activemq.pool.expiry-timeout=10000

    spring.activemq.pool.idle-timeout=30000

/**
 * 定义消费者
 * @Description
 * @author Qz
 * @date 2018年3月27日
 *
 */
@Component
public class Consumer {

@JmsListener(destination = "myTestQue")
public void receiveQueue(String text) {
System.out.println("消费者:来源于生产者对列的消息:"+text);
}






@JmsListener(destination = "myTestTopics")
public void receiveSub1(String text) {
System.out.println("消费者:Consumer1="+text);
}




// @JmsListener(destination = "myTestTopics")
// public void receiveSub2(String text) {
// System.out.println("消费者:Consumer2="+text);
// }

}


/**
 * 定义生产者
 * @Description
 * @author Qz
 * @date 2018年3月27日
 *
 */
@Service
public class Producer {


private static final Logger logger=LoggerFactory.getLogger(Producer.class);




@Autowired
private JmsMessagingTemplate jmsMessagingTemplate;

@Autowired
private Queue queue;


@Autowired
private Topic topic;






/**
* 每5S执行一次
*/
@Scheduled(fixedRate=5000,initialDelay=3000)
public void send() {
//发送队列消息
this.jmsMessagingTemplate.convertAndSend(this.queue, "发队列消息了");
//发送订阅消息
this.jmsMessagingTemplate.convertAndSend(this.topic, "发主题消息了");
}

}


以上是通过其他博客整合 自己用的 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值