├── LICENSE ├── README.md ├── activemq-receiver ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── techshard │ │ └── activemq │ │ ├── Application.java │ │ └── consumer │ │ └── MessageConsumer.java │ └── resources │ └── application.properties └── activemq-sender ├── pom.xml └── src └── main ├── java └── com │ └── techshard │ └── activemq │ ├── Application.java │ ├── configuration │ └── JmsConfig.java │ └── controller │ └── MessageController.java └── resources └── application.properties /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Swathi Prasad 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # event-driven-microservices-with-springboot-activemq 2 | Event-Driven Microservices with Spring Boot and ActiveMQ 3 | -------------------------------------------------------------------------------- /activemq-receiver/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.techshard.activemqreceiver 8 | activemq-receiver 9 | 1.0-SNAPSHOT 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 2.1.6.RELEASE 15 | 16 | 17 | 18 | 19 | UTF-8 20 | UTF-8 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-web 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-activemq 31 | 32 | 33 | org.slf4j 34 | slf4j-api 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /activemq-receiver/src/main/java/com/techshard/activemq/Application.java: -------------------------------------------------------------------------------- 1 | package com.techshard.activemq; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 6 | 7 | @SpringBootApplication 8 | public class Application extends SpringBootServletInitializer { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(Application.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /activemq-receiver/src/main/java/com/techshard/activemq/consumer/MessageConsumer.java: -------------------------------------------------------------------------------- 1 | package com.techshard.activemq.consumer; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.jms.annotation.EnableJms; 6 | import org.springframework.jms.annotation.JmsListener; 7 | import org.springframework.stereotype.Component; 8 | 9 | @Component 10 | @EnableJms 11 | public class MessageConsumer { 12 | 13 | private final Logger logger = LoggerFactory.getLogger(MessageConsumer.class); 14 | 15 | @JmsListener(destination = "test-queue") 16 | public void listener(String message){ 17 | logger.info("Message received {} ", message); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /activemq-receiver/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.activemq.broker-url=tcp://localhost:61616 2 | spring.activemq.user=admin 3 | spring.activemq.password=admin 4 | 5 | server.port=8081 -------------------------------------------------------------------------------- /activemq-sender/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.techshard.activemqsender 8 | activemq-sender 9 | 1.0-SNAPSHOT 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 2.1.6.RELEASE 15 | 16 | 17 | 18 | 19 | UTF-8 20 | UTF-8 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-web 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-activemq 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /activemq-sender/src/main/java/com/techshard/activemq/Application.java: -------------------------------------------------------------------------------- 1 | package com.techshard.activemq; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 6 | 7 | @SpringBootApplication 8 | public class Application extends SpringBootServletInitializer { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(Application.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /activemq-sender/src/main/java/com/techshard/activemq/configuration/JmsConfig.java: -------------------------------------------------------------------------------- 1 | package com.techshard.activemq.configuration; 2 | 3 | import org.apache.activemq.command.ActiveMQQueue; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.jms.annotation.EnableJms; 7 | 8 | import javax.jms.Queue; 9 | 10 | @Configuration 11 | @EnableJms 12 | public class JmsConfig { 13 | 14 | @Bean 15 | public Queue queue(){ 16 | return new ActiveMQQueue("test-queue"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /activemq-sender/src/main/java/com/techshard/activemq/controller/MessageController.java: -------------------------------------------------------------------------------- 1 | package com.techshard.activemq.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.jms.core.JmsTemplate; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import javax.jms.Queue; 13 | 14 | @RestController 15 | @RequestMapping("/api") 16 | public class MessageController { 17 | 18 | @Autowired 19 | private Queue queue; 20 | 21 | @Autowired 22 | private JmsTemplate jmsTemplate; 23 | 24 | @GetMapping("message/{message}") 25 | public ResponseEntity publish(@PathVariable("message") final String message){ 26 | jmsTemplate.convertAndSend(queue, message); 27 | return new ResponseEntity(message, HttpStatus.OK); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /activemq-sender/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.activemq.broker-url=tcp://localhost:61616 2 | spring.activemq.user=admin 3 | spring.activemq.password=admin --------------------------------------------------------------------------------