diff --git a/pom.xml b/pom.xml index b9a34f9..7b76216 100644 --- a/pom.xml +++ b/pom.xml @@ -40,6 +40,7 @@ ribbon-default-config ribbon-eureka sleuth + stream-bus turbine turbine-amqp zipkin diff --git a/stream-bus/docker-compose.yml b/stream-bus/docker-compose.yml new file mode 100644 index 0000000..1a53d6e --- /dev/null +++ b/stream-bus/docker-compose.yml @@ -0,0 +1,5 @@ +rabbitmq: + image: rabbitmq:management + ports: + - "5672:5672" + - "15672:15672" diff --git a/stream-bus/pom.xml b/stream-bus/pom.xml new file mode 100644 index 0000000..6e59988 --- /dev/null +++ b/stream-bus/pom.xml @@ -0,0 +1,108 @@ + + + 4.0.0 + + org.springframework.cloud.sample + spring-cloud-sample-stream-bus + Brixton.BUILD-SNAPSHOT + jar + + spring-cloud-sample-stream-bus + Demo project for Spring Cloud + + + org.springframework.boot + spring-boot-starter-parent + 1.3.3.RELEASE + + + + + UTF-8 + 1.7 + + + + + + + maven-deploy-plugin + + true + + + + + + + + org.springframework.cloud + spring-cloud-starter-config + + + org.springframework.cloud + spring-cloud-starter-bus-amqp + + + org.springframework.cloud + spring-cloud-stream-test-support + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.cloud + spring-cloud-dependencies + Brixton.BUILD-SNAPSHOT + pom + import + + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + diff --git a/stream-bus/src/main/java/demo/StreamBusApplication.java b/stream-bus/src/main/java/demo/StreamBusApplication.java new file mode 100644 index 0000000..92a4f76 --- /dev/null +++ b/stream-bus/src/main/java/demo/StreamBusApplication.java @@ -0,0 +1,18 @@ +package demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.stream.annotation.EnableBinding; +import org.springframework.cloud.stream.messaging.Source; + +/** + * @author Dave Syer + */ +@SpringBootApplication +@EnableBinding(Source.class) +public class StreamBusApplication { + + public static void main(String[] args) { + SpringApplication.run(StreamBusApplication.class, args); + } +} \ No newline at end of file diff --git a/stream-bus/src/main/resources/application.yml b/stream-bus/src/main/resources/application.yml new file mode 100644 index 0000000..c732361 --- /dev/null +++ b/stream-bus/src/main/resources/application.yml @@ -0,0 +1,8 @@ +spring: + application: + name: stream-bus +--- +spring: + profiles: other +server: + port: 8081 \ No newline at end of file diff --git a/stream-bus/src/test/java/demo/StreamBusApplicationTests.java b/stream-bus/src/test/java/demo/StreamBusApplicationTests.java new file mode 100644 index 0000000..f4e912f --- /dev/null +++ b/stream-bus/src/test/java/demo/StreamBusApplicationTests.java @@ -0,0 +1,53 @@ +package demo; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.cloud.bus.SpringCloudBusClient; +import org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent; +import org.springframework.cloud.stream.messaging.Source; +import org.springframework.cloud.stream.test.binder.MessageCollector; +import org.springframework.messaging.Message; +import org.springframework.messaging.support.MessageBuilder; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = StreamBusApplication.class) +@IntegrationTest +@DirtiesContext +public class StreamBusApplicationTests { + + @Autowired + private Source source; + + @Autowired + private SpringCloudBusClient bus; + + @Autowired + private MessageCollector collector; + + @Test + public void streaminess() throws Exception { + Message message = MessageBuilder.withPayload("Hello").build(); + this.source.output().send(message); + assertEquals(message, this.collector.forChannel(this.source.output()).take()); + } + + @Test + public void business() throws Exception { + Message message = MessageBuilder + .withPayload(new RefreshRemoteApplicationEvent(this, "me", "you")) + .build(); + this.bus.springCloudBusOutput().send(message); + String payload = (String) this.collector + .forChannel(this.bus.springCloudBusOutput()).take().getPayload(); + assertTrue("Wrong payload: " + payload, payload.contains("\"type\"")); + } + +}