Skip to content

Commit caab782

Browse files
danidemiKevinGilmore
authored andcommitted
Bael 555 spring remoting with amqp (eugenp#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.
1 parent 2a3030d commit caab782

File tree

8 files changed

+241
-0
lines changed

8 files changed

+241
-0
lines changed

spring-remoting/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<modules>
3737
<module>remoting-http</module>
3838
<module>remoting-hessian-burlap</module>
39+
<module>remoting-amqp</module>
3940
</modules>
4041

4142
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<parent>
4+
<artifactId>spring-remoting</artifactId>
5+
<groupId>com.baeldung</groupId>
6+
<version>1.0-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
10+
<artifactId>remoting-amqp</artifactId>
11+
<packaging>pom</packaging>
12+
13+
14+
15+
<name>remoting-amqp</name>
16+
<modules>
17+
<module>remoting-amqp-server</module>
18+
<module>remoting-amqp-client</module>
19+
</modules>
20+
21+
</project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<parent>
4+
<artifactId>remoting-amqp</artifactId>
5+
<groupId>com.baeldung</groupId>
6+
<version>1.0-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
10+
<artifactId>remoting-amqp-client</artifactId>
11+
<packaging>jar</packaging>
12+
13+
<name>remoting-amqp-client</name>
14+
<url>http://maven.apache.org</url>
15+
16+
<properties>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-amqp</artifactId>
24+
<exclusions>
25+
<exclusion>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-tomcat</artifactId>
28+
</exclusion>
29+
</exclusions>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.baeldung</groupId>
33+
<artifactId>api</artifactId>
34+
</dependency>
35+
</dependencies>
36+
</project>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.baeldung.client;
2+
3+
import com.baeldung.api.BookingException;
4+
import com.baeldung.api.CabBookingService;
5+
import org.springframework.amqp.core.*;
6+
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
7+
import org.springframework.amqp.rabbit.core.RabbitTemplate;
8+
import org.springframework.amqp.remoting.client.AmqpProxyFactoryBean;
9+
import org.springframework.boot.SpringApplication;
10+
import org.springframework.boot.autoconfigure.SpringBootApplication;
11+
import org.springframework.context.annotation.Bean;
12+
13+
import static java.lang.System.out;
14+
15+
@SpringBootApplication public class AmqpClient {
16+
17+
@Bean Queue queue() {
18+
return new Queue("remotingQueue");
19+
}
20+
21+
@Bean AmqpProxyFactoryBean amqpFactoryBean(AmqpTemplate amqpTemplate) {
22+
AmqpProxyFactoryBean factoryBean = new AmqpProxyFactoryBean();
23+
factoryBean.setServiceInterface(CabBookingService.class);
24+
factoryBean.setAmqpTemplate(amqpTemplate);
25+
return factoryBean;
26+
}
27+
28+
@Bean Exchange directExchange(Queue someQueue) {
29+
DirectExchange exchange = new DirectExchange("remoting.exchange");
30+
BindingBuilder.bind(someQueue).to(exchange).with("remoting.binding");
31+
return exchange;
32+
}
33+
34+
@Bean RabbitTemplate amqpTemplate(ConnectionFactory factory) {
35+
RabbitTemplate template = new RabbitTemplate(factory);
36+
template.setRoutingKey("remoting.binding");
37+
template.setExchange("remoting.exchange");
38+
return template;
39+
}
40+
41+
public static void main(String[] args) throws BookingException {
42+
CabBookingService service = SpringApplication.run(AmqpClient.class, args).getBean(CabBookingService.class);
43+
out.println(service.bookRide("13 Seagate Blvd, Key Largo, FL 33037"));
44+
}
45+
46+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This is true to make SpringBoot to automatically register a bean of type 'org.springframework.amqp.core.AmqpAdmin'.
2+
# Check the org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration javadoc for details.
3+
spring.rabbitmq.dynamic=true
4+
5+
# The port to which the client should connect defaults to 5672.
6+
spring.rabbitmq.port=32769
7+
8+
# Username and password
9+
spring.rabbitmq.username=guest
10+
spring.rabbitmq.password=guest
11+
12+
# The host, defaults to localhost.
13+
spring.rabbitmq.host=192.168.99.100
14+
15+
# Logging
16+
logging.pattern.console=%d{mm:ss.SSS} %-5p [%-31t] [%-54logger{0}] %marker%m%ex{full} - %logger - %F:%L%n
17+
logging.level.root=WARN
18+
logging.level.org.springframework.amqp=TRACE
19+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<parent>
4+
<artifactId>remoting-amqp</artifactId>
5+
<groupId>com.baeldung</groupId>
6+
<version>1.0-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
10+
<artifactId>remoting-amqp-server</artifactId>
11+
<packaging>jar</packaging>
12+
13+
<name>remoting-amqp-server</name>
14+
<url>http://maven.apache.org</url>
15+
16+
<properties>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>com.baeldung</groupId>
23+
<artifactId>api</artifactId>
24+
<version>${project.version}</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-amqp</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>com.baeldung</groupId>
32+
<artifactId>api</artifactId>
33+
<version>1.0-SNAPSHOT</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>junit</groupId>
37+
<artifactId>junit</artifactId>
38+
<scope>test</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>com.baeldung</groupId>
42+
<artifactId>spring-remoting-http-server</artifactId>
43+
<version>1.0-SNAPSHOT</version>
44+
</dependency>
45+
</dependencies>
46+
</project>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.baeldung.server;
2+
3+
import com.baeldung.api.CabBookingService;
4+
import org.springframework.amqp.core.AmqpTemplate;
5+
import org.springframework.amqp.core.Queue;
6+
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
7+
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
8+
import org.springframework.amqp.remoting.service.AmqpInvokerServiceExporter;
9+
import org.springframework.boot.SpringApplication;
10+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
11+
import org.springframework.context.annotation.Bean;
12+
import org.springframework.context.annotation.ComponentScan;
13+
import org.springframework.context.annotation.Configuration;
14+
15+
@Configuration @ComponentScan @EnableAutoConfiguration
16+
public class AmqpServer {
17+
18+
/*
19+
Please note that
20+
- CachingConnectionFactory
21+
- RabbitAdmin
22+
- AmqpTemplate
23+
are automatically declared by SpringBoot.
24+
*/
25+
26+
@Bean CabBookingService bookingService() {
27+
return new CabBookingServiceImpl();
28+
}
29+
30+
@Bean Queue queue() {
31+
return new Queue("remotingQueue");
32+
}
33+
34+
@Bean AmqpInvokerServiceExporter exporter(CabBookingService implementation, AmqpTemplate template) {
35+
AmqpInvokerServiceExporter exporter = new AmqpInvokerServiceExporter();
36+
exporter.setServiceInterface(CabBookingService.class);
37+
exporter.setService(implementation);
38+
exporter.setAmqpTemplate(template);
39+
return exporter;
40+
}
41+
42+
@Bean SimpleMessageListenerContainer listener(ConnectionFactory factory, AmqpInvokerServiceExporter exporter, Queue queue) {
43+
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(factory);
44+
container.setMessageListener(exporter);
45+
container.setQueueNames(queue.getName());
46+
return container;
47+
}
48+
49+
public static void main(String[] args) {
50+
SpringApplication.run(AmqpServer.class, args);
51+
}
52+
53+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This is true to make SpringBoot to automatically register a bean of type 'org.springframework.amqp.core.AmqpAdmin'.
2+
# Check the org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration javadoc for details.
3+
spring.rabbitmq.dynamic=true
4+
5+
# The port to which the client should connect defaults to 5672.
6+
spring.rabbitmq.port=32769
7+
8+
# Username and password
9+
spring.rabbitmq.username=guest
10+
spring.rabbitmq.password=guest
11+
12+
# The host, defaults to localhost.
13+
spring.rabbitmq.host=192.168.99.100
14+
15+
# Logging
16+
logging.pattern.console=%d{mm:ss.SSS} %-5p [%-31t] [%-54logger{0}] %marker%m%ex{full} - %logger - %F:%L%n
17+
logging.level.root=WARN
18+
logging.level.org.springframework.amqp=TRACE
19+

0 commit comments

Comments
 (0)