javaspringspring-bootspring-integrationibm-mq

How to check which JmsOutboundGateway was used by Messaging Gateway ( two JmsOutboundGateway attached to same input channel) - Spring Integration


I have problem with Spring Integration - MessagingGateway. I created gateway interface and attached to it's requestChannel two ServiceActivators.

Everything works fine but I would like to monitor which ServiceActivator(JmsOutboundGateway) is used while I will trigger gateway method ( sendMsg()) - monitoring where messages are actually sent (which JmsOutboundGateway was used) - I assume the mq connection may be closed randomly for the first or second JmsOutboundGateway.

Is there any chance to somehow monitor it ?

@MessagingGateway(name = "LocalGateway")
public interface LocalGateway {

    @Gateway(requestChannel = "inputLocalChannel")
    ListenableFuture<Message<String>> sendMsg(Message<String> request);

}

@Bean
    @ServiceActivator(inputChannel = "inputLocalChannel")
    public JmsOutboundGateway firstGateway(){
    // some code
}

@Bean
    @ServiceActivator(inputChannel = "inputLocalChannel")
    public JmsOutboundGateway secondGateway(){
    // some code
}

// use of  gateway  
    public sendMessage(){

    ListenableFuture<Message<String>> result localGateway.sendMsg("Message");

    result.addCallback(new CustomCallback());

    // some code
}

Solution

  • First of all you need to understand that default channel is a DirectChannel which comes with a round-robin handling strategy for its subscribers. So, the first message will go to first subscriber, the second to second. And so on until all subscribers are iterated, then we come back to first one for the next sent messages.

    Now, if that is OK with you, there is a way to attache a Message History into messages where you can track a journey for the message.

    Your @ServiceActivator might be marked with a @EndpointId if you find the long name generated from the method name as not convenient.

    See more info in docs:

    https://docs.spring.io/spring-integration/reference/message-history.html

    https://docs.spring.io/spring-integration/reference/configuration/annotations.html