├── 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 | Insert title here 6 | 7 | 8 | 9 | 10 |
11 | 12 | 43 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/resources/static/chat.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 |
11 | 12 | 43 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/websocket/WebSocketServer.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.websocket; 2 | 3 | import java.io.IOException; 4 | import java.util.concurrent.CopyOnWriteArraySet; 5 | 6 | import javax.websocket.OnClose; 7 | import javax.websocket.OnMessage; 8 | import javax.websocket.OnOpen; 9 | import javax.websocket.Session; 10 | import javax.websocket.server.ServerEndpoint; 11 | 12 | import org.springframework.stereotype.Component; 13 | 14 | @ServerEndpoint(value="/webSocket") 15 | @Component 16 | public class WebSocketServer { 17 | 18 | private Session session; 19 | public static CopyOnWriteArraySet webSockets = new CopyOnWriteArraySet(); 20 | 21 | @OnOpen 22 | public void onOpen(Session session) throws InterruptedException { 23 | this.session = session; 24 | webSockets.add(this); 25 | this.send("新用户加入"); 26 | // for(int i=0;i<100;i++) { 27 | // Thread.sleep(1000); 28 | // this.send("服务端推送:"+i); 29 | // } 30 | } 31 | @OnClose 32 | public void onClose(Session s) { 33 | webSockets.remove(this); 34 | this.send("有用户离开"); 35 | } 36 | @OnMessage 37 | public void onMessage(String msg) throws InterruptedException { 38 | System.out.println("从客服端接受的消息: "+msg); 39 | } 40 | 41 | public void send(String msg) { 42 | try { 43 | this.session.getBasicRemote().sendText(msg); 44 | } catch (IOException e) { 45 | e.printStackTrace(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.example.rabbitmq 7 | springboot_rabbitmq 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | springboot_rabbitmq 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.1.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-amqp 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-websocket 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-test 44 | test 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-maven-plugin 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/target/classes/META-INF/maven/com.example.rabbitmq/springboot_rabbitmq/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.example.rabbitmq 7 | springboot_rabbitmq 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | springboot_rabbitmq 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.1.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-amqp 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-websocket 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-test 44 | test 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-maven-plugin 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/src/main/java/com/example/demo/config/AppConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.config; 2 | 3 | import org.springframework.amqp.core.Binding; 4 | import org.springframework.amqp.core.BindingBuilder; 5 | import org.springframework.amqp.core.DirectExchange; 6 | import org.springframework.amqp.core.FanoutExchange; 7 | import org.springframework.amqp.core.Queue; 8 | import org.springframework.amqp.core.TopicExchange; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.web.socket.server.standard.ServerEndpointExporter; 12 | 13 | @Configuration 14 | public class AppConfig { 15 | 16 | private static String routingKey = "rabbit.msg"; 17 | private static String routingKey2 = "rabbit.msg.others"; 18 | private static String routingKey3 = "rabbit.user.others"; 19 | 20 | @Bean 21 | public Queue helloQueue() { 22 | return new Queue("hello"); 23 | } 24 | 25 | /** 26 | * 如果exchange和queue都是持久化的,那么它们之间的binding也是持久化的,如果exchange和queue两者之间有一个持久化,一个非持久化,则不允许建立绑定. 27 | 注意:一旦创建了队列和交换机,就不能修改其标志了,例如,创建了一个non-durable的队列,然后想把它改变成durable的,唯一的办法就是删除这个队列然后重现创建。 28 | * @return 29 | */ 30 | @Bean 31 | public Queue directQueue() { 32 | return new Queue("direct", false); 33 | } 34 | 35 | @Bean 36 | public Queue msgQueue2() { 37 | return new Queue(AppConfig.routingKey2, false); 38 | } 39 | 40 | @Bean 41 | public Queue userQueue2() { 42 | return new Queue(AppConfig.routingKey3, false); 43 | } 44 | 45 | @Bean 46 | public Queue fanoutQueue1() { 47 | return new Queue("fanoutQueue1",false); 48 | } 49 | @Bean 50 | public Queue fanoutQueue2() { 51 | return new Queue("fanoutQueue2",false); 52 | } 53 | @Bean 54 | public Queue fanoutQueue3() { 55 | return new Queue("fanoutQueue3",false); 56 | } 57 | 58 | @Bean 59 | public DirectExchange directExchange2() { 60 | return new DirectExchange("directExchange2", false, false); 61 | } 62 | 63 | @Bean 64 | public TopicExchange topicExchange2() { 65 | return new TopicExchange("topicExchange3", false, false); 66 | } 67 | 68 | @Bean 69 | public FanoutExchange fanoutExchange2() { 70 | return new FanoutExchange("fanoutExchange2", false, false); 71 | } 72 | 73 | @Bean 74 | public Binding binding() { 75 | return BindingBuilder.bind(directQueue()).to(directExchange2()).with(routingKey); 76 | } 77 | 78 | @Bean 79 | public Binding bindMsgQueue2() { 80 | return BindingBuilder.bind(msgQueue2()).to(topicExchange2()).with("rabbit.msg.others"); 81 | } 82 | 83 | @Bean 84 | public Binding bindUserQueue2() { 85 | return BindingBuilder.bind(userQueue2()).to(topicExchange2()).with("rabbit.user.others"); 86 | } 87 | 88 | @Bean 89 | public Binding bindFanoutQueue1() { 90 | return BindingBuilder.bind(fanoutQueue1()).to(fanoutExchange2()); 91 | } 92 | @Bean 93 | public Binding bindFanoutQueue2() { 94 | return BindingBuilder.bind(fanoutQueue2()).to(fanoutExchange2()); 95 | } 96 | @Bean 97 | public Binding bindFanoutQueue3() { 98 | return BindingBuilder.bind(fanoutQueue3()).to(fanoutExchange2()); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /springboot_rabbitmq_websocket/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | --------------------------------------------------------------------------------