Bael 555 spring remoting with amqp (#1654)
* Burlap & Hessian server added * Burlap & Hessian client work * Fixed main * Fixed formatting * Spring Remote example based on Burlap & Hessian runs in a JUnit test * Fixed main * Fixed formatting * Spring Remote example based on Burlap & Hessian runs in a JUnit test * Spring Remote example based on Burlap & Hessian runs in a JUnit test * Burlap & Hessian client work * Fixed main * Fixed main * Fixed formatting * Fixed formatting * Spring Remote example based on Burlap & Hessian runs in a JUnit test * Spring Remote example based on Burlap & Hessian runs in a JUnit test * Fixed POM * First experiments with amqp * First experiments with amqp * Firts example of remoting working with AMQP * Server code fixed * Client code fixed * Removed wrongly pushed work folder * Removed derby.log file. * Fixed client and server package. * Fixed indentation.
This commit is contained in:
parent
2a3030dd98
commit
caab7829e7
|
@ -36,6 +36,7 @@
|
|||
<modules>
|
||||
<module>remoting-http</module>
|
||||
<module>remoting-hessian-burlap</module>
|
||||
<module>remoting-amqp</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,21 @@
|
|||
<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">
|
||||
<parent>
|
||||
<artifactId>spring-remoting</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>remoting-amqp</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
||||
|
||||
<name>remoting-amqp</name>
|
||||
<modules>
|
||||
<module>remoting-amqp-server</module>
|
||||
<module>remoting-amqp-client</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,36 @@
|
|||
<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">
|
||||
<parent>
|
||||
<artifactId>remoting-amqp</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>remoting-amqp-client</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>remoting-amqp-client</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,46 @@
|
|||
package com.baeldung.client;
|
||||
|
||||
import com.baeldung.api.BookingException;
|
||||
import com.baeldung.api.CabBookingService;
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.remoting.client.AmqpProxyFactoryBean;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import static java.lang.System.out;
|
||||
|
||||
@SpringBootApplication public class AmqpClient {
|
||||
|
||||
@Bean Queue queue() {
|
||||
return new Queue("remotingQueue");
|
||||
}
|
||||
|
||||
@Bean AmqpProxyFactoryBean amqpFactoryBean(AmqpTemplate amqpTemplate) {
|
||||
AmqpProxyFactoryBean factoryBean = new AmqpProxyFactoryBean();
|
||||
factoryBean.setServiceInterface(CabBookingService.class);
|
||||
factoryBean.setAmqpTemplate(amqpTemplate);
|
||||
return factoryBean;
|
||||
}
|
||||
|
||||
@Bean Exchange directExchange(Queue someQueue) {
|
||||
DirectExchange exchange = new DirectExchange("remoting.exchange");
|
||||
BindingBuilder.bind(someQueue).to(exchange).with("remoting.binding");
|
||||
return exchange;
|
||||
}
|
||||
|
||||
@Bean RabbitTemplate amqpTemplate(ConnectionFactory factory) {
|
||||
RabbitTemplate template = new RabbitTemplate(factory);
|
||||
template.setRoutingKey("remoting.binding");
|
||||
template.setExchange("remoting.exchange");
|
||||
return template;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws BookingException {
|
||||
CabBookingService service = SpringApplication.run(AmqpClient.class, args).getBean(CabBookingService.class);
|
||||
out.println(service.bookRide("13 Seagate Blvd, Key Largo, FL 33037"));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
# This is true to make SpringBoot to automatically register a bean of type 'org.springframework.amqp.core.AmqpAdmin'.
|
||||
# Check the org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration javadoc for details.
|
||||
spring.rabbitmq.dynamic=true
|
||||
|
||||
# The port to which the client should connect defaults to 5672.
|
||||
spring.rabbitmq.port=32769
|
||||
|
||||
# Username and password
|
||||
spring.rabbitmq.username=guest
|
||||
spring.rabbitmq.password=guest
|
||||
|
||||
# The host, defaults to localhost.
|
||||
spring.rabbitmq.host=192.168.99.100
|
||||
|
||||
# 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.springframework.amqp=TRACE
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<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">
|
||||
<parent>
|
||||
<artifactId>remoting-amqp</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>remoting-amqp-server</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>remoting-amqp-server</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>spring-remoting-http-server</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,53 @@
|
|||
package com.baeldung.server;
|
||||
|
||||
import com.baeldung.api.CabBookingService;
|
||||
import org.springframework.amqp.core.AmqpTemplate;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.amqp.remoting.service.AmqpInvokerServiceExporter;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration @ComponentScan @EnableAutoConfiguration
|
||||
public class AmqpServer {
|
||||
|
||||
/*
|
||||
Please note that
|
||||
- CachingConnectionFactory
|
||||
- RabbitAdmin
|
||||
- AmqpTemplate
|
||||
are automatically declared by SpringBoot.
|
||||
*/
|
||||
|
||||
@Bean CabBookingService bookingService() {
|
||||
return new CabBookingServiceImpl();
|
||||
}
|
||||
|
||||
@Bean Queue queue() {
|
||||
return new Queue("remotingQueue");
|
||||
}
|
||||
|
||||
@Bean AmqpInvokerServiceExporter exporter(CabBookingService implementation, AmqpTemplate template) {
|
||||
AmqpInvokerServiceExporter exporter = new AmqpInvokerServiceExporter();
|
||||
exporter.setServiceInterface(CabBookingService.class);
|
||||
exporter.setService(implementation);
|
||||
exporter.setAmqpTemplate(template);
|
||||
return exporter;
|
||||
}
|
||||
|
||||
@Bean SimpleMessageListenerContainer listener(ConnectionFactory factory, AmqpInvokerServiceExporter exporter, Queue queue) {
|
||||
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(factory);
|
||||
container.setMessageListener(exporter);
|
||||
container.setQueueNames(queue.getName());
|
||||
return container;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AmqpServer.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
# This is true to make SpringBoot to automatically register a bean of type 'org.springframework.amqp.core.AmqpAdmin'.
|
||||
# Check the org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration javadoc for details.
|
||||
spring.rabbitmq.dynamic=true
|
||||
|
||||
# The port to which the client should connect defaults to 5672.
|
||||
spring.rabbitmq.port=32769
|
||||
|
||||
# Username and password
|
||||
spring.rabbitmq.username=guest
|
||||
spring.rabbitmq.password=guest
|
||||
|
||||
# The host, defaults to localhost.
|
||||
spring.rabbitmq.host=192.168.99.100
|
||||
|
||||
# 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.springframework.amqp=TRACE
|
||||
|
Loading…
Reference in New Issue