JAVA-12579 Renamed spring-remoting to spring-remoting-modules
This commit is contained in:
8
spring-remoting-modules/remoting-jms/README.md
Normal file
8
spring-remoting-modules/remoting-jms/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
## Remoting JMS
|
||||
|
||||
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)
|
||||
|
||||
21
spring-remoting-modules/remoting-jms/pom.xml
Normal file
21
spring-remoting-modules/remoting-jms/pom.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>remoting-jms</artifactId>
|
||||
<name>remoting-jms</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>spring-remoting-modules</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>remoting-jms-client</module>
|
||||
<module>remoting-jms-server</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>remoting-jms-client</artifactId>
|
||||
<name>remoting-jms-client</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>remoting-jms</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-activemq</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>remoting-http-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.baeldung.client;
|
||||
|
||||
import com.baeldung.api.Booking;
|
||||
import com.baeldung.api.BookingException;
|
||||
import com.baeldung.api.CabBookingService;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.jms.remoting.JmsInvokerProxyFactoryBean;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Queue;
|
||||
|
||||
@SpringBootApplication
|
||||
public class JmsClient {
|
||||
|
||||
@Bean Queue queue() {
|
||||
return new ActiveMQQueue("remotingQueue");
|
||||
}
|
||||
|
||||
@Bean FactoryBean invoker(ConnectionFactory factory, Queue queue) {
|
||||
JmsInvokerProxyFactoryBean factoryBean = new JmsInvokerProxyFactoryBean();
|
||||
factoryBean.setConnectionFactory(factory);
|
||||
factoryBean.setServiceInterface(CabBookingService.class);
|
||||
factoryBean.setQueue(queue);
|
||||
return factoryBean;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws BookingException {
|
||||
CabBookingService service = SpringApplication.run(JmsClient.class, args).getBean(CabBookingService.class);
|
||||
System.out.println("here");
|
||||
Booking bookingOutcome = service.bookRide("13 Seagate Blvd, Key Largo, FL 33037");
|
||||
System.out.println("there");
|
||||
System.out.println(bookingOutcome);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
spring.activemq.broker-url=tcp://127.0.0.1:61616
|
||||
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
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.baeldung;
|
||||
|
||||
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.baeldung.client.JmsClient;
|
||||
|
||||
@SpringBootTest(classes = JmsClient.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
public class SpringContextTest {
|
||||
|
||||
@Test
|
||||
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>remoting-jms-server</artifactId>
|
||||
<name>remoting-jms-server</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>remoting-jms</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-activemq</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>remoting-http-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.server;
|
||||
|
||||
import com.baeldung.api.Booking;
|
||||
import com.baeldung.api.BookingException;
|
||||
import com.baeldung.api.CabBookingService;
|
||||
|
||||
import static java.lang.Math.random;
|
||||
import static java.util.UUID.randomUUID;
|
||||
|
||||
public class CabBookingServiceImpl implements CabBookingService {
|
||||
|
||||
@Override public Booking bookRide(String pickUpLocation) throws BookingException {
|
||||
if (random() < 0.3) throw new BookingException("Cab unavailable");
|
||||
return new Booking(randomUUID().toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.baeldung.server;
|
||||
|
||||
import com.baeldung.api.CabBookingService;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.jms.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.jms.remoting.JmsInvokerServiceExporter;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Queue;
|
||||
|
||||
@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
|
||||
*/
|
||||
|
||||
@Bean CabBookingService bookingService() {
|
||||
return new CabBookingServiceImpl();
|
||||
}
|
||||
|
||||
@Bean Queue queue() {
|
||||
return new ActiveMQQueue("remotingQueue");
|
||||
}
|
||||
|
||||
@Bean JmsInvokerServiceExporter exporter(CabBookingService implementation) {
|
||||
JmsInvokerServiceExporter exporter = new JmsInvokerServiceExporter();
|
||||
exporter.setServiceInterface(CabBookingService.class);
|
||||
exporter.setService(implementation);
|
||||
return exporter;
|
||||
}
|
||||
|
||||
@Bean SimpleMessageListenerContainer listener(ConnectionFactory factory, JmsInvokerServiceExporter exporter) {
|
||||
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
|
||||
container.setConnectionFactory(factory);
|
||||
container.setDestinationName("remotingQueue");
|
||||
container.setConcurrentConsumers(1);
|
||||
container.setMessageListener(exporter);
|
||||
return container;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(JmsServer.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
spring.activemq.broker-url=tcp://127.0.0.1:61616
|
||||
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
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.baeldung;
|
||||
|
||||
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.baeldung.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() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user