Testing 使用测试绑定器测试SpringCloud流时总是抛出MessageDeliveryException:Dispatcher没有通道的订户

Testing 使用测试绑定器测试SpringCloud流时总是抛出MessageDeliveryException:Dispatcher没有通道的订户,testing,spring-cloud,spring-cloud-stream,spring-messaging,Testing,Spring Cloud,Spring Cloud Stream,Spring Messaging,我正在尝试为我的消息生成器编写测试。但是,每当我尝试使用注入的绑定发送消息时,就会出现以下错误 Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=..., headers={spanTraceId=0761b2d61b665041, spanId=e3b298682f

我正在尝试为我的消息生成器编写测试。但是,每当我尝试使用注入的绑定发送消息时,就会出现以下错误

Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=..., headers={spanTraceId=0761b2d61b665041, spanId=e3b298682fefe198, spanParentSpanId=549ea87126d2484d, nativeHeaders={X-B3-TraceId=[0761b2d61b665041], spanTraceId=[0761b2d61b665041], X-B3-SpanId=[e3b298682fefe198], spanId=[e3b298682fefe198], X-B3-ParentSpanId=[549ea87126d2484d], spanParentSpanId=[549ea87126d2484d], X-B3-Sampled=[0], spanSampled=[0]}, X-B3-SpanId=e3b298682fefe198, X-B3-ParentSpanId=549ea87126d2484d, X-B3-Sampled=0, X-B3-TraceId=0761b2d61b665041, id=0c885a37-a1b1-fc0a-1314-e403ec1bffdb, spanSampled=0, contentType=application/json, timestamp=1589551815143}]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:138)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:105)
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73)
    ... 42 more
因为我正在测试消息生产者,所以我的代码中自然没有消费者。如何修复此异常

下面是我创建的一个最小测试类,它显示了相同的行为:

@RunWith(SpringRunner.class)
@ActiveProfiles("test")
@SpringBootTest(classes = {MessagingTest.SampleConfiguration.class, Application.class, EventMockConfiguration.class})
public class MessagingTest {

    @Autowired
    private LibraryMessageSource libraryMessageSource;

    @Autowired
    private InputDestination input;

    @Autowired
    private OutputDestination output;

    @Test
    public void test() throws Exception {
        libraryMessageSource.creations().send(MessageBuilder.withPayload("test").build());
    }

    @SpringBootApplication
    @Import({TestChannelBinderConfiguration.class})
    public static class SampleConfiguration {

    }
}
注意:Application.class my app和EventMock的主类使用特定的mock覆盖上下文中的bean

public interface LibraryMessageSource {

    String LIBRARY_CREATE = "messages-library-create";
    String LIBRARY_UPDATE = "messages-library-update";

    @Input(LIBRARY_CREATE)
    MessageChannel creations();

    @Input(LIBRARY_UPDATE)
    MessageChannel updates();
}
因为我正在测试消息生成器

您的应用程序有一个使用者,而不是生产者

@输入 消息通道事件; 您没有订阅@StreamListener

@试验 公共无效测试引发异常{ libraryMessageSource.events.sendMessageBuilder.withPayloadtest.build; }
在这种情况下,活页夹是消费者;您需要显示您的测试代码。@GaryRussell我添加了一个最小的测试类,用于调试我认为应该可以工作的。请将一个完整的最小项目发布到某个地方,展示这种行为,以便我们可以看到发生了什么。@GaryRussell我创建了一个具有类似版本的示例,我必须使用:您是正确的,在将注释从输入更改为输出后,一切都变得更有意义,并且实际工作。