Spring Cloud Stream @SendTo注释不起作用

2023-12-15

我正在将 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) 不起作用吗?提前致谢。


是什么让你相信@SendTo本身是否支持?@SendTo是很多项目使用的辅助注解,不仅仅是Spring Cloud Stream;据我所知,没有什么可以自行寻找它。

尝试 Spring 集成@Publisher改为注释(用@EnablePublisher).

EDIT

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

@Bean
public static BeanFactoryPostProcessor bfpp() {
    return bf -> {
        bf.getBean(IntegrationContextUtils.PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME,
                PublisherAnnotationBeanPostProcessor.class).setProxyTargetClass(true);
    };
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring Cloud Stream @SendTo注释不起作用 的相关文章

随机推荐