├── springboot_rabbitmq_websocket ├── target │ ├── classes │ │ ├── application.properties │ │ ├── com │ │ │ └── example │ │ │ │ └── demo │ │ │ │ ├── model │ │ │ │ └── User.class │ │ │ │ ├── handler │ │ │ │ ├── Sender.class │ │ │ │ └── Receiver.class │ │ │ │ ├── config │ │ │ │ └── AppConfig.class │ │ │ │ ├── topic │ │ │ │ ├── TopicRecive1.class │ │ │ │ ├── TopicRecive2.class │ │ │ │ └── TopicSender.class │ │ │ │ ├── direct │ │ │ │ ├── DirectReceive.class │ │ │ │ ├── DirectSender.class │ │ │ │ ├── DirectSender2.class │ │ │ │ └── DirectReceive2.class │ │ │ │ ├── fanout │ │ │ │ ├── FanoutSender.class │ │ │ │ ├── FanoutReciver1.class │ │ │ │ ├── FanoutReciver2.class │ │ │ │ └── FanoutReciver3.class │ │ │ │ ├── websocket │ │ │ │ └── WebSocketServer.class │ │ │ │ ├── controller │ │ │ │ └── MessageController.class │ │ │ │ └── SpringbootRabbitmqApplication.class │ │ ├── application-dev.properties │ │ ├── META-INF │ │ │ ├── maven │ │ │ │ └── com.example.rabbitmq │ │ │ │ │ └── springboot_rabbitmq │ │ │ │ │ ├── pom.properties │ │ │ │ │ └── pom.xml │ │ │ └── MANIFEST.MF │ │ └── static │ │ │ └── chat.html │ └── test-classes │ │ └── com │ │ └── example │ │ └── demo │ │ └── SpringbootRabbitmqApplicationTests.class ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ ├── application-dev.properties │ │ │ └── static │ │ │ │ └── chat.html │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── demo │ │ │ ├── SpringbootRabbitmqApplication.java │ │ │ ├── model │ │ │ └── User.java │ │ │ ├── handler │ │ │ ├── Receiver.java │ │ │ └── Sender.java │ │ │ ├── fanout │ │ │ ├── FanoutReciver1.java │ │ │ ├── FanoutReciver2.java │ │ │ ├── FanoutReciver3.java │ │ │ └── FanoutSender.java │ │ │ ├── topic │ │ │ ├── TopicRecive1.java │ │ │ ├── TopicRecive2.java │ │ │ └── TopicSender.java │ │ │ ├── direct │ │ │ ├── DirectReceive.java │ │ │ ├── DirectReceive2.java │ │ │ ├── DirectSender.java │ │ │ └── DirectSender2.java │ │ │ ├── controller │ │ │ └── MessageController.java │ │ │ ├── websocket │ │ │ └── WebSocketServer.java │ │ │ └── config │ │ │ └── AppConfig.java │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── demo │ │ └── SpringbootRabbitmqApplicationTests.java ├── pom.xml ├── mvnw.cmd └── mvnw └── README.md /springboot_rabbitmq_websocket/target/classes/application.properties: -------------------------------------------------------------------------------- 1 | spring.profiles.active=dev -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.profiles.active=dev -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # springboot-rabbitMQ-websocket 2 | springboot整合rabbitMQ和websocket,实现消息的发布和接收,并通过websocket实时推送数据到页面 3 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/model/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/model/User.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/handler/Sender.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/handler/Sender.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/config/AppConfig.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/config/AppConfig.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/handler/Receiver.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/handler/Receiver.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/topic/TopicRecive1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/topic/TopicRecive1.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/topic/TopicRecive2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/topic/TopicRecive2.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/topic/TopicSender.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/topic/TopicSender.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/direct/DirectReceive.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/direct/DirectReceive.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/direct/DirectSender.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/direct/DirectSender.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/direct/DirectSender2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/direct/DirectSender2.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/fanout/FanoutSender.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/fanout/FanoutSender.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/direct/DirectReceive2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/direct/DirectReceive2.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/fanout/FanoutReciver1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/fanout/FanoutReciver1.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/fanout/FanoutReciver2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/fanout/FanoutReciver2.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/fanout/FanoutReciver3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/fanout/FanoutReciver3.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/websocket/WebSocketServer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/websocket/WebSocketServer.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/controller/MessageController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/controller/MessageController.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/com/example/demo/SpringbootRabbitmqApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/classes/com/example/demo/SpringbootRabbitmqApplication.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/test-classes/com/example/demo/SpringbootRabbitmqApplicationTests.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanhaiyang/springboot-rabbitMQ-websocket/HEAD/springboot_rabbitmq_websocket/target/test-classes/com/example/demo/SpringbootRabbitmqApplicationTests.class -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/application-dev.properties: -------------------------------------------------------------------------------- 1 | server.servlet.context-path=/ 2 | 3 | spring.rabbitmq.host=localhost 4 | spring.rabbitmq.port=5672 5 | #spring.rabbitmq.virtual-host=/ 6 | spring.rabbitmq.username=guest 7 | spring.rabbitmq.password=guest 8 | #spring.rabbitmq.publisher-confirms=true -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | server.servlet.context-path=/ 2 | 3 | spring.rabbitmq.host=localhost 4 | spring.rabbitmq.port=5672 5 | #spring.rabbitmq.virtual-host=/ 6 | spring.rabbitmq.username=guest 7 | spring.rabbitmq.password=guest 8 | #spring.rabbitmq.publisher-confirms=true -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/META-INF/maven/com.example.rabbitmq/springboot_rabbitmq/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven Integration for Eclipse 2 | #Fri Jan 15 14:46:25 CST 2021 3 | version=0.0.1-SNAPSHOT 4 | groupId=com.example.rabbitmq 5 | m2e.projectName=springboot_rabbitmq 6 | m2e.projectLocation=E\:\\sts_workspace\\springboot-rabbitMQ-websocket\\springboot_rabbitmq_websocket 7 | artifactId=springboot_rabbitmq 8 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Implementation-Title: springboot_rabbitmq 3 | Implementation-Version: 0.0.1-SNAPSHOT 4 | Built-By: hp 5 | Implementation-Vendor-Id: com.example.rabbitmq 6 | Build-Jdk: 1.8.0_144 7 | Implementation-URL: https://projects.spring.io/spring-boot/#/spring-bo 8 | ot-starter-parent/springboot_rabbitmq 9 | Created-By: Maven Integration for Eclipse 10 | 11 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/SpringbootRabbitmqApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootRabbitmqApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootRabbitmqApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/model/User.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | 3 | public class User { 4 | 5 | private int id; 6 | private String name; 7 | private int age; 8 | public User(int id, String name, int age) { 9 | super(); 10 | this.id = id; 11 | this.name = name; 12 | this.age = age; 13 | } 14 | @Override 15 | public String toString() { 16 | return "User:id="+id+",name="+name+",age="+age; 17 | } 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/handler/Receiver.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.handler; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @RabbitListener(queues="hello") 9 | public class Receiver { 10 | 11 | @RabbitHandler 12 | public void process(String msg) { 13 | System.out.println("receive: "+msg); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/fanout/FanoutReciver1.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.fanout; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @RabbitListener(queues="fanoutQueue1") 9 | public class FanoutReciver1 { 10 | 11 | @RabbitHandler 12 | public void read(String user) { 13 | System.out.println("fanoutQueue1: "+user); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/fanout/FanoutReciver2.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.fanout; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @RabbitListener(queues="fanoutQueue2") 9 | public class FanoutReciver2 { 10 | 11 | @RabbitHandler 12 | public void read(String user) { 13 | System.out.println("fanoutQueue2: "+user); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/fanout/FanoutReciver3.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.fanout; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @RabbitListener(queues="fanoutQueue3") 9 | public class FanoutReciver3 { 10 | 11 | @RabbitHandler 12 | public void read(String user) { 13 | System.out.println("fanoutQueue3: "+user); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/topic/TopicRecive1.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.topic; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @RabbitListener(queues="rabbit.msg.others") 9 | public class TopicRecive1 { 10 | 11 | @RabbitHandler 12 | public void process(String user) throws InterruptedException { 13 | System.out.println("TopicRecive1接受的消息: "+user); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/topic/TopicRecive2.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.topic; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @RabbitListener(queues="rabbit.user.others") 9 | public class TopicRecive2 { 10 | 11 | @RabbitHandler 12 | public void process(String user) throws InterruptedException { 13 | System.out.println("TopicRecive2接受的消息: "+user); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/direct/DirectReceive.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.direct; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @RabbitListener(queues="direct") 9 | public class DirectReceive { 10 | 11 | @RabbitHandler 12 | public void process(String msg) throws InterruptedException { 13 | System.out.println("Receive1接受的消息: "+msg); 14 | Thread.sleep(500); 15 | //同websocket推送到页面 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/direct/DirectReceive2.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.direct; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @RabbitListener(queues="direct") 9 | public class DirectReceive2 { 10 | 11 | @RabbitHandler 12 | public void process(String msg) throws InterruptedException { 13 | System.out.println("Receive2接受的消息: "+msg); 14 | Thread.sleep(500); 15 | //同websocket推送到页面 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/handler/Sender.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.handler; 2 | 3 | import java.util.Calendar; 4 | 5 | import org.springframework.amqp.rabbit.core.RabbitTemplate; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Component; 8 | 9 | @Component 10 | public class Sender { 11 | 12 | @Autowired 13 | private RabbitTemplate amqpTemplate; 14 | 15 | public void send() { 16 | String msg = "hello"+Calendar.getInstance().getTimeInMillis(); 17 | System.out.println("send: "+msg); 18 | this.amqpTemplate.convertAndSend("hello",msg); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/fanout/FanoutSender.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.fanout; 2 | 3 | import org.springframework.amqp.rabbit.core.RabbitTemplate; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Component; 6 | 7 | import com.example.demo.model.User; 8 | 9 | @Component 10 | public class FanoutSender { 11 | 12 | @Autowired 13 | private RabbitTemplate rabbitTemplate; 14 | 15 | public void send() { 16 | this.rabbitTemplate.convertAndSend("fanoutExchange2", "", new User(1,"sfsa111",23).toString()); 17 | System.out.println("fanout send msg"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/direct/DirectSender.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.direct; 2 | 3 | import org.springframework.amqp.rabbit.core.RabbitTemplate; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | public class DirectSender { 9 | 10 | @Autowired 11 | private RabbitTemplate rabbitTemplate; 12 | 13 | public void sendDirect() { 14 | for(int i=0;i<100;i++) { 15 | String msg = "direct msg22 "+i; 16 | System.out.println("Sender1发送的消息: "+msg); 17 | rabbitTemplate.convertAndSend("directExchange2", "rabbit.msg", msg); 18 | } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/direct/DirectSender2.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.direct; 2 | 3 | import org.springframework.amqp.rabbit.core.RabbitTemplate; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | public class DirectSender2 { 9 | 10 | @Autowired 11 | private RabbitTemplate rabbitTemplate; 12 | 13 | public void sendDirect() { 14 | for(int i=0;i<100;i++) { 15 | String msg = "direct msg22 "+i; 16 | System.out.println("Sender2发送的消息: "+msg); 17 | rabbitTemplate.convertAndSend("directExchange2", "rabbit.msg", msg); 18 | } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/topic/TopicSender.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.topic; 2 | 3 | import org.springframework.amqp.rabbit.core.RabbitTemplate; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Component; 6 | 7 | import com.example.demo.model.User; 8 | 9 | @Component 10 | public class TopicSender { 11 | 12 | @Autowired 13 | private RabbitTemplate rabbitTemplate; 14 | 15 | public void send() { 16 | rabbitTemplate.convertAndSend("topicExchange3", "rabbit.msg.others", new User(1,"sfsa3333",23).toString()); 17 | rabbitTemplate.convertAndSend("topicExchange3", "rabbit.user.others", new User(2,"sfsa2222",22).toString()); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/test/java/com/example/demo/SpringbootRabbitmqApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | 9 | import com.example.demo.direct.DirectSender; 10 | import com.example.demo.handler.Sender; 11 | 12 | @RunWith(SpringRunner.class) 13 | @SpringBootTest 14 | public class SpringbootRabbitmqApplicationTests { 15 | 16 | @Autowired 17 | private Sender sender; 18 | 19 | @Autowired 20 | private DirectSender dsender; 21 | 22 | @Test 23 | public void send() { 24 | sender.send(); 25 | } 26 | 27 | @Test 28 | public void sendDirect() { 29 | dsender.sendDirect(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/controller/MessageController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | 7 | import com.example.demo.direct.DirectSender; 8 | import com.example.demo.direct.DirectSender2; 9 | import com.example.demo.fanout.FanoutSender; 10 | import com.example.demo.handler.Sender; 11 | import com.example.demo.topic.TopicSender; 12 | 13 | @Controller 14 | public class MessageController { 15 | 16 | @Autowired 17 | private Sender sender; 18 | 19 | @Autowired 20 | private DirectSender dsender; 21 | @Autowired 22 | private DirectSender2 dsender2; 23 | @Autowired 24 | private TopicSender tsender; 25 | @Autowired 26 | private FanoutSender fsender; 27 | 28 | @GetMapping(path="/send") 29 | public void senderMsg() { 30 | dsender.sendDirect(); 31 | dsender2.sendDirect(); 32 | } 33 | 34 | @GetMapping(path="/sendTopic") 35 | public void sendTopic() { 36 | tsender.send(); 37 | } 38 | 39 | @GetMapping(path="/sendfanout") 40 | public void sendfanout() { 41 | fsender.send(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/static/chat.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |