2
votes

I'm trying to configure spring-integration to send a message to a queue and then receive it, i.e. something very simple:

myApp -> outbound message -> jmsQueue -> inbound message -> myApp

What I thought was necessary for decoupling was to have a message gateway at either end of the process. Thus my first attempt (which works) looks like the following:

@MessagingGateway(name = "outboundGateway")
public interface OutboundGateway {


  @Gateway(requestChannel = OUTBOUND_CHANNEL)
  void sentMyObject(final MyObject myObject);
}


@Bean
public IntegrationFlow outboundFlow() {
   return IntegrationFlows
    .from(outboundChannel())
    .handle(Jms.outboundAdapter(connectionFactory).destination(myQueue))
    .get();
}

@Bean
public IntegrationFlow inboundFlow() {
    return IntegrationFlows.from(Jms.messageDriverChannelAdapter(connectionFactory).destination(myQueue))
     .channel(inboundChannel())
     .handle(messageReceiverHandler())
     .get();
}

Where messageReceiverHandler() is a bean that extends AbstractMessageHandler.

So above we have a message gateway for the outbound message. What I had presumed is that we should have one for the inbound message too, allowing us to decouple the incoming message handling from the application code. Instead we simply have a bean that extends AbstractMessageHandler, whereas I'd expect some gateway config. What's the correct usage?

Many thanks in adance.

1

1 Answers

1
votes

First of all, you generally need to use a Jms.outboundGateway() for request/reply messsaging rather than two separate flows; you can make it work with adapters but it needs more work and, in this scenario, doesn't provide any benefit.

You can use:

...
.from(outboundChannel())
.handle(Jms.outboundGateway(...))
.handle("myPojo", "someMethod")
.get();

Where myPojo is a bean containing application code with the method taking the type returned by the gateway. The reply from the gateway goes to the next element in the flow.

It is generally not recommended that you inherit from framework classes, unless you have special requirements.

EDIT

However, this expects the remote system to reply using the JmsReplyTo header. Also, the reply from your second handler will go to the gateway (which shouldn't have a void reply).

For completely async request/reply your configuration is correct, but you can use a POJO in your .handle().