环境 :
JDK : 1.8
Springboot : 2.1.6.RELEASE
ErLang : otp_win64_22.0.exe
RabbitMQ : 3.7.16
开启RabbitMQ的stomp插件 .
在RabbitMQ安装目录sbin文件夹里执行命令 :
rabbitmq-plugins enable rabbitmq_stomp
Springboot pom.xml引入RabbitMQ 和 WebSocket
<!--RabbitMQ-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<!--WebSocket-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.46</version>
</dependency>
<!--JSON-->
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
application.yml
# RabbitMQ 配置
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
virtual-host: /
# 开启消息发送确认
publisher-confirms: true
publisher-returns: true
listener:
simple:
acknowledge-mode: manual
RabbitMQ
配置类
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;
/**
* @ClassName RabbitConfig
* @Description RabbitMQ 配置类
* @Date 2019-07-20 11:44
* @Version 1.0.0
**/
@Configuration
public class RabbitConfig {
//websocket 消息队列
public static final String msg_queue = "msg_queue";
//消息交换机
public static final String msg_exchang = "msg_exchang";
//消息路由键
public static final String msg_routing_key = "msg_routing_key";
/**
* 消息队列
* @return
*/
@Bean
public Queue msgQueue(){
return new Qu