Reputation: 1706
I am using a (already set up) Spring Integration worfklow in which I try to add a service-activator
that will basically count messages.
In this example I log the payload of the message but only for debugging purposes.
<bean id="messageCounterActivator" class="com.my.company.activators.MessageCounterActivator"/>
<bean id="jmsQueue2" class="com.ibm.mq.jms.MQQueue" depends-on="jmsConnectionFactory">...</bean>
<int:channel id="channelMQ_MQ" ></int:channel>
<int:service-activator input-channel="channelMQ_MQ" method="countMessage" ref="messageCounterActivator"/>
<int-jms:message-driven-channel-adapter id="jmsIn" channel="channelMQ_MQ" destination="jmsQueue"/>
<int-jms:outbound-channel-adapter channel="channelMQ_MQ"
id="jmsOut2"
destination="jmsQueue2"
connection-factory="connectionFactoryCaching2"
delivery-persistent="true"
explicit-qos-enabled="true"
session-transacted="true" />
And from the activator bean:
public Message<?> countMessage(Message<?> message) {
LOG.debug("=> " + message.getPayload());
someCounter.increment();
return message;
}
Once this bidge is up, it works well : all messages are routed from A to B (MqSeries => MqSeries), and the counter is updated.... every 2 messages!
MessageCounterActivator - => message 1
MessageCounterActivator - => message 3
MessageCounterActivator - => message 5
MessageCounterActivator - => message 7
MessageCounterActivator - => message 9
MessageCounterActivator - => message 11
MessageCounterActivator - => message 13
MessageCounterActivator - => message 15
MessageCounterActivator - => message 17
MessageCounterActivator - => message 19
This is very odd to me, but I suspect some embedded activator/listener is in competition with my service-activator
(I read from some posts here that when 2 activators, including logger ones, are active at once : you may have such behavior). Maybe it's because I have 2 channel adapters? I don't see here who is the competitor here.
Any idea how to have my activator working the right way?
Upvotes: 0
Views: 83
Reputation: 121177
I would say your counting logic is not a part of main flow. So, better to look into a wire-tap pattern and consider to use an <int:outbound-channel-adapter>
instead. Just because you not going to return anything from that counting method.
Another approach for calling different endpoints for the same message is an <int:publish-subscribe-channel>
.
Right now you declare a DirectChannel
with that <int:channel id="channelMQ_MQ">
, which has a round-robing distribution strategy by default for its subscribers. That's exactly why you see that odd-even behavior for your subscribers.
Not sure why you are missing that, but you indeed have two subscribers for this direct channel:
<int:service-activator input-channel="channelMQ_MQ"
<int-jms:outbound-channel-adapter channel="channelMQ_MQ"
See more in docs: https://docs.spring.io/spring-integration/docs/current/reference/html/core.html#channel-implementations-directchannel
Upvotes: 1