我正在将 Spring Cloud Stream 与 Spring Boot 结合使用。我的应用程序非常简单:
示例服务.类:
@EnableBinding(Processor1.class)
@Service
public class ExampleService {
@StreamListener(Processor1.INPUT)
@SendTo(Processor1.OUTPUT)
public String dequeue(String message){
System.out.println("New message: " + message);
return message;
}
@SendTo(Processor1.OUTPUT)
public String queue(String message){
return message;
}
}
处理器1.类:
public interface Processor1 {
String INPUT = "input1";
String OUTPUT = "output1";
@Input(Processor1.INPUT)
SubscribableChannel input1();
@Output(Processor1.OUTPUT)
MessageChannel output1();
}
应用程序属性:
spring.cloud.stream.bindings.input1.destination=test_input
spring.cloud.stream.bindings.input1.group=test_group
spring.cloud.stream.bindings.input1.binder=binder1
spring.cloud.stream.bindings.output1.destination=test_output
spring.cloud.stream.bindings.output1.binder=binder1
spring.cloud.stream.binders.binder1.type=rabbit
spring.cloud.stream.binders.binder1.environment.spring.rabbitmq.host=localhost
应用场景:
1)当我在“test_input.test_group”队列中推送消息时,消息被正确打印并正确发送到“test_output”交换。所以ExampleService::dequeue效果很好。
2)当我调用ExampleService::queue方法(从类外部,在测试中)时,消息永远不会发送到“test_output”交换。
我正在使用 Spring Boot 2.0.6.RELEASE 和 Spring Cloud Stream 2.0.2.RELEASE。
有人知道为什么场景 2) 不起作用吗?提前致谢。