Spring cloud samples (#3010)
* Matchers is now deprecated in Mockito 2, it's now replaced by ArgumentMatchers * BAEL-1069: Guide to diamond operator in Java * Changes after review * BAEL-719: Intro to Spring Cloud Stream * Pull request changes done * Renamed unit tests * Add spring-cloud-stream * Add module * Exclude integration tests from spring-cloud
This commit is contained in:
parent
8957b9414c
commit
d54917c7e9
125
drools/pom.xml
125
drools/pom.xml
@ -1,68 +1,87 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>drools</artifactId>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>parent-modules</artifactId>
|
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
|
<artifactId>drools</artifactId>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<artifactId>parent-modules</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
<properties>
|
<properties>
|
||||||
<http-component-version>4.4.6</http-component-version>
|
<http-component-version>4.4.6</http-component-version>
|
||||||
<drools-version>7.4.1.Final</drools-version>
|
<drools-version>7.4.1.Final</drools-version>
|
||||||
<apache-poi-version>3.13</apache-poi-version>
|
<apache-poi-version>3.13</apache-poi-version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
<artifactId>httpcore</artifactId>
|
<artifactId>httpcore</artifactId>
|
||||||
<version>${http-component-version}</version>
|
<version>${http-component-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- ... -->
|
<!-- ... -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.kie</groupId>
|
<groupId>org.kie</groupId>
|
||||||
<artifactId>kie-ci</artifactId>
|
<artifactId>kie-ci</artifactId>
|
||||||
<version>${drools-version}</version>
|
<version>${drools-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.drools</groupId>
|
<groupId>org.drools</groupId>
|
||||||
<artifactId>drools-decisiontables</artifactId>
|
<artifactId>drools-decisiontables</artifactId>
|
||||||
<version>${drools-version}</version>
|
<version>${drools-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.drools</groupId>
|
<groupId>org.drools</groupId>
|
||||||
<artifactId>drools-core</artifactId>
|
<artifactId>drools-core</artifactId>
|
||||||
<version>${drools-version}</version>
|
<version>${drools-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.drools</groupId>
|
<groupId>org.drools</groupId>
|
||||||
<artifactId>drools-compiler</artifactId>
|
<artifactId>drools-compiler</artifactId>
|
||||||
<version>${drools-version}</version>
|
<version>${drools-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.poi</groupId>
|
<groupId>org.apache.poi</groupId>
|
||||||
<artifactId>poi</artifactId>
|
<artifactId>poi</artifactId>
|
||||||
<version>${apache-poi-version}</version>
|
<version>${apache-poi-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.poi</groupId>
|
<groupId>org.apache.poi</groupId>
|
||||||
<artifactId>poi-ooxml</artifactId>
|
<artifactId>poi-ooxml</artifactId>
|
||||||
<version>${apache-poi-version}</version>
|
<version>${apache-poi-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-core</artifactId>
|
<artifactId>spring-core</artifactId>
|
||||||
<version>4.3.6.RELEASE</version>
|
<version>4.3.6.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>${maven-surefire-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<forkCount>3</forkCount>
|
||||||
|
<reuseForks>true</reuseForks>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*IntegrationTest.java</exclude>
|
||||||
|
<exclude>**/*LongRunningUnitTest.java</exclude>
|
||||||
|
<exclude>**/*ManualTest.java</exclude>
|
||||||
|
<exclude>**/JdbcTest.java</exclude>
|
||||||
|
<exclude>**/*LiveTest.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.baeldung.spring.cloud</groupId>
|
<groupId>com.baeldung.spring.cloud</groupId>
|
||||||
@ -15,8 +15,9 @@
|
|||||||
<module>spring-cloud-ribbon-client</module>
|
<module>spring-cloud-ribbon-client</module>
|
||||||
<module>spring-cloud-rest</module>
|
<module>spring-cloud-rest</module>
|
||||||
<module>spring-cloud-zookeeper</module>
|
<module>spring-cloud-zookeeper</module>
|
||||||
<module>spring-cloud-gateway</module>
|
<module>spring-cloud-gateway</module>
|
||||||
<module>spring-cloud-connectors-heroku</module>
|
<module>spring-cloud-stream</module>
|
||||||
|
<module>spring-cloud-connectors-heroku</module>
|
||||||
</modules>
|
</modules>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
@ -38,6 +39,7 @@
|
|||||||
<spring-cloud-starter-eureka.version>1.2.3.RELEASE</spring-cloud-starter-eureka.version>
|
<spring-cloud-starter-eureka.version>1.2.3.RELEASE</spring-cloud-starter-eureka.version>
|
||||||
<spring-cloud-starter-feign.version>1.2.3.RELEASE</spring-cloud-starter-feign.version>
|
<spring-cloud-starter-feign.version>1.2.3.RELEASE</spring-cloud-starter-feign.version>
|
||||||
<spring-cloud-starter-hystrix.version>1.2.3.RELEASE</spring-cloud-starter-hystrix.version>
|
<spring-cloud-starter-hystrix.version>1.2.3.RELEASE</spring-cloud-starter-hystrix.version>
|
||||||
|
<spring-cloud-stream.version>1.3.0.RELEASE</spring-cloud-stream.version>
|
||||||
<spring-boot-starter-web.version>1.4.2.RELEASE</spring-boot-starter-web.version>
|
<spring-boot-starter-web.version>1.4.2.RELEASE</spring-boot-starter-web.version>
|
||||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||||
<spring-boot-maven-plugin.version>1.4.2.RELEASE</spring-boot-maven-plugin.version>
|
<spring-boot-maven-plugin.version>1.4.2.RELEASE</spring-boot-maven-plugin.version>
|
||||||
|
71
spring-cloud/spring-cloud-stream/pom.xml
Normal file
71
spring-cloud/spring-cloud-stream/pom.xml
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
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>
|
||||||
|
|
||||||
|
<groupId>org.baeldung</groupId>
|
||||||
|
<artifactId>spring-cloud-stream</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
<name>spring-cloud-stream</name>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung.spring.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>spring-cloud-stream-rabbit</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
|
||||||
|
<version>${spring-cloud-stream.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-stream</artifactId>
|
||||||
|
<version>${spring-cloud-stream.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-stream-test-support</artifactId>
|
||||||
|
<version>${spring-cloud-stream.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>${spring-boot-maven-plugin.version}</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,32 @@
|
|||||||
|
<?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>spring-cloud-stream-rabbit</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>spring-cloud-stream-rabbit</name>
|
||||||
|
<description>Simple Spring Cloud Stream</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.baeldung</groupId>
|
||||||
|
<artifactId>spring-cloud-stream</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<relativePath>..</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-stream-test-support</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.baeldung.spring.cloud.stream.rabbit;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||||
|
import org.springframework.cloud.stream.annotation.StreamListener;
|
||||||
|
import org.springframework.messaging.Message;
|
||||||
|
import org.springframework.messaging.support.MessageBuilder;
|
||||||
|
|
||||||
|
import com.baeldung.spring.cloud.stream.rabbit.processor.MyProcessor;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableBinding(MyProcessor.class)
|
||||||
|
public class MultipleOutputsServiceApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(MultipleOutputsServiceApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MyProcessor processor;
|
||||||
|
|
||||||
|
@StreamListener(MyProcessor.INPUT)
|
||||||
|
public void routeValues(Integer val) {
|
||||||
|
if (val < 10) {
|
||||||
|
processor.anOutput()
|
||||||
|
.send(message(val));
|
||||||
|
} else {
|
||||||
|
processor.anotherOutput()
|
||||||
|
.send(message(val));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final <T> Message<T> message(T val) {
|
||||||
|
return MessageBuilder.withPayload(val)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.baeldung.spring.cloud.stream.rabbit;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||||
|
import org.springframework.cloud.stream.annotation.StreamListener;
|
||||||
|
import org.springframework.messaging.Message;
|
||||||
|
import org.springframework.messaging.support.MessageBuilder;
|
||||||
|
|
||||||
|
import com.baeldung.spring.cloud.stream.rabbit.processor.MyProcessor;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableBinding(MyProcessor.class)
|
||||||
|
public class MultipleOutputsWithConditionsServiceApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(MultipleOutputsWithConditionsServiceApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MyProcessor processor;
|
||||||
|
|
||||||
|
@StreamListener(target = MyProcessor.INPUT, condition = "payload < 10")
|
||||||
|
public void routeValuesToAnOutput(Integer val) {
|
||||||
|
processor.anOutput()
|
||||||
|
.send(message(val));
|
||||||
|
}
|
||||||
|
|
||||||
|
@StreamListener(target = MyProcessor.INPUT, condition = "payload >= 10")
|
||||||
|
public void routeValuesToAnotherOutput(Integer val) {
|
||||||
|
processor.anotherOutput()
|
||||||
|
.send(message(val));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final <T> Message<T> message(T val) {
|
||||||
|
return MessageBuilder.withPayload(val)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.baeldung.spring.cloud.stream.rabbit;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||||
|
import org.springframework.cloud.stream.annotation.StreamListener;
|
||||||
|
import org.springframework.cloud.stream.messaging.Processor;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.messaging.converter.MessageConverter;
|
||||||
|
import org.springframework.messaging.handler.annotation.SendTo;
|
||||||
|
|
||||||
|
import com.baeldung.spring.cloud.stream.rabbit.messages.TextPlainMessageConverter;
|
||||||
|
import com.baeldung.spring.cloud.stream.rabbit.model.LogMessage;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableBinding(Processor.class)
|
||||||
|
public class MyLoggerServiceApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(MyLoggerServiceApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public MessageConverter providesTextPlainMessageConverter() {
|
||||||
|
return new TextPlainMessageConverter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@StreamListener(Processor.INPUT)
|
||||||
|
@SendTo(Processor.OUTPUT)
|
||||||
|
public LogMessage enrichLogMessage(LogMessage log) {
|
||||||
|
return new LogMessage(String.format("[1]: %s", log.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.baeldung.spring.cloud.stream.rabbit.messages;
|
||||||
|
|
||||||
|
import org.springframework.messaging.Message;
|
||||||
|
import org.springframework.messaging.converter.AbstractMessageConverter;
|
||||||
|
import org.springframework.util.MimeType;
|
||||||
|
|
||||||
|
import com.baeldung.spring.cloud.stream.rabbit.model.LogMessage;
|
||||||
|
|
||||||
|
public class TextPlainMessageConverter extends AbstractMessageConverter {
|
||||||
|
|
||||||
|
public TextPlainMessageConverter() {
|
||||||
|
super(new MimeType("text", "plain"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean supports(Class<?> clazz) {
|
||||||
|
return (LogMessage.class == clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object convertFromInternal(Message<?> message, Class<?> targetClass, Object conversionHint) {
|
||||||
|
Object payload = message.getPayload();
|
||||||
|
String text = payload instanceof String ? (String) payload : new String((byte[]) payload);
|
||||||
|
return new LogMessage(text);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.baeldung.spring.cloud.stream.rabbit.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class LogMessage implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -5857383701708275796L;
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public LogMessage() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public LogMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.baeldung.spring.cloud.stream.rabbit.processor;
|
||||||
|
|
||||||
|
import org.springframework.cloud.stream.annotation.Input;
|
||||||
|
import org.springframework.cloud.stream.annotation.Output;
|
||||||
|
import org.springframework.messaging.MessageChannel;
|
||||||
|
import org.springframework.messaging.SubscribableChannel;
|
||||||
|
|
||||||
|
public interface MyProcessor {
|
||||||
|
String INPUT = "myInput";
|
||||||
|
|
||||||
|
@Input
|
||||||
|
SubscribableChannel myInput();
|
||||||
|
|
||||||
|
@Output("myOutput")
|
||||||
|
MessageChannel anOutput();
|
||||||
|
|
||||||
|
@Output
|
||||||
|
MessageChannel anotherOutput();
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
spring:
|
||||||
|
cloud:
|
||||||
|
stream:
|
||||||
|
bindings:
|
||||||
|
input:
|
||||||
|
destination: queue.log.messages
|
||||||
|
binder: local_rabbit
|
||||||
|
group: logMessageConsumers
|
||||||
|
output:
|
||||||
|
destination: queue.pretty.log.messages
|
||||||
|
binder: local_rabbit
|
||||||
|
binders:
|
||||||
|
local_rabbit:
|
||||||
|
type: rabbit
|
||||||
|
environment:
|
||||||
|
spring:
|
||||||
|
rabbitmq:
|
||||||
|
host: localhost
|
||||||
|
port: 5672
|
||||||
|
username: guest
|
||||||
|
password: guest
|
||||||
|
virtual-host: /
|
||||||
|
server:
|
||||||
|
port: 0
|
||||||
|
management:
|
||||||
|
health:
|
||||||
|
binders:
|
||||||
|
enabled: true
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.baeldung.spring.cloud.stream.rabbit;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cloud.stream.test.binder.MessageCollector;
|
||||||
|
import org.springframework.messaging.MessageChannel;
|
||||||
|
import org.springframework.messaging.support.MessageBuilder;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
import com.baeldung.spring.cloud.stream.rabbit.processor.MyProcessor;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(classes = MultipleOutputsServiceApplication.class)
|
||||||
|
@DirtiesContext
|
||||||
|
public class MultipleOutputsServiceApplicationIntegrationTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MyProcessor pipe;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MessageCollector messageCollector;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSendMessage_thenResponseIsInAOutput() {
|
||||||
|
whenSendMessage(1);
|
||||||
|
thenPayloadInChannelIs(pipe.anOutput(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSendMessage_thenResponseIsInAnotherOutput() {
|
||||||
|
whenSendMessage(11);
|
||||||
|
thenPayloadInChannelIs(pipe.anotherOutput(), 11);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void whenSendMessage(Integer val) {
|
||||||
|
pipe.myInput()
|
||||||
|
.send(MessageBuilder.withPayload(val)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void thenPayloadInChannelIs(MessageChannel channel, Integer expectedValue) {
|
||||||
|
Object payload = messageCollector.forChannel(channel)
|
||||||
|
.poll()
|
||||||
|
.getPayload();
|
||||||
|
assertEquals(expectedValue, payload);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.baeldung.spring.cloud.stream.rabbit;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cloud.stream.test.binder.MessageCollector;
|
||||||
|
import org.springframework.messaging.MessageChannel;
|
||||||
|
import org.springframework.messaging.support.MessageBuilder;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
import com.baeldung.spring.cloud.stream.rabbit.processor.MyProcessor;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(classes = MultipleOutputsWithConditionsServiceApplication.class)
|
||||||
|
@DirtiesContext
|
||||||
|
public class MultipleOutputsWithConditionsServiceIntegrationTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MyProcessor pipe;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MessageCollector messageCollector;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSendMessage_thenResponseIsInAOutput() {
|
||||||
|
whenSendMessage(1);
|
||||||
|
thenPayloadInChannelIs(pipe.anOutput(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSendMessage_thenResponseIsInAnotherOutput() {
|
||||||
|
whenSendMessage(11);
|
||||||
|
thenPayloadInChannelIs(pipe.anotherOutput(), 11);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void whenSendMessage(Integer val) {
|
||||||
|
pipe.myInput()
|
||||||
|
.send(MessageBuilder.withPayload(val)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void thenPayloadInChannelIs(MessageChannel channel, Integer expectedValue) {
|
||||||
|
Object payload = messageCollector.forChannel(channel)
|
||||||
|
.poll()
|
||||||
|
.getPayload();
|
||||||
|
assertEquals(expectedValue, payload);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.baeldung.spring.cloud.stream.rabbit;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cloud.stream.messaging.Processor;
|
||||||
|
import org.springframework.cloud.stream.test.binder.MessageCollector;
|
||||||
|
import org.springframework.messaging.support.MessageBuilder;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
import com.baeldung.spring.cloud.stream.rabbit.model.LogMessage;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(classes = MyLoggerServiceApplication.class)
|
||||||
|
@DirtiesContext
|
||||||
|
public class MyLoggerApplicationIntegrationTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Processor pipe;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MessageCollector messageCollector;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSendMessage_thenResponseShouldUpdateText() {
|
||||||
|
pipe.input()
|
||||||
|
.send(MessageBuilder.withPayload(new LogMessage("This is my message"))
|
||||||
|
.build());
|
||||||
|
|
||||||
|
Object payload = messageCollector.forChannel(pipe.output())
|
||||||
|
.poll()
|
||||||
|
.getPayload();
|
||||||
|
|
||||||
|
assertEquals("[1]: This is my message", payload.toString());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user