没有回复通道错误,即使它是在网关中定义的
No reply channel error, even if it is defined in the gateway
我已经创建了一个带有请求通道和回复通道的 spring dsl 网关。此网关产生输出。
@MessaginGateway
public interface Gateway{
@Gateway(requestChannel="reqChannel", replyChannel="replyChannel")
String sayHello(String name);
}
我正在尝试在单元测试中测试输出。所以我在我的单元测试上下文中创建了一个桥梁。当我尝试从桥接通道接收它时,它给我 "no output-channel or reply-channel header available" 错误。
我创建了如下桥。
@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 并设置 属性。除了 'gatewayRequestChannel',我可以在那里调用 java 方法并设置 return 值吗?
你不能那样做;网关将回复频道作为 header 插入。
您的桥正在回复通道上创建第二个消费者。
如果你想在单元测试中模拟网关在做什么,删除那个桥并使用:
QueueChannel replyChannel = new QueueChannel();
reqChannel.send(MessageBuilder.withPayload("Name")
.setReplyChannel(replyChannel)
.build());
Message<?> reply = replyChannel.receive(10000);
在网关内部,reply-channel
桥接到消息 header;那座桥是一个消费者,你的桥是另一个。
编辑
您正在绕过增强器 - 您似乎误解了增强器的配置。 enricher 本身就是一种特殊的网关。
使用:
<int-enricher input-channel="enricherChannel"
request-channel="gatewayRequestChannel" >
<int-property name="name" expression="payload" />
</int-enricher>
并将您的测试消息发送至 enricherChannel
。浓缩器充当 gatewayRequestChannel
上流的网关,并丰富该流结果的结果。
我已经创建了一个带有请求通道和回复通道的 spring dsl 网关。此网关产生输出。
@MessaginGateway
public interface Gateway{
@Gateway(requestChannel="reqChannel", replyChannel="replyChannel")
String sayHello(String name);
}
我正在尝试在单元测试中测试输出。所以我在我的单元测试上下文中创建了一个桥梁。当我尝试从桥接通道接收它时,它给我 "no output-channel or reply-channel header available" 错误。
我创建了如下桥。
@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 并设置 属性。除了 'gatewayRequestChannel',我可以在那里调用 java 方法并设置 return 值吗?
你不能那样做;网关将回复频道作为 header 插入。
您的桥正在回复通道上创建第二个消费者。
如果你想在单元测试中模拟网关在做什么,删除那个桥并使用:
QueueChannel replyChannel = new QueueChannel();
reqChannel.send(MessageBuilder.withPayload("Name")
.setReplyChannel(replyChannel)
.build());
Message<?> reply = replyChannel.receive(10000);
在网关内部,reply-channel
桥接到消息 header;那座桥是一个消费者,你的桥是另一个。
编辑
您正在绕过增强器 - 您似乎误解了增强器的配置。 enricher 本身就是一种特殊的网关。
使用:
<int-enricher input-channel="enricherChannel"
request-channel="gatewayRequestChannel" >
<int-property name="name" expression="payload" />
</int-enricher>
并将您的测试消息发送至 enricherChannel
。浓缩器充当 gatewayRequestChannel
上流的网关,并丰富该流结果的结果。