错误:无法指定多个目的地

时间:2018-11-14 04:34:38

标签: spring-cloud-stream

我正在尝试将发送消息配置为如下所示的两个输出流。

@StreamListener(SampleBinding.INPUT1)
@SendTo({SampleBinding.OUTPUT1, SampleBinding.OUTPUT2})
public String handleM(String sampleMessage){
    log.info("Received message="+sampleMessage.toString());
    sampleMessage=sampleMessage.toUpperCase();
    return sampleMessage;
}

我遵循了这个example

出现以下错误。

  

java.lang.IllegalArgumentException:无法指定多个目的地       在org.springframework.util.Assert.isTrue(Assert.java:118)       在org.springframework.cloud.stream.binding.StreamListenerMethodUtils.getOutboundBindingTargetName(StreamListenerMethodUtils.java:146)处       在org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessor $ DefaultStreamListenerSetupMethodOrchestrator.orchestrateStreamListenerSetupMethod(StreamListenerAnnotationBeanPostProcessor.java:349)处       在org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessor.doPostProcess(StreamListenerAnnotationBeanPostProcessor.java:195)处       在org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessor.lambda $ postProcessAfterInitialization $ 0(StreamListenerAnnotationBeanPostProcessor.java:167)       在java.lang.Iterable.forEach(Iterable.java:75)       在org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessor.injectAndPostProcessDependencies(StreamListenerAnnotationBeanPostProcessor.java:285)处       在org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessor.afterSingletonsInstantiated(StreamListenerAnnotationBeanPostProcessor.java:105)处       在org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:863)       在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863)处       在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)       在org.springframework.boot.web.servle

1 个答案:

答案 0 :(得分:1)

使用基于常规StreamListener的活页夹时,无法通过MessageChannel方法发送到多个目的地。可以使用您在上面提供的链接中引用的Kafka Streams活页夹的分支功能将多个主题发送给您。如果要发送到应用程序中的多个目标,一种选择是使用Spring Cloud Stream的动态目标功能。 Here is an example关于动态目的地的工作方式。