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 config;
|
||||
|
||||
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
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
@EnableModule
|
||||
@EnableModule(Sink.class)
|
||||
public class TappingLoggingSink {
|
||||
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(TappingLoggingSink.class);
|
||||
|
||||
@Input
|
||||
public MessageChannel input;
|
||||
|
||||
@ServiceActivator(inputChannel="input")
|
||||
@ServiceActivator(inputChannel = Sink.INPUT)
|
||||
public void loggerSink(Object payload) {
|
||||
logger.info("Received: " + payload);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,11 @@ package demo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.stream.annotation.EnableModule;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
import config.TappingLoggingSink;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableModule
|
||||
@ComponentScan(basePackageClasses= TappingLoggingSink.class)
|
||||
public class TapApplication {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user