Use @EnableModule(Channels.class) instead of field declarations
Standard channel interface types of Sink, Source, Processor are provided, but user can create others with @Input and @Output MessageChannel methods. To get the declared channels in an app you can use the @ModuleChannels qualifier to inject the interface, e.g. @ModuleChannels(Cafe.class) injects the channels defined in the Cafe.
This commit is contained in:
@@ -18,25 +18,20 @@ package sink;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.cloud.stream.annotation.EnableModule;
|
||||
import org.springframework.cloud.stream.annotation.Input;
|
||||
import org.springframework.cloud.stream.annotation.Sink;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@EnableModule
|
||||
@EnableModule(Sink.class)
|
||||
public class LogSink {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(LogSink.class);
|
||||
|
||||
@Input
|
||||
public MessageChannel input;
|
||||
|
||||
@ServiceActivator(inputChannel="input")
|
||||
@ServiceActivator(inputChannel=Sink.INPUT)
|
||||
public void loggerSink(Object payload) {
|
||||
logger.info("Received: " + payload);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
package demo;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.stream.annotation.ModuleChannels;
|
||||
import org.springframework.cloud.stream.annotation.Output;
|
||||
import org.springframework.cloud.stream.annotation.Sink;
|
||||
import org.springframework.cloud.stream.annotation.Source;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import sink.LogSink;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = SinkApplication.class)
|
||||
@@ -13,8 +23,19 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@DirtiesContext
|
||||
public class ModuleApplicationTests {
|
||||
|
||||
@Autowired
|
||||
@ModuleChannels(LogSink.class)
|
||||
private Sink sink;
|
||||
|
||||
@Autowired
|
||||
private Sink same;
|
||||
|
||||
@Output(Source.OUTPUT)
|
||||
private MessageChannel output;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
assertNotNull(this.sink.input());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user