Spring Cloud Stream @SendTo 注释不工作

Spring Cloud Stream @SendTo Annotation not working

我正在使用 Spring Cloud Stream 和 Spring Boot。我的申请很简单:

ExampleService.class:

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

Procesor1.class:

public interface Processor1 {

    String INPUT = "input1";
    String OUTPUT = "output1";

    @Input(Processor1.INPUT)
    SubscribableChannel input1();

    @Output(Processor1.OUTPUT)
    MessageChannel output1();
}

application.properties:

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 方法时(在测试中从 class 外部),消息永远不会发送到 'test_output' 交换。

我正在使用 Spring Boot 2.0.6.RELEASE 和 Spring Cloud Stream 2.0.2.RELEASE.

有人知道为什么方案 2) 不起作用吗?提前致谢。

是什么让您相信 @SendTo 本身是受支持的? @SendTo 是许多项目使用的辅助注释,而不仅仅是 Spring Cloud Stream;据我所知,没有任何东西会自己寻找它。

尝试使用 Spring 集成的 @Publisher 注释(使用 @EnablePublisher)。

编辑

要强制使用 CGLIB 而不是 JDK 代理进行代理,您可以这样做...

@Bean
public static BeanFactoryPostProcessor bfpp() {
    return bf -> {
        bf.getBean(IntegrationContextUtils.PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME,
                PublisherAnnotationBeanPostProcessor.class).setProxyTargetClass(true);
    };
}