ActiveMQ简单使用
JMS
ActiveMQ
下载安装
https://activemq.apache.org/components/classic/download/
解压缩文件。进入win64目录,双击运行activemq.bat文件,运行服务
将下面的网址输入到浏览器,用户名和密码都是admin
SpringBoot整合ActiveMQ
- 导入坐标
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-activemq</artifactId></dependency>
- 添加配置
server:port: 8080spring:activemq:broker-url: tcp://localhost:61616jms:template:default-destination: itheima
- 实现业务类
package com.ustc.service.activemq;import com.ustc.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;@Service
public class MessageServiceActivemqImpl implements MessageService {@Autowiredprivate JmsMessagingTemplate messagingTemplate;@Overridepublic void sendMessage(String id) {System.out.println("待发送短信的订单已经纳入处理对队列id" + id);messagingTemplate.convertAndSend(id);}@Overridepublic String doMessge() {String id = messagingTemplate.receiveAndConvert(String.class);System.out.println("已经完成短信发送服务:id" + id);return id;}
}