Reputation: 5867
I have created a spring dsl gateway with request channel and reply channel. This gateway produces output.
@MessaginGateway
public interface Gateway{
@Gateway(requestChannel="reqChannel", replyChannel="replyChannel")
String sayHello(String name);
}
I am trying to test the output in unit testing. So I have created a bridge in my unit test context. And when i try to receive it from bridge channel, it is giving me "no output-channel or reply-channel header available" error.
I have created bridge like below.
@Bean
@BridgeFrom("replyChannel")
public QueueChannel bridgeOutput(){
return MessageChannels.queue.get();
}
In my test, I am sending message to the request channel reqChannel.send(MessageBuilder.withPayload("Name").build());
and I have tried to receive the reply by bridgeOutput.receive(0)
. It is giving me the above error.
If i call sayHello() method directly, it is working fine. I am just trying to test the gateway, by directly putting message into the channel.
What I am missing?
UPDATE:
<int-enricher request-channel="gatewayRequestChannel" >
<int-property name="name" expression="payload" />
</int-enricher>
In the above, i am putting message into the requestChannel and setting the property. Instead of 'gatewayRequestChannel', can I call a java method there and set the return value?
Upvotes: 1
Views: 773
Reputation: 174554
You cannot do that; the reply channel is inserted as a header by the gateway.
Your bridge is creating a second consumer on the reply channel.
If you want to simulate what the gateway is doing in a unit test, remove that bridge and use:
QueueChannel replyChannel = new QueueChannel();
reqChannel.send(MessageBuilder.withPayload("Name")
.setReplyChannel(replyChannel)
.build());
Message<?> reply = replyChannel.receive(10000);
Inside the gateway, the reply-channel
is bridged to the message header; that bridge is one consumer, your bridge is another.
EDIT
You are bypassing the enricher - you seem to have misunderstood the configuration of an enricher. The enricher is a special kind of gateway itself.
Use:
<int-enricher input-channel="enricherChannel"
request-channel="gatewayRequestChannel" >
<int-property name="name" expression="payload" />
</int-enricher>
and send your test message to enricherChannel
. The enricher acts as a gateway to the flow on gatewayRequestChannel
and enriches the results from the results of that flow.
Upvotes: 1