Spring integration 没有应答通道错误,即使它是在网关中定义的

Spring integration 没有应答通道错误,即使它是在网关中定义的,spring-integration,Spring Integration,我已经创建了一个带有请求通道和应答通道的SpringDSL网关。这个网关产生输出 @MessaginGateway public interface Gateway{ @Gateway(requestChannel="reqChannel", replyChannel="replyChannel") String sayHello(String name); } 我试图在单元测试中测试输出。因此,我在单元测试上下文中创建了一个桥。当我试图从桥接通道接收它时,它给了我“没有可用的输出通道或应答通

我已经创建了一个带有请求通道和应答通道的SpringDSL网关。这个网关产生输出

@MessaginGateway
public interface Gateway{
@Gateway(requestChannel="reqChannel", replyChannel="replyChannel")
String sayHello(String name);
}
我试图在单元测试中测试输出。因此,我在单元测试上下文中创建了一个桥。当我试图从桥接通道接收它时,它给了我“没有可用的输出通道或应答通道头”错误

我已经创造了如下的桥梁

@Bean
@BridgeFrom("replyChannel")
public QueueChannel bridgeOutput(){
return MessageChannels.queue.get();
}
在我的测试中,我向请求通道
reqChannel.send(MessageBuilder.withPayload(“Name”).build())发送消息并且我已尝试通过
bridgeOutput.receive(0)
接收回复。它给了我上述的错误

如果我直接调用sayHello()方法,它可以正常工作。我只是想通过直接将消息放入通道来测试网关

我错过了什么

更新:

<int-enricher request-channel="gatewayRequestChannel" >
   <int-property name="name" expression="payload" />
</int-enricher>


在上面,我将消息放入requestChannel并设置属性。我可以在那里调用java方法并设置返回值而不是“gatewayRequestChannel”吗?

您不能这样做;网关将应答通道作为报头插入

您的网桥正在回复频道上创建第二个消费者

如果要模拟网关在单元测试中的操作,请移除该网桥并使用:

QueueChannel replyChannel = new QueueChannel();
reqChannel.send(MessageBuilder.withPayload("Name")
    .setReplyChannel(replyChannel)
    .build());
Message<?> reply = replyChannel.receive(10000);

并将测试消息发送到
enricherChannel
。enricher充当到
gatewayRequestChannel
上的流的网关,并从该流的结果中丰富结果。

谢谢,我面临的另一个问题是,我已经从errorChannel实现了errorFlow。因此,我配置了setErrorChannel(),正如您在上面解释的那样。但是我的错误流没有收到消息,异常被抛出。可能出错的地方。处理错误的逻辑内置于网关中;如果在测试中绕过它,则无法调用它。仅在消息中设置错误通道是不够的。现在还不清楚你想测试什么。最好通过调用网关来测试您的流量。我之所以想这样做,是因为在enricher这样的地方,我们可以给这个网关提供请求通道,获得回复并设置属性。是否有其他方法可以直接从enricher调用网关而不是使用service activator?您不应该直接发送到网关的请求通道-您应该始终使用网关<代码>。。。直接从enricher调用网关…
。不清楚你的意思是什么,或者你想做什么;请用更多信息和示例配置编辑您的问题。您似乎误解了enricher;请参阅我的编辑。
<int-enricher input-channel="enricherChannel" 
        request-channel="gatewayRequestChannel" >
    <int-property name="name" expression="payload" />
</int-enricher>