├── spring-jms-annotations
├── src
│ ├── test
│ │ ├── resources
│ │ │ └── application.yml
│ │ └── java
│ │ │ └── com
│ │ │ └── codenotfound
│ │ │ └── jms
│ │ │ └── SpringJmsApplicationTest.java
│ └── main
│ │ ├── resources
│ │ └── application.yml
│ │ └── java
│ │ └── com
│ │ └── codenotfound
│ │ ├── SpringJmsApplication.java
│ │ └── jms
│ │ ├── Sender.java
│ │ └── Receiver.java
├── README.md
└── pom.xml
├── spring-jms-message-converter
├── src
│ ├── test
│ │ ├── resources
│ │ │ └── application.yml
│ │ └── java
│ │ │ └── com
│ │ │ └── codenotfound
│ │ │ └── jms
│ │ │ └── SpringJmsApplicationTest.java
│ └── main
│ │ ├── resources
│ │ └── application.yml
│ │ └── java
│ │ └── com
│ │ └── codenotfound
│ │ ├── SpringJmsApplication.java
│ │ └── jms
│ │ ├── Sender.java
│ │ ├── Person.java
│ │ ├── Receiver.java
│ │ └── PersonMessageConverter.java
├── README.md
└── pom.xml
├── spring-jms-message-selector
├── src
│ ├── test
│ │ ├── resources
│ │ │ └── application.yml
│ │ └── java
│ │ │ └── com
│ │ │ └── codenotfound
│ │ │ └── jms
│ │ │ └── SpringJmsApplicationTest.java
│ └── main
│ │ ├── resources
│ │ └── application.yml
│ │ └── java
│ │ └── com
│ │ └── codenotfound
│ │ ├── SpringJmsApplication.java
│ │ └── jms
│ │ ├── Receiver.java
│ │ └── Sender.java
├── README.md
└── pom.xml
├── spring-jms-artemis-hello-world
├── src
│ ├── test
│ │ ├── resources
│ │ │ └── application.yml
│ │ └── java
│ │ │ └── com
│ │ │ └── codenotfound
│ │ │ └── SpringJmsApplicationTest.java
│ └── main
│ │ ├── resources
│ │ └── application.yml
│ │ └── java
│ │ └── com
│ │ └── codenotfound
│ │ ├── SpringJmsApplication.java
│ │ └── jms
│ │ ├── Sender.java
│ │ ├── Receiver.java
│ │ ├── SenderConfig.java
│ │ └── ReceiverConfig.java
├── README.md
└── pom.xml
├── spring-jms-integration
├── src
│ ├── test
│ │ ├── resources
│ │ │ └── application.yml
│ │ └── java
│ │ │ └── com
│ │ │ └── codenotfound
│ │ │ └── jms
│ │ │ └── SpringJmsApplicationTest.java
│ └── main
│ │ ├── resources
│ │ └── application.yml
│ │ └── java
│ │ └── com
│ │ └── codenotfound
│ │ ├── SpringJmsApplication.java
│ │ └── jms
│ │ ├── CountDownLatchHandler.java
│ │ ├── ProducingChannelConfig.java
│ │ └── ConsumingChannelConfig.java
├── README.md
└── pom.xml
├── spring-jms-activemq-hello-world
├── src
│ ├── main
│ │ ├── resources
│ │ │ └── application.yml
│ │ └── java
│ │ │ └── com
│ │ │ └── codenotfound
│ │ │ ├── SpringJmsApplication.java
│ │ │ └── jms
│ │ │ ├── Sender.java
│ │ │ ├── Receiver.java
│ │ │ ├── SenderConfig.java
│ │ │ └── ReceiverConfig.java
│ └── test
│ │ ├── resources
│ │ └── application.yml
│ │ └── java
│ │ └── com
│ │ └── codenotfound
│ │ └── SpringJmsApplicationTest.java
├── README.md
└── pom.xml
├── spring-jms-topic
├── src
│ ├── main
│ │ ├── resources
│ │ │ └── application.yml
│ │ └── java
│ │ │ └── com
│ │ │ └── codenotfound
│ │ │ ├── SpringJmsApplication.java
│ │ │ └── jms
│ │ │ ├── Sender.java
│ │ │ ├── Receiver.java
│ │ │ ├── ReceiverConfig.java
│ │ │ └── SenderConfig.java
│ └── test
│ │ ├── resources
│ │ └── application.yml
│ │ └── java
│ │ └── com
│ │ └── codenotfound
│ │ └── SpringJmsApplicationTest.java
├── README.md
└── pom.xml
├── spring-jms-jmstemplate
├── src
│ ├── main
│ │ ├── resources
│ │ │ └── application.yml
│ │ └── java
│ │ │ └── com
│ │ │ └── codenotfound
│ │ │ ├── SpringJmsApplication.java
│ │ │ └── jms
│ │ │ ├── ReceiverConfig.java
│ │ │ ├── Receiver.java
│ │ │ ├── Sender.java
│ │ │ └── SenderConfig.java
│ └── test
│ │ ├── resources
│ │ └── application.yml
│ │ └── java
│ │ └── com
│ │ └── codenotfound
│ │ └── SpringJmsApplicationTest.java
├── README.md
└── pom.xml
├── spring-jms-listener
├── src
│ ├── main
│ │ ├── resources
│ │ │ └── application.yml
│ │ └── java
│ │ │ └── com
│ │ │ └── codenotfound
│ │ │ ├── SpringJmsApplication.java
│ │ │ └── jms
│ │ │ ├── Sender.java
│ │ │ ├── OrderReceiver.java
│ │ │ ├── StatusMessageListener.java
│ │ │ ├── SenderConfig.java
│ │ │ └── ReceiverConfig.java
│ └── test
│ │ ├── resources
│ │ └── application.yml
│ │ └── java
│ │ └── com
│ │ └── codenotfound
│ │ └── SpringJmsApplicationTest.java
├── README.md
└── pom.xml
├── spring-jms-integration-gateway
├── src
│ ├── test
│ │ ├── resources
│ │ │ └── application.yml
│ │ └── java
│ │ │ └── com
│ │ │ └── codenotfound
│ │ │ └── jms
│ │ │ └── SpringJmsApplicationTest.java
│ └── main
│ │ ├── resources
│ │ └── application.yml
│ │ └── java
│ │ └── com
│ │ └── codenotfound
│ │ ├── SpringJmsApplication.java
│ │ └── jms
│ │ ├── OrderService.java
│ │ ├── OutboundGatewayConfig.java
│ │ └── InboundGatewayConfig.java
├── README.md
└── pom.xml
├── .gitignore
├── README.md
├── .travis.yml
└── LICENSE
/spring-jms-annotations/src/test/resources/application.yml:
--------------------------------------------------------------------------------
1 | queue:
2 | boot: boot.q
3 |
--------------------------------------------------------------------------------
/spring-jms-message-converter/src/test/resources/application.yml:
--------------------------------------------------------------------------------
1 | queue:
2 | boot: converter.q
3 |
--------------------------------------------------------------------------------
/spring-jms-message-selector/src/test/resources/application.yml:
--------------------------------------------------------------------------------
1 | queue:
2 | boot: selector.q
3 |
--------------------------------------------------------------------------------
/spring-jms-artemis-hello-world/src/test/resources/application.yml:
--------------------------------------------------------------------------------
1 | artemis:
2 | broker-url: vm://0
3 |
--------------------------------------------------------------------------------
/spring-jms-integration/src/test/resources/application.yml:
--------------------------------------------------------------------------------
1 | destination:
2 | integration: integration.q
3 |
--------------------------------------------------------------------------------
/spring-jms-artemis-hello-world/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | artemis:
2 | broker-url: tcp://localhost:61616
3 |
--------------------------------------------------------------------------------
/spring-jms-activemq-hello-world/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | activemq:
2 | broker-url: tcp://localhost:61616
3 |
--------------------------------------------------------------------------------
/spring-jms-activemq-hello-world/src/test/resources/application.yml:
--------------------------------------------------------------------------------
1 | activemq:
2 | broker-url: vm://embedded-broker?broker.persistent=false
3 |
--------------------------------------------------------------------------------
/spring-jms-topic/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | activemq:
2 | broker-url: tcp://localhost:61616
3 |
4 | destination:
5 | topic: topic.t
6 |
--------------------------------------------------------------------------------
/spring-jms-annotations/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | activemq:
3 | broker-url: tcp://localhost:61616
4 |
5 | destination:
6 | boot: boot.q
7 |
--------------------------------------------------------------------------------
/spring-jms-message-converter/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | activemq:
3 | broker-url: tcp://localhost:61616
4 |
5 | queue:
6 | boot: converter.q
7 |
--------------------------------------------------------------------------------
/spring-jms-message-selector/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | activemq:
3 | broker-url: tcp://localhost:61616
4 |
5 | queue:
6 | boot: selector.q
7 |
--------------------------------------------------------------------------------
/spring-jms-topic/src/test/resources/application.yml:
--------------------------------------------------------------------------------
1 | activemq:
2 | broker-url: vm://embedded-broker?broker.persistent=false
3 |
4 | destination:
5 | topic: topic.t
6 |
--------------------------------------------------------------------------------
/spring-jms-jmstemplate/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | activemq:
2 | broker-url: tcp://localhost:61616
3 |
4 | destination:
5 | order: order.q
6 | status: status.q
7 |
--------------------------------------------------------------------------------
/spring-jms-integration/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | activemq:
3 | broker-url: tcp://localhost:61616
4 |
5 | destination:
6 | integration: integration.q
7 |
--------------------------------------------------------------------------------
/spring-jms-jmstemplate/src/test/resources/application.yml:
--------------------------------------------------------------------------------
1 | activemq:
2 | broker-url: vm://embedded-broker?create=false
3 |
4 | destination:
5 | order: order.q
6 | status: status.q
7 |
--------------------------------------------------------------------------------
/spring-jms-listener/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | activemq:
2 | broker-url: tcp://localhost:61616
3 |
4 | destination:
5 | order: order.q
6 | status1: status1.q
7 | status2: status2.q
--------------------------------------------------------------------------------
/spring-jms-listener/src/test/resources/application.yml:
--------------------------------------------------------------------------------
1 | activemq:
2 | broker-url: vm://embedded-broker?create=false
3 |
4 | destination:
5 | order: order.q
6 | status1: status1.q
7 | status2: status2.q
--------------------------------------------------------------------------------
/spring-jms-integration-gateway/src/test/resources/application.yml:
--------------------------------------------------------------------------------
1 | destination:
2 | order:
3 | request: request.q
4 | response: response.q
5 |
6 | logging:
7 | level:
8 | org.springframework.integration: DEBUG
--------------------------------------------------------------------------------
/spring-jms-integration-gateway/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | activemq:
3 | broker-url: tcp://localhost:61616
4 |
5 | destination:
6 | order:
7 | request: request.q
8 | response: response.q
9 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ##Maven##
2 | target/
3 | pom.xml.tag
4 | pom.xml.releaseBackup
5 | pom.xml.next
6 | release.properties
7 |
8 | ##Eclipse##
9 | .classpath
10 | .project
11 | .settings/
12 |
13 | ##Logs##
14 | *.log
15 | *.log.*
16 |
--------------------------------------------------------------------------------
/spring-jms-topic/src/main/java/com/codenotfound/SpringJmsApplication.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringJmsApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringJmsApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-jms-annotations/src/main/java/com/codenotfound/SpringJmsApplication.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringJmsApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringJmsApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-jms-integration/src/main/java/com/codenotfound/SpringJmsApplication.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringJmsApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringJmsApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-jms-jmstemplate/src/main/java/com/codenotfound/SpringJmsApplication.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringJmsApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringJmsApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-jms-listener/src/main/java/com/codenotfound/SpringJmsApplication.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringJmsApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringJmsApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-jms-message-selector/src/main/java/com/codenotfound/SpringJmsApplication.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringJmsApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringJmsApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-jms-activemq-hello-world/src/main/java/com/codenotfound/SpringJmsApplication.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringJmsApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringJmsApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-jms-artemis-hello-world/src/main/java/com/codenotfound/SpringJmsApplication.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringJmsApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringJmsApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-jms-integration-gateway/src/main/java/com/codenotfound/SpringJmsApplication.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringJmsApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringJmsApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-jms-message-converter/src/main/java/com/codenotfound/SpringJmsApplication.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringJmsApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringJmsApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-jms-topic/README.md:
--------------------------------------------------------------------------------
1 | # spring-jms-topic
2 |
3 | [](https://sonarcloud.io/dashboard?id=com.codenotfound%3Aspring-jms-topic)
4 |
5 | A detailed step-by-step tutorial on how to publish/subscribe to a JMS topic using Spring JMS and Spring Boot.
6 |
7 | [https://codenotfound.com/spring-jms-topic-example.html](https://codenotfound.com/spring-jms-topic-example.html)
8 |
--------------------------------------------------------------------------------
/spring-jms-listener/README.md:
--------------------------------------------------------------------------------
1 | # spring-jms-listener
2 |
3 | [](https://sonarcloud.io/dashboard?id=com.codenotfound%3Aspring-jms-listener)
4 |
5 | A detailed step-by-step tutorial on how a Spring JMS listener works in combination with Spring Boot.
6 |
7 | [https://codenotfound.com/spring-jms-listener-example.html](https://codenotfound.com/spring-jms-listener-example.html)
8 |
--------------------------------------------------------------------------------
/spring-jms-integration/README.md:
--------------------------------------------------------------------------------
1 | # spring-jms-integration
2 |
3 | [](https://sonarcloud.io/dashboard?id=com.codenotfound%3Aspring-jms-integration)
4 |
5 | A detailed step-by-step tutorial on how to connect to a JMS broker using Spring Integration and Spring Boot.
6 |
7 | [https://codenotfound.com/spring-jms-integration-example.html](https://codenotfound.com/spring-jms-integration-example.html)
8 |
--------------------------------------------------------------------------------
/spring-jms-jmstemplate/README.md:
--------------------------------------------------------------------------------
1 | # spring-jms-jmstemplate
2 |
3 | [](https://sonarcloud.io/dashboard?id=com.codenotfound%3Aspring-jms-jmstemplate)
4 |
5 | A detailed step-by-step tutorial on how to use JmsTemplate in combination with Spring JMS and Spring Boot.
6 |
7 | [https://codenotfound.com/spring-jms-jmstemplate-example.html](https://codenotfound.com/spring-jms-jmstemplate-example.html)
8 |
--------------------------------------------------------------------------------
/spring-jms-annotations/README.md:
--------------------------------------------------------------------------------
1 | # spring-jms-annotations
2 |
3 | [](https://sonarcloud.io/dashboard?id=com.codenotfound%3Aspring-jms-annotations)
4 |
5 | A detailed step-by-step tutorial on how to autoconfigure Spring JMS using annotations in combination with Spring Boot.
6 |
7 | [https://codenotfound.com/spring-jms-annotations-example.html](https://codenotfound.com/spring-jms-annotations-example.html)
8 |
--------------------------------------------------------------------------------
/spring-jms-activemq-hello-world/README.md:
--------------------------------------------------------------------------------
1 | # spring-jms-activemq-hello-world
2 |
3 | [](https://sonarcloud.io/dashboard?id=com.codenotfound%3Aspring-jms-activemq-hello-world)
4 |
5 | A detailed step-by-step tutorial on how to connect to Apache ActiveMQ using Spring JMS and Spring Boot.
6 |
7 | [https://codenotfound.com/spring-jms-activemq-example.html](https://codenotfound.com/spring-jms-activemq-example.html)
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Spring JMS Tutorials
2 |
3 | [](https://travis-ci.org/code-not-found/spring-jms)
4 | [](./LICENSE)
5 |
6 | This repository contains the source code for the spring-jms examples posted on [https://codenotfound.com/spring-jms-tutorials](https://codenotfound.com/spring-jms-tutorials)
7 |
8 | In case of questions or remarks please leave a comment in the respective blog post or open a GitHub issue. Thanks!
9 |
--------------------------------------------------------------------------------
/spring-jms-artemis-hello-world/README.md:
--------------------------------------------------------------------------------
1 | # spring-jms-artemis-hello-world
2 |
3 | [](https://sonarcloud.io/dashboard?id=com.codenotfound%3Aspring-jms-artemis-hello-world)
4 |
5 | A detailed step-by-step tutorial on how to connect to Apache ActiveMQ Artemis using Spring JMS and Spring Boot.
6 |
7 | [https://codenotfound.com/spring-jms-artemis-example.html](https://codenotfound.com/spring-jms-artemis-example.html)
8 |
--------------------------------------------------------------------------------
/spring-jms-message-selector/README.md:
--------------------------------------------------------------------------------
1 | # spring-jms-message-selector
2 |
3 | [](https://sonarcloud.io/dashboard?id=com.codenotfound%3Aspring-jms-message-selector)
4 |
5 | A detailed step-by-step tutorial on how to implement a message selector using Spring JMS and Spring Boot.
6 |
7 | [https://codenotfound.com/spring-jms-message-selector-example.html](https://codenotfound.com/spring-jms-message-selector-example.html)
8 |
--------------------------------------------------------------------------------
/spring-jms-message-converter/README.md:
--------------------------------------------------------------------------------
1 | # spring-jms-message-converter
2 |
3 | [](https://sonarcloud.io/dashboard?id=com.codenotfound%3Aspring-jms-message-converter)
4 |
5 | A detailed step-by-step tutorial on how to implement a message converter using Spring JMS and Spring Boot.
6 |
7 | [https://codenotfound.com/spring-jms-message-converter-example.html](https://codenotfound.com/spring-jms-message-converter-example.html)
8 |
--------------------------------------------------------------------------------
/spring-jms-integration-gateway/README.md:
--------------------------------------------------------------------------------
1 | # spring-jms-integration-gateway
2 |
3 | [](https://sonarcloud.io/dashboard?id=com.codenotfound%3Aspring-jms-integration-gateway)
4 |
5 | A detailed step-by-step tutorial on how to connect to a JMS broker using a Spring Integration Gateway and Spring Boot.
6 |
7 | [https://codenotfound.com/spring-jms-integration-gateway-example.html](https://codenotfound.com/spring-jms-integration-gateway-example.html)
8 |
--------------------------------------------------------------------------------
/spring-jms-activemq-hello-world/src/main/java/com/codenotfound/jms/Sender.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.jms.core.JmsTemplate;
7 |
8 | public class Sender {
9 |
10 | private static final Logger LOGGER =
11 | LoggerFactory.getLogger(Sender.class);
12 |
13 | @Autowired
14 | private JmsTemplate jmsTemplate;
15 |
16 | public void send(String message) {
17 | LOGGER.info("sending message='{}'", message);
18 | jmsTemplate.convertAndSend("helloworld.q", message);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/spring-jms-artemis-hello-world/src/main/java/com/codenotfound/jms/Sender.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.jms.core.JmsTemplate;
7 |
8 | public class Sender {
9 |
10 | private static final Logger LOGGER =
11 | LoggerFactory.getLogger(Sender.class);
12 |
13 | @Autowired
14 | private JmsTemplate jmsTemplate;
15 |
16 | public void send(String message) {
17 | LOGGER.info("sending message='{}'", message);
18 | jmsTemplate.convertAndSend("helloworld.q", message);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/spring-jms-listener/src/main/java/com/codenotfound/jms/Sender.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.jms.core.JmsTemplate;
7 | import org.springframework.stereotype.Component;
8 |
9 | @Component
10 | public class Sender {
11 |
12 | private static final Logger LOGGER =
13 | LoggerFactory.getLogger(Sender.class);
14 |
15 | @Autowired
16 | private JmsTemplate jmsTemplate;
17 |
18 | public void send(String message) {
19 | LOGGER.info("sending message='{}'", message);
20 | jmsTemplate.convertAndSend(message);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/spring-jms-activemq-hello-world/src/main/java/com/codenotfound/jms/Receiver.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import java.util.concurrent.CountDownLatch;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.jms.annotation.JmsListener;
7 |
8 | public class Receiver {
9 |
10 | private static final Logger LOGGER =
11 | LoggerFactory.getLogger(Receiver.class);
12 |
13 | private CountDownLatch latch = new CountDownLatch(1);
14 |
15 | public CountDownLatch getLatch() {
16 | return latch;
17 | }
18 |
19 | @JmsListener(destination = "helloworld.q")
20 | public void receive(String message) {
21 | LOGGER.info("received message='{}'", message);
22 | latch.countDown();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/spring-jms-artemis-hello-world/src/main/java/com/codenotfound/jms/Receiver.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import java.util.concurrent.CountDownLatch;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.jms.annotation.JmsListener;
7 |
8 | public class Receiver {
9 |
10 | private static final Logger LOGGER =
11 | LoggerFactory.getLogger(Receiver.class);
12 |
13 | private CountDownLatch latch = new CountDownLatch(1);
14 |
15 | public CountDownLatch getLatch() {
16 | return latch;
17 | }
18 |
19 | @JmsListener(destination = "helloworld.q")
20 | public void receive(String message) {
21 | LOGGER.info("received message='{}'", message);
22 | latch.countDown();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/spring-jms-annotations/src/main/java/com/codenotfound/jms/Sender.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.jms.core.JmsTemplate;
7 | import org.springframework.stereotype.Component;
8 |
9 | @Component
10 | public class Sender {
11 |
12 | private static final Logger LOGGER =
13 | LoggerFactory.getLogger(Sender.class);
14 |
15 | @Autowired
16 | private JmsTemplate jmsTemplate;
17 |
18 | public void send(String destination, String message) {
19 | LOGGER.info("sending message='{}' to destination='{}'", message,
20 | destination);
21 | jmsTemplate.convertAndSend(destination, message);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/spring-jms-message-converter/src/main/java/com/codenotfound/jms/Sender.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.jms.core.JmsTemplate;
7 | import org.springframework.stereotype.Component;
8 |
9 | @Component
10 | public class Sender {
11 |
12 | private static final Logger LOGGER =
13 | LoggerFactory.getLogger(Sender.class);
14 |
15 | @Autowired
16 | private JmsTemplate jmsTemplate;
17 |
18 | public void send(String destination, Person person) {
19 | LOGGER.info("sending person='{}' to destination='{}'", person,
20 | destination);
21 | jmsTemplate.convertAndSend(destination, person);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/spring-jms-message-converter/src/main/java/com/codenotfound/jms/Person.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | public class Person {
4 |
5 | private String name;
6 |
7 | private int age;
8 |
9 | public Person() {
10 | super();
11 | }
12 |
13 | public Person(String name, int age) {
14 | super();
15 | this.name = name;
16 | this.age = age;
17 | }
18 |
19 | public String getName() {
20 | return name;
21 | }
22 |
23 | public void setName(String name) {
24 | this.name = name;
25 | }
26 |
27 | public int getAge() {
28 | return age;
29 | }
30 |
31 | public void setAge(int age) {
32 | this.age = age;
33 | }
34 |
35 | @Override
36 | public String toString() {
37 | return "person[name=" + name + ", age=" + age + "]";
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/spring-jms-annotations/src/main/java/com/codenotfound/jms/Receiver.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import java.util.concurrent.CountDownLatch;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.jms.annotation.JmsListener;
7 | import org.springframework.stereotype.Component;
8 |
9 | @Component
10 | public class Receiver {
11 |
12 | private static final Logger LOGGER =
13 | LoggerFactory.getLogger(Receiver.class);
14 |
15 | private CountDownLatch latch = new CountDownLatch(1);
16 |
17 | public CountDownLatch getLatch() {
18 | return latch;
19 | }
20 |
21 | @JmsListener(destination = "${queue.boot}")
22 | public void receive(String message) {
23 | LOGGER.info("received message='{}'", message);
24 | latch.countDown();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-jms-message-converter/src/main/java/com/codenotfound/jms/Receiver.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import java.util.concurrent.CountDownLatch;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.jms.annotation.JmsListener;
7 | import org.springframework.stereotype.Component;
8 |
9 | @Component
10 | public class Receiver {
11 |
12 | private static final Logger LOGGER =
13 | LoggerFactory.getLogger(Receiver.class);
14 |
15 | private CountDownLatch latch = new CountDownLatch(1);
16 |
17 | public CountDownLatch getLatch() {
18 | return latch;
19 | }
20 |
21 | @JmsListener(destination = "${queue.boot}")
22 | public void receive(Person person) {
23 | LOGGER.info("received person='{}'", person);
24 | latch.countDown();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-jms-integration/src/main/java/com/codenotfound/jms/CountDownLatchHandler.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import java.util.concurrent.CountDownLatch;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.messaging.Message;
7 | import org.springframework.messaging.MessageHandler;
8 |
9 | public class CountDownLatchHandler implements MessageHandler {
10 |
11 | private static final Logger LOGGER =
12 | LoggerFactory.getLogger(CountDownLatchHandler.class);
13 |
14 | private CountDownLatch latch = new CountDownLatch(10);
15 |
16 | public CountDownLatch getLatch() {
17 | return latch;
18 | }
19 |
20 | @Override
21 | public void handleMessage(Message> message) {
22 | LOGGER.info("received message='{}'", message);
23 | latch.countDown();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/spring-jms-integration-gateway/src/main/java/com/codenotfound/jms/OrderService.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.messaging.Message;
6 | import org.springframework.messaging.support.MessageBuilder;
7 |
8 | public class OrderService {
9 |
10 | private static final Logger LOGGER =
11 | LoggerFactory.getLogger(OrderService.class);
12 |
13 | public Message> order(Message> order) {
14 | LOGGER.info("received order='{}'", order);
15 |
16 | Message> status = MessageBuilder.withPayload("Accepted")
17 | .setHeader("jms_correlationId",
18 | order.getHeaders().get("jms_messageId"))
19 | .setReplyChannelName("inboundOrderResponseChannel").build();
20 | LOGGER.info("sending status='{}'", status);
21 |
22 | return status;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/spring-jms-topic/src/main/java/com/codenotfound/jms/Sender.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.beans.factory.annotation.Value;
7 | import org.springframework.jms.core.JmsTemplate;
8 | import org.springframework.stereotype.Component;
9 |
10 | @Component
11 | public class Sender {
12 |
13 | @Value("${destination.topic}")
14 | private String topicDestination;
15 |
16 | private static final Logger LOGGER =
17 | LoggerFactory.getLogger(Sender.class);
18 |
19 | @Autowired
20 | private JmsTemplate jmsTemplate;
21 |
22 | public void send(String message) {
23 | LOGGER.info("sending message='{}' to destination='{}'", message,
24 | topicDestination);
25 | jmsTemplate.convertAndSend(topicDestination, message);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | sudo: false
3 | install: true
4 |
5 | jdk:
6 | - openjdk11
7 |
8 | addons:
9 | sonarqube:
10 | organization: code-not-found-spring-jms
11 | token:
12 | secure: $SONAR_TOKEN
13 |
14 | env:
15 | - PROJECT_DIR=spring-jms-activemq-hello-world
16 | - PROJECT_DIR=spring-jms-annotations
17 | - PROJECT_DIR=spring-jms-artemis-hello-world
18 | - PROJECT_DIR=spring-jms-integration
19 | - PROJECT_DIR=spring-jms-integration-gateway
20 | - PROJECT_DIR=spring-jms-jmstemplate
21 | - PROJECT_DIR=spring-jms-listener
22 | - PROJECT_DIR=spring-jms-message-converter
23 | - PROJECT_DIR=spring-jms-message-selector
24 | - PROJECT_DIR=spring-jms-topic
25 |
26 | script:
27 | - cd $PROJECT_DIR
28 | - mvn test -B
29 | - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar
30 |
31 | cache:
32 | directories:
33 | - $HOME/.m2/repository
34 | - $HOME/.sonar/cache
35 |
36 | notifications:
37 | email: false
38 |
--------------------------------------------------------------------------------
/spring-jms-topic/src/test/java/com/codenotfound/SpringJmsApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 | import java.util.concurrent.TimeUnit;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.boot.test.context.SpringBootTest;
9 | import org.springframework.test.context.junit4.SpringRunner;
10 | import com.codenotfound.jms.Receiver;
11 | import com.codenotfound.jms.Sender;
12 |
13 | @RunWith(SpringRunner.class)
14 | @SpringBootTest
15 | public class SpringJmsApplicationTest {
16 |
17 | @Autowired
18 | private Sender sender;
19 |
20 | @Autowired
21 | private Receiver receiver;
22 |
23 | @Test
24 | public void testReceive() throws Exception {
25 | sender.send("order-001");
26 |
27 | receiver.getLatch().await(10000, TimeUnit.MILLISECONDS);
28 | assertThat(receiver.getLatch().getCount()).isEqualTo(0);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/spring-jms-annotations/src/test/java/com/codenotfound/jms/SpringJmsApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 | import java.util.concurrent.TimeUnit;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.boot.test.context.SpringBootTest;
9 | import org.springframework.test.annotation.DirtiesContext;
10 | import org.springframework.test.context.junit4.SpringRunner;
11 |
12 | @RunWith(SpringRunner.class)
13 | @SpringBootTest
14 | @DirtiesContext
15 | public class SpringJmsApplicationTest {
16 |
17 | @Autowired
18 | private Sender sender;
19 |
20 | @Autowired
21 | private Receiver receiver;
22 |
23 | @Test
24 | public void testReceive() throws Exception {
25 | sender.send("boot.q", "Hello Boot!");
26 |
27 | receiver.getLatch().await(10000, TimeUnit.MILLISECONDS);
28 | assertThat(receiver.getLatch().getCount()).isEqualTo(0);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/spring-jms-topic/src/main/java/com/codenotfound/jms/Receiver.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import java.util.concurrent.CountDownLatch;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.jms.annotation.JmsListener;
7 | import org.springframework.stereotype.Component;
8 |
9 | @Component
10 | public class Receiver {
11 |
12 | private static final Logger LOGGER =
13 | LoggerFactory.getLogger(Receiver.class);
14 |
15 | private CountDownLatch latch = new CountDownLatch(2);
16 |
17 | public CountDownLatch getLatch() {
18 | return latch;
19 | }
20 |
21 | @JmsListener(destination = "${destination.topic}")
22 | public void receive1(String message) {
23 | LOGGER.info("'subscriber1' received message='{}'", message);
24 | latch.countDown();
25 | }
26 |
27 | @JmsListener(destination = "${destination.topic}")
28 | public void receive2(String message) {
29 | LOGGER.info("'subscriber2' received message='{}'", message);
30 | latch.countDown();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/spring-jms-activemq-hello-world/src/test/java/com/codenotfound/SpringJmsApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 | import java.util.concurrent.TimeUnit;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.boot.test.context.SpringBootTest;
9 | import org.springframework.test.context.junit4.SpringRunner;
10 | import com.codenotfound.jms.Receiver;
11 | import com.codenotfound.jms.Sender;
12 |
13 | @RunWith(SpringRunner.class)
14 | @SpringBootTest
15 | public class SpringJmsApplicationTest {
16 |
17 | @Autowired
18 | private Sender sender;
19 |
20 | @Autowired
21 | private Receiver receiver;
22 |
23 | @Test
24 | public void testReceive() throws Exception {
25 | sender.send("Hello Spring JMS ActiveMQ!");
26 |
27 | receiver.getLatch().await(10000, TimeUnit.MILLISECONDS);
28 | assertThat(receiver.getLatch().getCount()).isEqualTo(0);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/spring-jms-message-converter/src/test/java/com/codenotfound/jms/SpringJmsApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 | import java.util.concurrent.TimeUnit;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.boot.test.context.SpringBootTest;
9 | import org.springframework.test.annotation.DirtiesContext;
10 | import org.springframework.test.context.junit4.SpringRunner;
11 |
12 | @RunWith(SpringRunner.class)
13 | @SpringBootTest
14 | @DirtiesContext
15 | public class SpringJmsApplicationTest {
16 |
17 | @Autowired
18 | private Sender sender;
19 |
20 | @Autowired
21 | private Receiver receiver;
22 |
23 | @Test
24 | public void testReceive() throws Exception {
25 | Person person = new Person("John Doe", 20);
26 | sender.send("converter.q", person);
27 |
28 | receiver.getLatch().await(10000, TimeUnit.MILLISECONDS);
29 | assertThat(receiver.getLatch().getCount()).isEqualTo(0);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/spring-jms-message-selector/src/main/java/com/codenotfound/jms/Receiver.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import java.util.concurrent.CountDownLatch;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.jms.annotation.JmsListener;
7 | import org.springframework.stereotype.Component;
8 |
9 | @Component
10 | public class Receiver {
11 |
12 | private static final Logger LOGGER =
13 | LoggerFactory.getLogger(Receiver.class);
14 |
15 | private CountDownLatch latch = new CountDownLatch(2);
16 |
17 | public CountDownLatch getLatch() {
18 | return latch;
19 | }
20 |
21 | @JmsListener(destination = "${queue.boot}",
22 | selector = "priority = 'high'")
23 | public void receiveHigh(String message) {
24 | LOGGER.info("received high priority message='{}'", message);
25 | latch.countDown();
26 | }
27 |
28 | @JmsListener(destination = "${queue.boot}",
29 | selector = "priority = 'low'")
30 | public void receiveLow(String message) {
31 | LOGGER.info("received low priority message='{}'", message);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 code-not-found
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 |
--------------------------------------------------------------------------------
/spring-jms-jmstemplate/src/test/java/com/codenotfound/SpringJmsApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 | import org.apache.activemq.junit.EmbeddedActiveMQBroker;
5 | import org.junit.ClassRule;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.test.annotation.DirtiesContext;
11 | import org.springframework.test.context.junit4.SpringRunner;
12 | import com.codenotfound.jms.Sender;
13 |
14 | @RunWith(SpringRunner.class)
15 | @SpringBootTest
16 | @DirtiesContext
17 | public class SpringJmsApplicationTest {
18 |
19 | @ClassRule
20 | public static EmbeddedActiveMQBroker broker =
21 | new EmbeddedActiveMQBroker();
22 |
23 | @Autowired
24 | private Sender sender;
25 |
26 | @Test
27 | public void testReceive() throws Exception {
28 | String correlationId = sender.sendOrder("order-001");
29 | String status = sender.receiveOrderStatus(correlationId);
30 |
31 | assertThat(status).isEqualTo("Accepted");
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/spring-jms-message-selector/src/test/java/com/codenotfound/jms/SpringJmsApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 | import java.util.concurrent.TimeUnit;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.boot.test.context.SpringBootTest;
9 | import org.springframework.test.annotation.DirtiesContext;
10 | import org.springframework.test.context.junit4.SpringRunner;
11 |
12 | @RunWith(SpringRunner.class)
13 | @SpringBootTest
14 | @DirtiesContext
15 | public class SpringJmsApplicationTest {
16 |
17 | @Autowired
18 | private Sender sender;
19 |
20 | @Autowired
21 | private Receiver receiver;
22 |
23 | @Test
24 | public void testReceive() throws Exception {
25 | sender.send("selector.q", "High priority 1!", true);
26 | sender.send("selector.q", "Low priority 1!", false);
27 | sender.send("selector.q", "High priority 2!", true);
28 |
29 | receiver.getLatch().await(10000, TimeUnit.MILLISECONDS);
30 | assertThat(receiver.getLatch().getCount()).isEqualTo(0);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/spring-jms-artemis-hello-world/src/main/java/com/codenotfound/jms/SenderConfig.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.jms.connection.CachingConnectionFactory;
8 | import org.springframework.jms.core.JmsTemplate;
9 |
10 | @Configuration
11 | public class SenderConfig {
12 |
13 | @Value("${artemis.broker-url}")
14 | private String brokerUrl;
15 |
16 | @Bean
17 | public ActiveMQConnectionFactory senderActiveMQConnectionFactory() {
18 | return new ActiveMQConnectionFactory(brokerUrl);
19 | }
20 |
21 | @Bean
22 | public CachingConnectionFactory cachingConnectionFactory() {
23 | return new CachingConnectionFactory(
24 | senderActiveMQConnectionFactory());
25 | }
26 |
27 | @Bean
28 | public JmsTemplate jmsTemplate() {
29 | return new JmsTemplate(cachingConnectionFactory());
30 | }
31 |
32 | @Bean
33 | public Sender sender() {
34 | return new Sender();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/spring-jms-artemis-hello-world/src/test/java/com/codenotfound/SpringJmsApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 | import java.util.concurrent.TimeUnit;
5 | import org.apache.activemq.artemis.junit.EmbeddedJMSResource;
6 | import org.junit.Rule;
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.boot.test.context.SpringBootTest;
11 | import org.springframework.test.context.junit4.SpringRunner;
12 | import com.codenotfound.jms.Receiver;
13 | import com.codenotfound.jms.Sender;
14 |
15 | @RunWith(SpringRunner.class)
16 | @SpringBootTest
17 | public class SpringJmsApplicationTest {
18 |
19 | @Rule
20 | public EmbeddedJMSResource resource = new EmbeddedJMSResource();
21 |
22 | @Autowired
23 | private Sender sender;
24 |
25 | @Autowired
26 | private Receiver receiver;
27 |
28 | @Test
29 | public void testReceive() throws Exception {
30 | sender.send("Hello Spring JMS ActiveMQ!");
31 |
32 | receiver.getLatch().await(10000, TimeUnit.MILLISECONDS);
33 | assertThat(receiver.getLatch().getCount()).isEqualTo(0);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/spring-jms-listener/src/main/java/com/codenotfound/jms/OrderReceiver.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.beans.factory.annotation.Value;
7 | import org.springframework.jms.annotation.JmsListener;
8 | import org.springframework.jms.core.JmsTemplate;
9 | import org.springframework.stereotype.Component;
10 |
11 | @Component
12 | public class OrderReceiver {
13 |
14 | private static final Logger LOGGER =
15 | LoggerFactory.getLogger(OrderReceiver.class);
16 |
17 | @Value("${destination.status1}")
18 | private String status1Destination;
19 |
20 | @Value("${destination.status2}")
21 | private String status2Destination;
22 |
23 | @Autowired
24 | JmsTemplate jmsTemplate;
25 |
26 | @JmsListener(destination = "${destination.order}",
27 | containerFactory = "orderDefaultJmsListenerContainerFactory")
28 | public void receiveOrder(String order) {
29 | LOGGER.info("received order='{}'", order);
30 | jmsTemplate.convertAndSend(status1Destination, "Accepted");
31 | jmsTemplate.convertAndSend(status2Destination, "Accepted");
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/spring-jms-integration/src/main/java/com/codenotfound/jms/ProducingChannelConfig.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.integration.annotation.ServiceActivator;
7 | import org.springframework.integration.channel.DirectChannel;
8 | import org.springframework.integration.jms.JmsSendingMessageHandler;
9 | import org.springframework.jms.core.JmsTemplate;
10 | import org.springframework.messaging.MessageHandler;
11 |
12 | @Configuration
13 | public class ProducingChannelConfig {
14 |
15 | @Value("${destination.integration}")
16 | private String integrationDestination;
17 |
18 | @Bean
19 | public DirectChannel producingChannel() {
20 | return new DirectChannel();
21 | }
22 |
23 | @Bean
24 | @ServiceActivator(inputChannel = "producingChannel")
25 | public MessageHandler jmsMessageHandler(JmsTemplate jmsTemplate) {
26 | JmsSendingMessageHandler handler =
27 | new JmsSendingMessageHandler(jmsTemplate);
28 | handler.setDestinationName(integrationDestination);
29 |
30 | return handler;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/spring-jms-artemis-hello-world/src/main/java/com/codenotfound/jms/ReceiverConfig.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.jms.annotation.EnableJms;
8 | import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
9 |
10 | @Configuration
11 | @EnableJms
12 | public class ReceiverConfig {
13 |
14 | @Value("${artemis.broker-url}")
15 | private String brokerUrl;
16 |
17 | @Bean
18 | public ActiveMQConnectionFactory receiverActiveMQConnectionFactory() {
19 | return new ActiveMQConnectionFactory(brokerUrl);
20 | }
21 |
22 | @Bean
23 | public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
24 | DefaultJmsListenerContainerFactory factory =
25 | new DefaultJmsListenerContainerFactory();
26 | factory
27 | .setConnectionFactory(receiverActiveMQConnectionFactory());
28 | factory.setConcurrency("3-10");
29 |
30 | return factory;
31 | }
32 |
33 | @Bean
34 | public Receiver receiver() {
35 | return new Receiver();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/spring-jms-listener/src/main/java/com/codenotfound/jms/StatusMessageListener.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import java.util.concurrent.CountDownLatch;
4 | import javax.jms.JMSException;
5 | import javax.jms.Message;
6 | import javax.jms.MessageListener;
7 | import javax.jms.TextMessage;
8 | import org.slf4j.Logger;
9 | import org.slf4j.LoggerFactory;
10 |
11 | public class StatusMessageListener implements MessageListener {
12 |
13 | private static final Logger LOGGER =
14 | LoggerFactory.getLogger(Sender.class);
15 |
16 | private String id;
17 |
18 | private CountDownLatch latch = new CountDownLatch(1);
19 |
20 | public StatusMessageListener(String id) {
21 | super();
22 | this.id = id;
23 | }
24 |
25 | @Override
26 | public void onMessage(Message message) {
27 | if (message instanceof TextMessage) {
28 | try {
29 | String text = ((TextMessage) message).getText();
30 | LOGGER.info("id='{}' received status='{}'", id, text);
31 | latch.countDown();
32 | } catch (JMSException e) {
33 | LOGGER.error("unable to read message payload", e);
34 | }
35 | } else {
36 | LOGGER.error("received unsupported message type");
37 | }
38 | }
39 |
40 | public CountDownLatch getLatch() {
41 | return latch;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/spring-jms-topic/src/main/java/com/codenotfound/jms/ReceiverConfig.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.apache.activemq.ActiveMQConnectionFactory;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.jms.annotation.EnableJms;
8 | import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
9 |
10 | @Configuration
11 | @EnableJms
12 | public class ReceiverConfig {
13 |
14 | @Value("${activemq.broker-url}")
15 | private String brokerUrl;
16 |
17 | @Bean
18 | public ActiveMQConnectionFactory receiverActiveMQConnectionFactory() {
19 | ActiveMQConnectionFactory activeMQConnectionFactory =
20 | new ActiveMQConnectionFactory();
21 | activeMQConnectionFactory.setBrokerURL(brokerUrl);
22 |
23 | return activeMQConnectionFactory;
24 | }
25 |
26 | @Bean
27 | public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
28 | DefaultJmsListenerContainerFactory factory =
29 | new DefaultJmsListenerContainerFactory();
30 | factory
31 | .setConnectionFactory(receiverActiveMQConnectionFactory());
32 | factory.setPubSubDomain(true);
33 |
34 | return factory;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/spring-jms-jmstemplate/src/main/java/com/codenotfound/jms/ReceiverConfig.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.apache.activemq.ActiveMQConnectionFactory;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.jms.annotation.EnableJms;
8 | import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
9 |
10 | @Configuration
11 | @EnableJms
12 | public class ReceiverConfig {
13 |
14 | @Value("${activemq.broker-url}")
15 | private String brokerUrl;
16 |
17 | @Bean
18 | public ActiveMQConnectionFactory receiverActiveMQConnectionFactory() {
19 | ActiveMQConnectionFactory activeMQConnectionFactory =
20 | new ActiveMQConnectionFactory();
21 | activeMQConnectionFactory.setBrokerURL(brokerUrl);
22 |
23 | return activeMQConnectionFactory;
24 | }
25 |
26 | @Bean
27 | public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
28 | DefaultJmsListenerContainerFactory factory =
29 | new DefaultJmsListenerContainerFactory();
30 | factory
31 | .setConnectionFactory(receiverActiveMQConnectionFactory());
32 | factory.setConcurrency("3-10");
33 |
34 | return factory;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/spring-jms-activemq-hello-world/src/main/java/com/codenotfound/jms/SenderConfig.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.apache.activemq.ActiveMQConnectionFactory;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.jms.connection.CachingConnectionFactory;
8 | import org.springframework.jms.core.JmsTemplate;
9 |
10 | @Configuration
11 | public class SenderConfig {
12 |
13 | @Value("${activemq.broker-url}")
14 | private String brokerUrl;
15 |
16 | @Bean
17 | public ActiveMQConnectionFactory senderActiveMQConnectionFactory() {
18 | ActiveMQConnectionFactory activeMQConnectionFactory =
19 | new ActiveMQConnectionFactory();
20 | activeMQConnectionFactory.setBrokerURL(brokerUrl);
21 |
22 | return activeMQConnectionFactory;
23 | }
24 |
25 | @Bean
26 | public CachingConnectionFactory cachingConnectionFactory() {
27 | return new CachingConnectionFactory(
28 | senderActiveMQConnectionFactory());
29 | }
30 |
31 | @Bean
32 | public JmsTemplate jmsTemplate() {
33 | return new JmsTemplate(cachingConnectionFactory());
34 | }
35 |
36 | @Bean
37 | public Sender sender() {
38 | return new Sender();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/spring-jms-topic/src/main/java/com/codenotfound/jms/SenderConfig.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.apache.activemq.ActiveMQConnectionFactory;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.jms.connection.CachingConnectionFactory;
8 | import org.springframework.jms.core.JmsTemplate;
9 |
10 | @Configuration
11 | public class SenderConfig {
12 |
13 | @Value("${activemq.broker-url}")
14 | private String brokerUrl;
15 |
16 | @Bean
17 | public ActiveMQConnectionFactory senderActiveMQConnectionFactory() {
18 | ActiveMQConnectionFactory activeMQConnectionFactory =
19 | new ActiveMQConnectionFactory();
20 | activeMQConnectionFactory.setBrokerURL(brokerUrl);
21 |
22 | return activeMQConnectionFactory;
23 | }
24 |
25 | @Bean
26 | public CachingConnectionFactory cachingConnectionFactory() {
27 | return new CachingConnectionFactory(
28 | senderActiveMQConnectionFactory());
29 | }
30 |
31 | @Bean
32 | public JmsTemplate jmsTemplate() {
33 | JmsTemplate jmsTemplate =
34 | new JmsTemplate(cachingConnectionFactory());
35 | jmsTemplate.setPubSubDomain(true);
36 |
37 | return jmsTemplate;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/spring-jms-message-selector/src/main/java/com/codenotfound/jms/Sender.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.jms.core.JmsTemplate;
7 | import org.springframework.stereotype.Component;
8 |
9 | @Component
10 | public class Sender {
11 |
12 | private static final Logger LOGGER =
13 | LoggerFactory.getLogger(Sender.class);
14 |
15 | @Autowired
16 | private JmsTemplate jmsTemplate;
17 |
18 | public void send(String destination, String message,
19 | boolean isHighPriority) {
20 | LOGGER.info("sending message='{}' with highPriority='{}'",
21 | message, isHighPriority);
22 |
23 | if (isHighPriority) {
24 | jmsTemplate.convertAndSend(destination, message,
25 | messagePostProcessor -> {
26 | messagePostProcessor.setStringProperty("priority",
27 | "high");
28 | return messagePostProcessor;
29 | });
30 | } else {
31 | jmsTemplate.convertAndSend(destination, message,
32 | messagePostProcessor -> {
33 | messagePostProcessor.setStringProperty("priority",
34 | "low");
35 | return messagePostProcessor;
36 | });
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/spring-jms-activemq-hello-world/src/main/java/com/codenotfound/jms/ReceiverConfig.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.apache.activemq.ActiveMQConnectionFactory;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.jms.annotation.EnableJms;
8 | import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
9 |
10 | @Configuration
11 | @EnableJms
12 | public class ReceiverConfig {
13 |
14 | @Value("${activemq.broker-url}")
15 | private String brokerUrl;
16 |
17 | @Bean
18 | public ActiveMQConnectionFactory receiverActiveMQConnectionFactory() {
19 | ActiveMQConnectionFactory activeMQConnectionFactory =
20 | new ActiveMQConnectionFactory();
21 | activeMQConnectionFactory.setBrokerURL(brokerUrl);
22 |
23 | return activeMQConnectionFactory;
24 | }
25 |
26 | @Bean
27 | public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
28 | DefaultJmsListenerContainerFactory factory =
29 | new DefaultJmsListenerContainerFactory();
30 | factory
31 | .setConnectionFactory(receiverActiveMQConnectionFactory());
32 |
33 | return factory;
34 | }
35 |
36 | @Bean
37 | public Receiver receiver() {
38 | return new Receiver();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/spring-jms-listener/src/main/java/com/codenotfound/jms/SenderConfig.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.apache.activemq.ActiveMQConnectionFactory;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.jms.connection.CachingConnectionFactory;
8 | import org.springframework.jms.core.JmsTemplate;
9 |
10 | @Configuration
11 | public class SenderConfig {
12 |
13 | @Value("${activemq.broker-url}")
14 | private String brokerUrl;
15 |
16 | @Value("${destination.order}")
17 | private String orderDestination;
18 |
19 | @Bean
20 | public ActiveMQConnectionFactory senderActiveMQConnectionFactory() {
21 | ActiveMQConnectionFactory activeMQConnectionFactory =
22 | new ActiveMQConnectionFactory();
23 | activeMQConnectionFactory.setBrokerURL(brokerUrl);
24 |
25 | return activeMQConnectionFactory;
26 | }
27 |
28 | @Bean
29 | public CachingConnectionFactory cachingConnectionFactory() {
30 | return new CachingConnectionFactory(
31 | senderActiveMQConnectionFactory());
32 | }
33 |
34 | @Bean
35 | public JmsTemplate orderJmsTemplate() {
36 | JmsTemplate jmsTemplate =
37 | new JmsTemplate(cachingConnectionFactory());
38 | jmsTemplate.setDefaultDestinationName(orderDestination);
39 |
40 | return jmsTemplate;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/spring-jms-jmstemplate/src/main/java/com/codenotfound/jms/Receiver.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import javax.jms.Destination;
4 | import javax.jms.TextMessage;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.jms.annotation.JmsListener;
9 | import org.springframework.jms.core.JmsTemplate;
10 | import org.springframework.jms.support.JmsHeaders;
11 | import org.springframework.messaging.handler.annotation.Header;
12 | import org.springframework.stereotype.Component;
13 |
14 | @Component
15 | public class Receiver {
16 |
17 | @Autowired
18 | private Destination statusDestination;
19 |
20 | @Autowired
21 | private JmsTemplate jmsTemplate;
22 |
23 | private static final Logger LOGGER =
24 | LoggerFactory.getLogger(Receiver.class);
25 |
26 | @JmsListener(destination = "${destination.order}")
27 | public void receiveOrder(String orderNumber,
28 | @Header(JmsHeaders.MESSAGE_ID) String messageId) {
29 | LOGGER.info("received OrderNumber='{}' with MessageId='{}'",
30 | orderNumber, messageId);
31 |
32 | LOGGER.info("sending Status='Accepted' with CorrelationId='{}'",
33 | messageId);
34 |
35 | jmsTemplate.send(statusDestination, messageCreator -> {
36 | TextMessage message =
37 | messageCreator.createTextMessage("Accepted");
38 | message.setJMSCorrelationID(messageId);
39 | return message;
40 | });
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/spring-jms-integration-gateway/src/test/java/com/codenotfound/jms/SpringJmsApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.boot.test.context.SpringBootTest;
8 | import org.springframework.context.ApplicationContext;
9 | import org.springframework.integration.channel.QueueChannel;
10 | import org.springframework.messaging.MessageChannel;
11 | import org.springframework.messaging.support.GenericMessage;
12 | import org.springframework.test.annotation.DirtiesContext;
13 | import org.springframework.test.context.junit4.SpringRunner;
14 |
15 | @RunWith(SpringRunner.class)
16 | @SpringBootTest
17 | @DirtiesContext
18 | public class SpringJmsApplicationTest {
19 |
20 | @Autowired
21 | private ApplicationContext applicationContext;
22 |
23 | @Test
24 | public void testIntegrationGateway() {
25 | MessageChannel outboundOrderRequestChannel =
26 | applicationContext.getBean("outboundOrderRequestChannel",
27 | MessageChannel.class);
28 | QueueChannel outboundOrderResponseChannel = applicationContext
29 | .getBean("outboundOrderResponseChannel", QueueChannel.class);
30 |
31 | outboundOrderRequestChannel
32 | .send(new GenericMessage<>("order-001"));
33 |
34 | assertThat(
35 | outboundOrderResponseChannel.receive(5000).getPayload())
36 | .isEqualTo("Accepted");;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/spring-jms-topic/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.codenotfound
8 | spring-jms-topic
9 | 0.0.1-SNAPSHOT
10 |
11 | spring-jms-topic
12 | Spring JMS Topic Example
13 | https://codenotfound.com/spring-jms-topic-example.html
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-parent
18 | 2.1.5.RELEASE
19 |
20 |
21 |
22 |
23 | 11
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-activemq
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-test
34 | test
35 |
36 |
37 |
38 |
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-maven-plugin
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/spring-jms-annotations/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.codenotfound
8 | spring-jms-annotations
9 | 0.0.1-SNAPSHOT
10 |
11 | spring-jms-annotations
12 | Spring JMS Annotations Example
13 | https://codenotfound.com/spring-jms-annotations-example.html
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-parent
18 | 2.1.5.RELEASE
19 |
20 |
21 |
22 |
23 | 11
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-activemq
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-test
34 | test
35 |
36 |
37 |
38 |
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-maven-plugin
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/spring-jms-activemq-hello-world/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.codenotfound
8 | spring-jms-activemq-hello-world
9 | 0.0.1-SNAPSHOT
10 |
11 | spring-jms-activemq-hello-world
12 | Spring JMS ActiveMQ Example
13 | https://codenotfound.com/spring-jms-activemq-example.html
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-parent
18 | 2.1.5.RELEASE
19 |
20 |
21 |
22 |
23 | 11
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-activemq
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-test
34 | test
35 |
36 |
37 |
38 |
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-maven-plugin
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/spring-jms-message-selector/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.codenotfound
7 | spring-jms-message-selector
8 | 0.0.1-SNAPSHOT
9 |
10 | spring-jms-message-selector
11 | Spring JMS Message Selector Example
12 | https://codenotfound.com/spring-jms-message-selector-example.html
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.1.5.RELEASE
18 |
19 |
20 |
21 |
22 | 11
23 |
24 |
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-starter-activemq
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-starter-test
33 | test
34 |
35 |
36 |
37 |
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-maven-plugin
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/spring-jms-message-converter/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.codenotfound
8 | spring-jms-message-converter
9 | 0.0.1-SNAPSHOT
10 |
11 | spring-jms-message-converter
12 | Spring JMS Message Converter Example
13 | https://codenotfound.com/spring-jms-message-converter-example.html
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-parent
18 | 2.1.5.RELEASE
19 |
20 |
21 |
22 |
23 | 11
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-activemq
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-test
34 | test
35 |
36 |
37 |
38 |
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-maven-plugin
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/spring-jms-jmstemplate/src/main/java/com/codenotfound/jms/Sender.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import java.util.concurrent.atomic.AtomicReference;
4 | import javax.jms.Destination;
5 | import javax.jms.JMSException;
6 | import javax.jms.Message;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.jms.core.JmsTemplate;
11 | import org.springframework.stereotype.Component;
12 |
13 | @Component
14 | public class Sender {
15 |
16 | private static final Logger LOGGER =
17 | LoggerFactory.getLogger(Sender.class);
18 |
19 | @Autowired
20 | private Destination statusDestination;
21 |
22 | @Autowired
23 | private JmsTemplate jmsTemplate;
24 |
25 | public String sendOrder(String orderNumber) throws JMSException {
26 | final AtomicReference message = new AtomicReference<>();
27 |
28 | jmsTemplate.convertAndSend(orderNumber, messagePostProcessor -> {
29 | message.set(messagePostProcessor);
30 | return messagePostProcessor;
31 | });
32 |
33 | String messageId = message.get().getJMSMessageID();
34 | LOGGER.info("sending OrderNumber='{}' with MessageId='{}'",
35 | orderNumber, messageId);
36 |
37 | return messageId;
38 | }
39 |
40 | public String receiveOrderStatus(String correlationId) {
41 | String status = (String) jmsTemplate.receiveSelectedAndConvert(
42 | statusDestination,
43 | "JMSCorrelationID = '" + correlationId + "'");
44 | LOGGER.info("receive Status='{}' for CorrelationId='{}'", status,
45 | correlationId);
46 |
47 | return status;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/spring-jms-integration-gateway/src/main/java/com/codenotfound/jms/OutboundGatewayConfig.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import javax.jms.ConnectionFactory;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.integration.annotation.ServiceActivator;
8 | import org.springframework.integration.channel.DirectChannel;
9 | import org.springframework.integration.channel.QueueChannel;
10 | import org.springframework.integration.jms.JmsOutboundGateway;
11 | import org.springframework.messaging.MessageChannel;
12 |
13 | @Configuration
14 | public class OutboundGatewayConfig {
15 |
16 | @Value("${destination.order.request}")
17 | private String orderRequestDestination;
18 |
19 | @Value("${destination.order.response}")
20 | private String orderResponseDestination;
21 |
22 | @Bean
23 | public MessageChannel outboundOrderRequestChannel() {
24 | return new DirectChannel();
25 | }
26 |
27 | @Bean
28 | public MessageChannel outboundOrderResponseChannel() {
29 | return new QueueChannel();
30 | }
31 |
32 | @Bean
33 | @ServiceActivator(inputChannel = "outboundOrderRequestChannel")
34 | public JmsOutboundGateway jmsOutboundGateway(
35 | ConnectionFactory connectionFactory) {
36 | JmsOutboundGateway gateway = new JmsOutboundGateway();
37 | gateway.setConnectionFactory(connectionFactory);
38 | gateway.setRequestDestinationName(orderRequestDestination);
39 | gateway.setReplyDestinationName(orderResponseDestination);
40 | gateway.setReplyChannel(outboundOrderResponseChannel());
41 |
42 | return gateway;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/spring-jms-integration/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.codenotfound
8 | spring-jms-integration
9 | 0.0.1-SNAPSHOT
10 |
11 | spring-jms-integration
12 | Spring JMS Integration Example
13 | https://codenotfound.com/spring-jms-integration-example.html
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-parent
18 | 2.1.5.RELEASE
19 |
20 |
21 |
22 |
23 | 11
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-activemq
30 |
31 |
32 | org.springframework.integration
33 | spring-integration-jms
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-starter-test
38 | test
39 |
40 |
41 |
42 |
43 |
44 |
45 | org.springframework.boot
46 | spring-boot-maven-plugin
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/spring-jms-integration-gateway/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.codenotfound
8 | spring-jms-integration-gateway
9 | 0.0.1-SNAPSHOT
10 |
11 | spring-jms-integration-gateway
12 | Spring JMS Integration Gateway Example
13 | https://codenotfound.com/spring-jms-integration-gateway-example.html
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-parent
18 | 2.1.5.RELEASE
19 |
20 |
21 |
22 |
23 | 11
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-activemq
30 |
31 |
32 | org.springframework.integration
33 | spring-integration-jms
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-starter-test
38 | test
39 |
40 |
41 |
42 |
43 |
44 |
45 | org.springframework.boot
46 | spring-boot-maven-plugin
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/spring-jms-listener/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.codenotfound
8 | spring-jms-listener
9 | 0.0.1-SNAPSHOT
10 |
11 | spring-jms-listener
12 | Spring JMS Listener Example
13 | https://codenotfound.com/spring-jms-listener-example.html
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-parent
18 | 2.1.5.RELEASE
19 |
20 |
21 |
22 |
23 | 11
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-activemq
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-test
34 | test
35 |
36 |
37 | org.apache.activemq.tooling
38 | activemq-junit
39 | ${activemq.version}
40 | test
41 |
42 |
43 |
44 |
45 |
46 |
47 | org.springframework.boot
48 | spring-boot-maven-plugin
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/spring-jms-jmstemplate/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.codenotfound
8 | spring-jms-jmstemplate
9 | 0.0.1-SNAPSHOT
10 |
11 | spring-jms-jmstemplate
12 | Spring JMS JmsTemplate Example
13 | https://codenotfound.com/spring-jms-jmstemplate.html
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-parent
18 | 2.1.5.RELEASE
19 |
20 |
21 |
22 |
23 | 11
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-activemq
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-test
34 | test
35 |
36 |
37 | org.apache.activemq.tooling
38 | activemq-junit
39 | ${activemq.version}
40 | test
41 |
42 |
43 |
44 |
45 |
46 |
47 | org.springframework.boot
48 | spring-boot-maven-plugin
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/spring-jms-artemis-hello-world/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.codenotfound
8 | spring-jms-artemis-hello-world
9 | 0.0.1-SNAPSHOT
10 |
11 | spring-jms-artemis-hello-world
12 | Spring JMS Artemis Example
13 | https://codenotfound.com/spring-jms-artemis-example.html
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-parent
18 | 2.1.5.RELEASE
19 |
20 |
21 |
22 |
23 | 11
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-artemis
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-test
34 | test
35 |
36 |
37 | org.apache.activemq
38 | artemis-junit
39 | ${artemis.version}
40 | test
41 |
42 |
43 |
44 |
45 |
46 |
47 | org.springframework.boot
48 | spring-boot-maven-plugin
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/spring-jms-message-converter/src/main/java/com/codenotfound/jms/PersonMessageConverter.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import javax.jms.JMSException;
4 | import javax.jms.Message;
5 | import javax.jms.Session;
6 | import javax.jms.TextMessage;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 | import org.springframework.jms.support.converter.MessageConverter;
10 | import org.springframework.stereotype.Component;
11 | import com.fasterxml.jackson.core.JsonProcessingException;
12 | import com.fasterxml.jackson.databind.ObjectMapper;
13 |
14 | @Component
15 | public class PersonMessageConverter implements MessageConverter {
16 |
17 | private static final Logger LOGGER =
18 | LoggerFactory.getLogger(PersonMessageConverter.class);
19 |
20 | ObjectMapper mapper;
21 |
22 | public PersonMessageConverter() {
23 | mapper = new ObjectMapper();
24 | }
25 |
26 | @Override
27 | public Message toMessage(Object object, Session session)
28 | throws JMSException {
29 | Person person = (Person) object;
30 | String payload = null;
31 | try {
32 | payload = mapper.writeValueAsString(person);
33 | LOGGER.info("outbound json='{}'", payload);
34 | } catch (JsonProcessingException e) {
35 | LOGGER.error("error converting form person", e);
36 | }
37 |
38 | TextMessage message = session.createTextMessage();
39 | message.setText(payload);
40 |
41 | return message;
42 | }
43 |
44 | @Override
45 | public Object fromMessage(Message message) throws JMSException {
46 | TextMessage textMessage = (TextMessage) message;
47 | String payload = textMessage.getText();
48 | LOGGER.info("inbound json='{}'", payload);
49 |
50 | Person person = null;
51 | try {
52 | person = mapper.readValue(payload, Person.class);
53 | } catch (Exception e) {
54 | LOGGER.error("error converting to person", e);
55 | }
56 |
57 | return person;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/spring-jms-listener/src/test/java/com/codenotfound/SpringJmsApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 | import java.util.concurrent.TimeUnit;
5 | import org.apache.activemq.junit.EmbeddedActiveMQBroker;
6 | import org.junit.ClassRule;
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.boot.test.context.SpringBootTest;
11 | import org.springframework.jms.listener.DefaultMessageListenerContainer;
12 | import org.springframework.jms.listener.SimpleMessageListenerContainer;
13 | import org.springframework.test.annotation.DirtiesContext;
14 | import org.springframework.test.context.junit4.SpringRunner;
15 | import com.codenotfound.jms.Sender;
16 | import com.codenotfound.jms.StatusMessageListener;
17 |
18 | @RunWith(SpringRunner.class)
19 | @SpringBootTest
20 | @DirtiesContext
21 | public class SpringJmsApplicationTest {
22 |
23 | @ClassRule
24 | public static EmbeddedActiveMQBroker broker =
25 | new EmbeddedActiveMQBroker();
26 |
27 | @Autowired
28 | private Sender sender;
29 |
30 | @Autowired
31 | private DefaultMessageListenerContainer dmlc;
32 |
33 | @Autowired
34 | private SimpleMessageListenerContainer smlc;
35 |
36 | @Test
37 | public void testReceive() throws Exception {
38 | sender.send("order-002");
39 |
40 | StatusMessageListener status1MessageListener =
41 | (StatusMessageListener) dmlc.getMessageListener();
42 | status1MessageListener.getLatch().await(10000,
43 | TimeUnit.MILLISECONDS);
44 | assertThat(status1MessageListener.getLatch().getCount())
45 | .isEqualTo(0);
46 |
47 | StatusMessageListener status2MessageListener =
48 | (StatusMessageListener) smlc.getMessageListener();
49 | status2MessageListener.getLatch().await(10000,
50 | TimeUnit.MILLISECONDS);
51 | assertThat(status2MessageListener.getLatch().getCount())
52 | .isEqualTo(0);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/spring-jms-jmstemplate/src/main/java/com/codenotfound/jms/SenderConfig.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import javax.jms.Destination;
4 | import org.apache.activemq.ActiveMQConnectionFactory;
5 | import org.apache.activemq.command.ActiveMQQueue;
6 | import org.springframework.beans.factory.annotation.Value;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 | import org.springframework.jms.connection.CachingConnectionFactory;
10 | import org.springframework.jms.core.JmsTemplate;
11 |
12 | @Configuration
13 | public class SenderConfig {
14 |
15 | @Value("${activemq.broker-url}")
16 | private String brokerUrl;
17 |
18 | @Value("${destination.order}")
19 | private String orderDestination;
20 |
21 | @Value("${destination.status}")
22 | private String statusDestination;
23 |
24 | @Bean
25 | public ActiveMQConnectionFactory senderConnectionFactory() {
26 | ActiveMQConnectionFactory activeMQConnectionFactory =
27 | new ActiveMQConnectionFactory();
28 | activeMQConnectionFactory.setBrokerURL(brokerUrl);
29 |
30 | return activeMQConnectionFactory;
31 | }
32 |
33 | @Bean
34 | public CachingConnectionFactory cachingConnectionFactory() {
35 | CachingConnectionFactory cachingConnectionFactory =
36 | new CachingConnectionFactory(senderConnectionFactory());
37 | cachingConnectionFactory.setSessionCacheSize(10);
38 |
39 | return cachingConnectionFactory;
40 | }
41 |
42 | @Bean
43 | public Destination orderDestination() {
44 | return new ActiveMQQueue(orderDestination);
45 | }
46 |
47 | @Bean
48 | public Destination statusDestination() {
49 | return new ActiveMQQueue(statusDestination);
50 | }
51 |
52 | @Bean
53 | public JmsTemplate orderJmsTemplate() {
54 | JmsTemplate jmsTemplate =
55 | new JmsTemplate(cachingConnectionFactory());
56 | jmsTemplate.setDefaultDestination(orderDestination());
57 | jmsTemplate.setReceiveTimeout(5000);
58 |
59 | return jmsTemplate;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/spring-jms-integration/src/main/java/com/codenotfound/jms/ConsumingChannelConfig.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import javax.jms.ConnectionFactory;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.integration.annotation.ServiceActivator;
8 | import org.springframework.integration.channel.DirectChannel;
9 | import org.springframework.integration.jms.ChannelPublishingJmsMessageListener;
10 | import org.springframework.integration.jms.JmsMessageDrivenEndpoint;
11 | import org.springframework.jms.listener.SimpleMessageListenerContainer;
12 |
13 | @Configuration
14 | public class ConsumingChannelConfig {
15 |
16 | @Value("${destination.integration}")
17 | private String integrationDestination;
18 |
19 | @Bean
20 | public DirectChannel consumingChannel() {
21 | return new DirectChannel();
22 | }
23 |
24 | @Bean
25 | public JmsMessageDrivenEndpoint jmsMessageDrivenEndpoint(
26 | ConnectionFactory connectionFactory) {
27 | JmsMessageDrivenEndpoint endpoint = new JmsMessageDrivenEndpoint(
28 | simpleMessageListenerContainer(connectionFactory),
29 | channelPublishingJmsMessageListener());
30 | endpoint.setOutputChannel(consumingChannel());
31 |
32 | return endpoint;
33 | }
34 |
35 | @Bean
36 | public SimpleMessageListenerContainer simpleMessageListenerContainer(
37 | ConnectionFactory connectionFactory) {
38 | SimpleMessageListenerContainer container =
39 | new SimpleMessageListenerContainer();
40 | container.setConnectionFactory(connectionFactory);
41 | container.setDestinationName(integrationDestination);
42 | return container;
43 | }
44 |
45 | @Bean
46 | public ChannelPublishingJmsMessageListener channelPublishingJmsMessageListener() {
47 | return new ChannelPublishingJmsMessageListener();
48 | }
49 |
50 | @Bean
51 | @ServiceActivator(inputChannel = "consumingChannel")
52 | public CountDownLatchHandler countDownLatchHandler() {
53 | return new CountDownLatchHandler();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/spring-jms-integration/src/test/java/com/codenotfound/jms/SpringJmsApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 | import java.util.Collections;
5 | import java.util.Map;
6 | import java.util.concurrent.TimeUnit;
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.slf4j.Logger;
10 | import org.slf4j.LoggerFactory;
11 | import org.springframework.beans.factory.annotation.Autowired;
12 | import org.springframework.beans.factory.annotation.Value;
13 | import org.springframework.boot.test.context.SpringBootTest;
14 | import org.springframework.context.ApplicationContext;
15 | import org.springframework.jms.support.JmsHeaders;
16 | import org.springframework.messaging.MessageChannel;
17 | import org.springframework.messaging.support.GenericMessage;
18 | import org.springframework.test.annotation.DirtiesContext;
19 | import org.springframework.test.context.junit4.SpringRunner;
20 |
21 | @RunWith(SpringRunner.class)
22 | @SpringBootTest
23 | @DirtiesContext
24 | public class SpringJmsApplicationTest {
25 |
26 | private static final Logger LOGGER =
27 | LoggerFactory.getLogger(SpringJmsApplicationTest.class);
28 |
29 | @Value("${destination.integration}")
30 | private String integrationDestination;
31 |
32 | @Autowired
33 | private ApplicationContext applicationContext;
34 |
35 | @Autowired
36 | private CountDownLatchHandler countDownLatchHandler;
37 |
38 | @Test
39 | public void testIntegration() throws Exception {
40 | MessageChannel producingChannel = applicationContext
41 | .getBean("producingChannel", MessageChannel.class);
42 |
43 | Map headers = Collections.singletonMap(
44 | JmsHeaders.DESTINATION, integrationDestination);
45 |
46 | LOGGER.info("sending 10 messages");
47 | for (int i = 0; i < 10; i++) {
48 | GenericMessage message = new GenericMessage<>(
49 | "Hello Spring Integration JMS " + i + "!", headers);
50 | producingChannel.send(message);
51 | LOGGER.info("sent message='{}'", message);
52 | }
53 |
54 | countDownLatchHandler.getLatch().await(10000,
55 | TimeUnit.MILLISECONDS);
56 | assertThat(countDownLatchHandler.getLatch().getCount())
57 | .isEqualTo(0);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/spring-jms-integration-gateway/src/main/java/com/codenotfound/jms/InboundGatewayConfig.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import javax.jms.ConnectionFactory;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.integration.annotation.ServiceActivator;
8 | import org.springframework.integration.channel.DirectChannel;
9 | import org.springframework.integration.config.EnableIntegration;
10 | import org.springframework.integration.jms.ChannelPublishingJmsMessageListener;
11 | import org.springframework.integration.jms.JmsInboundGateway;
12 | import org.springframework.jms.listener.SimpleMessageListenerContainer;
13 | import org.springframework.messaging.MessageChannel;
14 |
15 | @Configuration
16 | @EnableIntegration
17 | public class InboundGatewayConfig {
18 |
19 | @Value("${destination.order.request}")
20 | private String orderRequestDestination;
21 |
22 | @Bean
23 | public MessageChannel inboundOrderRequestChannel() {
24 | return new DirectChannel();
25 | }
26 |
27 | @Bean
28 | public MessageChannel inboundOrderResponseChannel() {
29 | return new DirectChannel();
30 | }
31 |
32 | @Bean
33 | @ServiceActivator(inputChannel = "inboundOrderRequestChannel")
34 | public OrderService orderService() {
35 | return new OrderService();
36 | }
37 |
38 | @Bean
39 | public JmsInboundGateway jmsInboundGateway(
40 | ConnectionFactory connectionFactory) {
41 | JmsInboundGateway gateway = new JmsInboundGateway(
42 | simpleMessageListenerContainer(connectionFactory),
43 | channelPublishingJmsMessageListener());
44 | gateway.setRequestChannel(inboundOrderRequestChannel());
45 |
46 | return gateway;
47 | }
48 |
49 | @Bean
50 | public SimpleMessageListenerContainer simpleMessageListenerContainer(
51 | ConnectionFactory connectionFactory) {
52 | SimpleMessageListenerContainer container =
53 | new SimpleMessageListenerContainer();
54 | container.setConnectionFactory(connectionFactory);
55 | container.setDestinationName(orderRequestDestination);
56 | return container;
57 | }
58 |
59 | @Bean
60 | public ChannelPublishingJmsMessageListener channelPublishingJmsMessageListener() {
61 | ChannelPublishingJmsMessageListener channelPublishingJmsMessageListener =
62 | new ChannelPublishingJmsMessageListener();
63 | channelPublishingJmsMessageListener.setExpectReply(true);
64 |
65 | return channelPublishingJmsMessageListener;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/spring-jms-listener/src/main/java/com/codenotfound/jms/ReceiverConfig.java:
--------------------------------------------------------------------------------
1 | package com.codenotfound.jms;
2 |
3 | import org.apache.activemq.ActiveMQConnectionFactory;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.jms.annotation.EnableJms;
8 | import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
9 | import org.springframework.jms.config.SimpleJmsListenerContainerFactory;
10 | import org.springframework.jms.config.SimpleJmsListenerEndpoint;
11 | import org.springframework.jms.listener.DefaultMessageListenerContainer;
12 | import org.springframework.jms.listener.SimpleMessageListenerContainer;
13 |
14 | @Configuration
15 | @EnableJms
16 | public class ReceiverConfig {
17 |
18 | @Value("${activemq.broker-url}")
19 | private String brokerUrl;
20 |
21 | @Value("${destination.status1}")
22 | private String status1Destination;
23 |
24 | @Value("${destination.status2}")
25 | private String status2Destination;
26 |
27 | @Bean
28 | public ActiveMQConnectionFactory receiverActiveMQConnectionFactory() {
29 | ActiveMQConnectionFactory activeMQConnectionFactory =
30 | new ActiveMQConnectionFactory();
31 | activeMQConnectionFactory.setBrokerURL(brokerUrl);
32 |
33 | return activeMQConnectionFactory;
34 | }
35 |
36 | @Bean
37 | public DefaultJmsListenerContainerFactory orderDefaultJmsListenerContainerFactory() {
38 | DefaultJmsListenerContainerFactory factory =
39 | new DefaultJmsListenerContainerFactory();
40 | factory
41 | .setConnectionFactory(receiverActiveMQConnectionFactory());
42 | factory.setConcurrency("3-10");
43 |
44 | return factory;
45 | }
46 |
47 | @Bean
48 | public SimpleJmsListenerContainerFactory orderSimpleJmsListenerContainerFactory() {
49 | SimpleJmsListenerContainerFactory factory =
50 | new SimpleJmsListenerContainerFactory();
51 | factory
52 | .setConnectionFactory(receiverActiveMQConnectionFactory());
53 |
54 | return factory;
55 | }
56 |
57 | @Bean
58 | public DefaultMessageListenerContainer orderMessageListenerContainer() {
59 | SimpleJmsListenerEndpoint endpoint =
60 | new SimpleJmsListenerEndpoint();
61 | endpoint.setMessageListener(new StatusMessageListener("DMLC"));
62 | endpoint.setDestination(status1Destination);
63 |
64 | return orderDefaultJmsListenerContainerFactory()
65 | .createListenerContainer(endpoint);
66 | }
67 |
68 | @Bean
69 | public SimpleMessageListenerContainer statusMessageListenerContainer() {
70 | SimpleJmsListenerEndpoint endpoint =
71 | new SimpleJmsListenerEndpoint();
72 | endpoint.setMessageListener(new StatusMessageListener("SMLC"));
73 | endpoint.setDestination(status2Destination);
74 |
75 | return orderSimpleJmsListenerContainerFactory()
76 | .createListenerContainer(endpoint);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------