Add stream-bus sample to esnure they work together

This commit is contained in:
Dave Syer
2016-04-26 11:13:01 +01:00
parent 019ebe7731
commit 884c10b971
6 changed files with 193 additions and 0 deletions

View File

@@ -40,6 +40,7 @@
<module>ribbon-default-config</module>
<module>ribbon-eureka</module>
<module>sleuth</module>
<module>stream-bus</module>
<module>turbine</module>
<module>turbine-amqp</module>
<module>zipkin</module>

View File

@@ -0,0 +1,5 @@
rabbitmq:
image: rabbitmq:management
ports:
- "5672:5672"
- "15672:15672"

108
stream-bus/pom.xml Normal file
View File

@@ -0,0 +1,108 @@
<?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>
<groupId>org.springframework.cloud.sample</groupId>
<artifactId>spring-cloud-sample-stream-bus</artifactId>
<version>Brixton.BUILD-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-cloud-sample-stream-bus</name>
<description>Demo project for Spring Cloud</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>
<build>
<plugins>
<plugin>
<!--skip deploy (this is just a test module) -->
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-test-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Brixton.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>

View File

@@ -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);
}
}

View File

@@ -0,0 +1,8 @@
spring:
application:
name: stream-bus
---
spring:
profiles: other
server:
port: 8081

View File

@@ -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<String> 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<RefreshRemoteApplicationEvent> 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\""));
}
}