From 8807cd243838527c045e79512358ba91c5f7e73e Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Wed, 13 Sep 2023 02:03:46 -0400 Subject: [PATCH] =?UTF-8?q?ActiveMQ=20=E6=B6=88=E6=81=AF=E5=A4=84=E7=90=86?= =?UTF-8?q?=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spring-remoting-modules-3/README.md | 13 +++++ spring-remoting-modules-3/pom.xml | 53 +++++++++++++++++++ .../remoting-jms-artemis/.idea/.gitignore | 10 ++++ .../.idea/checkstyle-idea.xml | 16 ++++++ .../remoting-jms-artemis/.idea/compiler.xml | 15 ++++++ .../remoting-jms-artemis/.idea/encodings.xml | 11 ++++ .../.idea/jarRepositories.xml | 30 +++++++++++ .../remoting-jms-artemis/.idea/jpa-buddy.xml | 7 +++ .../remoting-jms-artemis/.idea/misc.xml | 18 +++++++ .../remoting-jms-artemis/.idea/vcs.xml | 6 +++ .../remoting-jms-artemis/README.md | 8 +++ .../remoting-jms-artemis/pom.xml | 21 ++++++++ .../remoting-jms-artemis-client/pom.xml | 32 +++++++++++ .../client/JmsArtemisClientApplication.java | 16 ++++++ .../com/ossez/artemis/client/JmsProducer.java | 22 ++++++++ .../client/controller/MQController.java | 30 +++++++++++ .../src/main/resources/application.properties | 6 +++ .../src/main/resources/logback.xml | 23 ++++++++ .../com/ossez/artemis/SpringContextTest.java | 17 ++++++ .../remoting-jms-artemis-server/pom.xml | 28 ++++++++++ .../com/ossez/artemis/server/JmsServer.java | 29 ++++++++++ .../src/main/resources/application.properties | 13 +++++ .../src/main/resources/logback.xml | 13 +++++ .../ossez/artemis/SpringContextLiveTest.java | 23 ++++++++ 24 files changed, 460 insertions(+) create mode 100644 spring-remoting-modules-3/README.md create mode 100644 spring-remoting-modules-3/pom.xml create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/.idea/.gitignore create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/.idea/checkstyle-idea.xml create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/.idea/compiler.xml create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/.idea/encodings.xml create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/.idea/jarRepositories.xml create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/.idea/jpa-buddy.xml create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/.idea/misc.xml create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/.idea/vcs.xml create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/README.md create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/pom.xml create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/pom.xml create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/java/com/ossez/artemis/client/JmsArtemisClientApplication.java create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/java/com/ossez/artemis/client/JmsProducer.java create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/java/com/ossez/artemis/client/controller/MQController.java create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/resources/application.properties create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/resources/logback.xml create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/test/java/com/ossez/artemis/SpringContextTest.java create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/pom.xml create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/src/main/java/com/ossez/artemis/server/JmsServer.java create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/src/main/resources/application.properties create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/src/main/resources/logback.xml create mode 100644 spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/src/test/java/com/ossez/artemis/SpringContextLiveTest.java diff --git a/spring-remoting-modules-3/README.md b/spring-remoting-modules-3/README.md new file mode 100644 index 0000000000..91db561f83 --- /dev/null +++ b/spring-remoting-modules-3/README.md @@ -0,0 +1,13 @@ +## Spring Remoting + +This module contains articles about Spring Remoting + + +### Overview +This Maven project contains the Java source code for various modules used in the Spring Remoting series of articles. + +### Building the Project +You can build the project using Maven inside your IDE or from the command line: +``` +mvn clean install +``` diff --git a/spring-remoting-modules-3/pom.xml b/spring-remoting-modules-3/pom.xml new file mode 100644 index 0000000000..ea3e6e70f7 --- /dev/null +++ b/spring-remoting-modules-3/pom.xml @@ -0,0 +1,53 @@ + + + 4.0.0 + + spring-remoting-modules-3 + 1.0-SNAPSHOT + spring-remoting-modules-3 + pom + Parent for all projects related to Spring Remoting, except remoting-hessian-burlap + + + com.ossez + parent-boot-3 + 0.0.1-SNAPSHOT + parent-boot-3 + + + + remoting-jms-artemis + + + + + + + ${project.groupId} + api + ${project.version} + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + 17 + 17 + + + \ No newline at end of file diff --git a/spring-remoting-modules-3/remoting-jms-artemis/.idea/.gitignore b/spring-remoting-modules-3/remoting-jms-artemis/.idea/.gitignore new file mode 100644 index 0000000000..0a8642fac0 --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Zeppelin ignored files +/ZeppelinRemoteNotebooks/ diff --git a/spring-remoting-modules-3/remoting-jms-artemis/.idea/checkstyle-idea.xml b/spring-remoting-modules-3/remoting-jms-artemis/.idea/checkstyle-idea.xml new file mode 100644 index 0000000000..f0c49846ff --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + 10.12.2 + JavaOnly + true + + + \ No newline at end of file diff --git a/spring-remoting-modules-3/remoting-jms-artemis/.idea/compiler.xml b/spring-remoting-modules-3/remoting-jms-artemis/.idea/compiler.xml new file mode 100644 index 0000000000..4352c98059 --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/.idea/compiler.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules-3/remoting-jms-artemis/.idea/encodings.xml b/spring-remoting-modules-3/remoting-jms-artemis/.idea/encodings.xml new file mode 100644 index 0000000000..56c6c7bcd3 --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/.idea/encodings.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules-3/remoting-jms-artemis/.idea/jarRepositories.xml b/spring-remoting-modules-3/remoting-jms-artemis/.idea/jarRepositories.xml new file mode 100644 index 0000000000..1067e4c6b5 --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules-3/remoting-jms-artemis/.idea/jpa-buddy.xml b/spring-remoting-modules-3/remoting-jms-artemis/.idea/jpa-buddy.xml new file mode 100644 index 0000000000..898e07a675 --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/.idea/jpa-buddy.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/spring-remoting-modules-3/remoting-jms-artemis/.idea/misc.xml b/spring-remoting-modules-3/remoting-jms-artemis/.idea/misc.xml new file mode 100644 index 0000000000..a2eb346bb8 --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/.idea/misc.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules-3/remoting-jms-artemis/.idea/vcs.xml b/spring-remoting-modules-3/remoting-jms-artemis/.idea/vcs.xml new file mode 100644 index 0000000000..b2bdec2d71 --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules-3/remoting-jms-artemis/README.md b/spring-remoting-modules-3/remoting-jms-artemis/README.md new file mode 100644 index 0000000000..cf86f4adc4 --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/README.md @@ -0,0 +1,8 @@ +## Remoting JMS Artemis + +This module contains articles about Spring Remoting with Java Message Service (JMS) + +### Relevant Articles: + +- [Spring Remoting with JMS and ActiveMQ](https://www.baeldung.com/spring-remoting-jms) + diff --git a/spring-remoting-modules-3/remoting-jms-artemis/pom.xml b/spring-remoting-modules-3/remoting-jms-artemis/pom.xml new file mode 100644 index 0000000000..0e06f402cf --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + remoting-jms-artemis + remoting-jms-artemis + pom + + + com.ossez + spring-remoting-modules-3 + 1.0-SNAPSHOT + + + + remoting-jms-artemis-client + remoting-jms-artemis-server + + + \ No newline at end of file diff --git a/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/pom.xml b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/pom.xml new file mode 100644 index 0000000000..d0d7cd88bb --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + remoting-jms-artemis-client + remoting-jms-client + + + com.ossez + remoting-jms-artemis + 1.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-artemis + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + org.springframework.boot + spring-boot-autoconfigure + + + + \ No newline at end of file diff --git a/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/java/com/ossez/artemis/client/JmsArtemisClientApplication.java b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/java/com/ossez/artemis/client/JmsArtemisClientApplication.java new file mode 100644 index 0000000000..048dc9e351 --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/java/com/ossez/artemis/client/JmsArtemisClientApplication.java @@ -0,0 +1,16 @@ +package com.ossez.artemis.client; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class JmsArtemisClientApplication { + + public static void main(String[] args) { + JmsProducer jmsProducer = SpringApplication.run(JmsArtemisClientApplication.class, args).getBean(JmsProducer.class); + jmsProducer.send("xxxddx");; + + } + +} diff --git a/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/java/com/ossez/artemis/client/JmsProducer.java b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/java/com/ossez/artemis/client/JmsProducer.java new file mode 100644 index 0000000000..3c149ef19b --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/java/com/ossez/artemis/client/JmsProducer.java @@ -0,0 +1,22 @@ +package com.ossez.artemis.client; + +import org.springframework.jms.core.JmsTemplate; +import org.springframework.stereotype.Component; + +/** + * JmsProducer + */ +@Component +public class JmsProducer { + + private final JmsTemplate jmsTemplate; + + public JmsProducer(JmsTemplate jmsTemplate) { + this.jmsTemplate = jmsTemplate; + } + + public void send(String message) { + jmsTemplate.convertAndSend("remotingQueue", message); + } + +} diff --git a/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/java/com/ossez/artemis/client/controller/MQController.java b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/java/com/ossez/artemis/client/controller/MQController.java new file mode 100644 index 0000000000..e8d9f1877d --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/java/com/ossez/artemis/client/controller/MQController.java @@ -0,0 +1,30 @@ +package com.ossez.artemis.client.controller; + +import com.ossez.artemis.client.JmsProducer; +import lombok.RequiredArgsConstructor; + +import org.springframework.web.bind.annotation.*; + +/** + * 承包商相关 API + * + * @author ForteScarlet + */ +@RestController +@RequiredArgsConstructor +@RequestMapping(MQController.BASE_URL) +public class MQController { + + protected static final String BASE_URL = "/mq"; + + private final JmsProducer jmsProducer; + + @PostMapping("/send") + public String addContractorInfo(@RequestBody String request) { + jmsProducer.send(request); + + return "Send"; + } + + +} diff --git a/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/resources/application.properties b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/resources/application.properties new file mode 100644 index 0000000000..6a7307708b --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/resources/application.properties @@ -0,0 +1,6 @@ +spring.artemis.mode=native +spring.artemis.broker-url=tcp://nas1120:61616 +#spring.artemis.host=nas1120 +#spring.artemis.port=61616 +spring.artemis.user=artemis +spring.artemis.password=artemis \ No newline at end of file diff --git a/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/resources/logback.xml b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/resources/logback.xml new file mode 100644 index 0000000000..35be7e9f22 --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/main/resources/logback.xml @@ -0,0 +1,23 @@ + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/test/java/com/ossez/artemis/SpringContextTest.java b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/test/java/com/ossez/artemis/SpringContextTest.java new file mode 100644 index 0000000000..149ff0ab41 --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-client/src/test/java/com/ossez/artemis/SpringContextTest.java @@ -0,0 +1,17 @@ +package com.ossez.artemis; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.ossez.artemis.client.JmsArtemisClientApplication; + +@SpringBootTest(classes = JmsArtemisClientApplication.class) +@RunWith(SpringRunner.class) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/pom.xml b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/pom.xml new file mode 100644 index 0000000000..37f1ce4010 --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + remoting-jms-artemis-server + remoting-jms-server + + + com.ossez + remoting-jms-artemis + 1.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-artemis + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/src/main/java/com/ossez/artemis/server/JmsServer.java b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/src/main/java/com/ossez/artemis/server/JmsServer.java new file mode 100644 index 0000000000..581ea2eeb1 --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/src/main/java/com/ossez/artemis/server/JmsServer.java @@ -0,0 +1,29 @@ +package com.ossez.artemis.server; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.jms.annotation.JmsListener; +//import org.springframework.jmsremoting.JmsInvokerServiceExporter; + +@SpringBootApplication +public class JmsServer { + + /* + This server needs to be connected to an ActiveMQ server. + To quickly spin up an ActiveMQ server, you can use Docker. + + docker run -p 61616:61616 -p 8161:8161 rmohr/activemq:5.14.3 + */ + + + + @JmsListener(destination = "remotingQueue") + public void receive(String message) { + System.out.println("Received message: " + message); + } + + public static void main(String[] args) { + SpringApplication.run(JmsServer.class, args); + } + +} diff --git a/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/src/main/resources/application.properties b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/src/main/resources/application.properties new file mode 100644 index 0000000000..1992e49a35 --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/src/main/resources/application.properties @@ -0,0 +1,13 @@ +spring.artemis.mode=native +spring.artemis.broker-url=tcp://nas1120:61616 +spring.artemis.user=artemis +spring.artemis.password=artemis +#spring.activemq.packages.trusted=org.springframework.remoting.support,java.lang,com.baeldung.api + +# Logging +logging.pattern.console=%d{mm:ss.SSS} %-5p [%-31t] [%-54logger{0}] %marker%m%ex{full} - %logger - %F:%L%n +logging.level.root=WARN +logging.level.org.apache.activemq=DEBUG +logging.level.org.springframework.jms=DEBUG +logging.level.org.springframework=WARN + diff --git a/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/src/main/resources/logback.xml b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/src/test/java/com/ossez/artemis/SpringContextLiveTest.java b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/src/test/java/com/ossez/artemis/SpringContextLiveTest.java new file mode 100644 index 0000000000..21553872ed --- /dev/null +++ b/spring-remoting-modules-3/remoting-jms-artemis/remoting-jms-artemis-server/src/test/java/com/ossez/artemis/SpringContextLiveTest.java @@ -0,0 +1,23 @@ +package com.ossez.artemis; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.ossez.artemis.server.JmsServer; + +/** + * This Live Test requires: + * * the `com.baeldung:remoting-http-api:jar:1.0-SNAPSHOT` artifact accessible. For that we can run `mvn clean install` in the 'spring-remoting/remoting-http/remoting-http-api' module. + * * an ActiveMQ instance running (e.g. `docker run -p 61616:61616 -p 8161:8161 --name bael-activemq rmohr/activemq`) + * + */ +@SpringBootTest(classes = JmsServer.class) +@RunWith(SpringRunner.class) +public class SpringContextLiveTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +}