BAEL-1174: A Quick Guide to Spring Cloud Consul
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
## Relevant Articles
|
||||
- [Introduction to Spring Cloud Stream](http://www.baeldung.com/spring-cloud-stream)
|
||||
@@ -1,14 +1,12 @@
|
||||
<?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">
|
||||
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>
|
||||
<modules>
|
||||
<module>spring-cloud-stream-rabbit</module>
|
||||
</modules>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>spring-cloud-stream</name>
|
||||
@@ -19,6 +17,10 @@
|
||||
<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>
|
||||
@@ -31,7 +33,7 @@
|
||||
<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>
|
||||
|
||||
+52
@@ -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);
|
||||
}
|
||||
}
|
||||
+52
@@ -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);
|
||||
}
|
||||
}
|
||||
+40
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user