복붙노트

[SPRING] Spring Cloud Stream @SendTo 주석이 작동하지 않음

SPRING

Spring Cloud Stream @SendTo 주석이 작동하지 않음

스프링 부트와 함께 스프링 클라우드 스트림을 사용하고 있습니다. 내 응용 프로그램은 매우 간단합니다.

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 메서드 (클래스 외부에서 테스트)를 호출하면 메시지가 'test_output'교환에 보내지지 않습니다.

저는 Spring Boot 2.0.6.RELEASE 및 Spring Cloud Stream 2.0.2와 함께 작업하고 있습니다. 릴리스.

누가 시나리오 2)가 작동하지 않는지 아는 사람이 있습니까? 미리 감사드립니다.

해결법

  1. ==============================

    1.@SendTo가 독자적으로 지원된다고 믿게하는 이유는 무엇입니까? @SendTo는 Spring Cloud Stream뿐만 아니라 많은 프로젝트에서 사용되는 2 차 주석이다. 내가 아는 한, 독자적으로 찾아 볼 것은 없습니다.

    @SendTo가 독자적으로 지원된다고 믿게하는 이유는 무엇입니까? @SendTo는 Spring Cloud Stream뿐만 아니라 많은 프로젝트에서 사용되는 2 차 주석이다. 내가 아는 한, 독자적으로 찾아 볼 것은 없습니다.

    Spring Integration의 @Publisher 어노테이션 대신 @EnablePublisher를 사용해보십시오.

    편집하다

    JDK 프록시가 아닌 CGLIB로 강제로 프록시하려면 다음을 수행하십시오.

    @Bean
    public static BeanFactoryPostProcessor bfpp() {
        return bf -> {
            bf.getBean(IntegrationContextUtils.PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME,
                    PublisherAnnotationBeanPostProcessor.class).setProxyTargetClass(true);
        };
    }
    
  2. from https://stackoverflow.com/questions/54119209/spring-cloud-stream-sendto-annotation-not-working by cc-by-sa and MIT license