After some debugging and reading, finally I came to a solution for this issue. An inbound-gateway is a JmsMessageDrivenEndpoint, based in two inner components, a MessageListenerContainer and a MessageListener. MessageListenerContainer is the one in charge at scheduling MessageListener behaviour so, overriding the noMessageReceived and messageReceived, and adding some attributes to control the desired behaviour, I could be able to do the "magic".
My MessageListenerContainer implementation got like this.
public class ControlMessageListenerContainer extends DefaultMessageListenerContainer{
private JmsMessageDrivenEndpoint mainInputGateway;
private long timeOut;
private long lastTimeReceived;
public PassControlMessageListenerContainer() {
this.setAutoStartup(false);
}
@Override
public void start() throws JmsException {
/*When the container is started the lastTimeReceived is set to actial time*/
lastTimeReceived = (new Date()).getTime();
super.start();
}
@Override
protected void noMessageReceived(Object invoker, Session session) {
long actualTime = (new Date()).getTime();
if((actualTime - lastTimeReceived) >= timeOut
&& mainInputGateway != null && !mainInputGateway.isRunning()){
mainInputGateway.start();
}
super.noMessageReceived(invoker, session);
}
@Override
protected void messageReceived(Object invoker, Session session) {
/*lastTimeReceived is set again to actual time at new message arrive*/
lastTimeReceived = (new Date()).getTime();
super.messageReceived(invoker, session);
}
}
And finally, the spring bean config get like this:
<bean id="listenerContainer"
class="org.merol.ControlMessageListenerContainer">
<property name="mainInputGateway" ref="mainGateway" />
<property name="destination" ref="onHoldQueue" />
<property name="timeOut" value="10000"/>
<property name="connectionFactory" ref="connectionFactory"/>
</bean>
<bean id="messageListener"
class="org.springframework.integration.jms.ChannelPublishingJmsMessageListener">
<property name="requestChannel" ref="outputChannel" />
</bean>
<bean id="inboundGateway"
class="org.springframework.integration.jms.JmsMessageDrivenEndpoint">
<constructor-arg name="listenerContainer" ref="listenerContainer" />
<constructor-arg name="listener" ref="messageListener" />
</bean>
Hope this could be helpful for someone else.
Thanks to @Nicholas for the clues.