Kros
Kros

Reputation: 848

Spring Integration 2 - Splitter only returns the first element

I am using Spring Integration 2. I have the following scenario. A 'MassMessageObject' which is made up of a body field and a list of recipients. I am implementing a splitter to create a 'BasicMessageObject' for every recipient in the list. The problem is that only the first message is received by the output channel of the splitter. Eg:

MassMessageObject> [body: Hello, recipients{A,B}] Is creating a List of BasicMessageObject {[body: Hello, recipient: A], [body: Hello, recipient: B]}.

The endpoint connected to the out put channel is receiving '[body: Hello, recipient: A]' but not '[body: Hello, recipient: B]'.

The following is my application context:

<int:splitter input-channel="mass_receiving_channel"
                  output-channel="receiving_channel"                  
                  method="splitMessages"
                  ref="massMessageSplitter"/>

<!-- Main Chain. The one that will lead to the messageTypeRouter -->
<int:chain input-channel="receiving_channel" output-channel="sms_channel">
        <int:service-activator ref="saveMessageToDB" method="saveMessageToDB"/>
        <int:gateway request-channel="message_type_router_channel"/>
</int:chain>

The following is the splitter ...

public List<BasicMessageObject> splitMessages(final GenericMessage message) {
        List<BasicMessageObject> messages = new ArrayList<BasicMessageObject>();
        // DOING STUFF HERE 
        return messages;
    }
}





[springframework.integration.jms.ChannelPublishingJmsMessageListener:234] - converted JMS Message [ActiveMQObjectMessage {commandId = 6, responseRequired = true, messageId = ID:PC-CMICALLEF-61953-1335249128607-0:0:1:2:1, originalDestination = null, originalTransactionId = null, producerId = ID:PC-CMICALLEF-61953-1335249128607-0:0:1:2, destination = queue://mass_messaging_queue, transactionId = null, expiration = 0, timestamp = 1335249128840, arrival = 0, brokerInTime = 1335249128841, brokerOutTime = 1335249128842, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@39673d71, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false}] to integration Message payload [com.connexo.icubeplus3.dispatcher.connector.messageobjects.SmsMassMessageObject@28f2e328]
[springframework.integration.channel.DirectChannel:224] - preSend on channel 'mass_receiving_channel', message: [Payload=com.connexo.icubeplus3.dispatcher.connector.messageobjects.SmsMassMessageObject@28f2e328][Headers={timestamp=1335249128882, id=fb9904da-f5b1-49e0-af25-6711015f1365, jms_redelivered=false, jms_messageId=ID:PC-CMICALLEF-61953-1335249128607-0:0:1:2:1}]
[springframework.integration.splitter.MethodInvokingSplitter:72] - org.springframework.integration.splitter.MethodInvokingSplitter@56de9984 received message: [Payload=com.connexo.icubeplus3.dispatcher.connector.messageobjects.SmsMassMessageObject@28f2e328][Headers={timestamp=1335249128882, id=fb9904da-f5b1-49e0-af25-6711015f1365, jms_redelivered=false, jms_messageId=ID:PC-CMICALLEF-61953-1335249128607-0:0:1:2:1}]
[springframework.integration.splitter.MethodInvokingSplitter:157] - handler 'org.springframework.integration.splitter.MethodInvokingSplitter@56de9984' sending reply Message: [Payload=[SMS] [sender: icube+] [destination: +35611111111] [messageIdentifier: 1234] [clientId: 1]][Headers={timestamp=1335249137537, id=566d7d54-f4cc-4896-8d39-d95636c20a57, correlationId=fb9904da-f5b1-49e0-af25-6711015f1365, jms_redelivered=false, sequenceSize=4, sequenceNumber=1, jms_messageId=ID:PC-CMICALLEF-61953-1335249128607-0:0:1:2:1}]
[springframework.integration.channel.DirectChannel:224] - preSend on channel 'receiving_channel', message: [Payload=[SMS] [sender: icube+] [destination: +35611111111] [messageIdentifier: 1234] clientId: 1]][Headers={timestamp=1335249137537, id=566d7d54-f4cc-4896-8d39-d95636c20a57, correlationId=fb9904da-f5b1-49e0-af25-6711015f1365, jms_redelivered=false, sequenceSize=4, sequenceNumber=1, jms_messageId=ID:PC-CMICALLEF-61953-1335249128607-0:0:1:2:1}]
[springframework.integration.handler.MessageHandlerChain:72] - org.springframework.integration.handler.MessageHandlerChain#0 received message: [Payload=[SMS] [sender: icube+] [destination: +35611111111] [messageIdentifier: 1234] [clientId: 1]][Headers={timestamp=1335249137537, id=566d7d54-f4cc-4896-8d39-d95636c20a57, correlationId=fb9904da-f5b1-49e0-af25-6711015f1365, jms_redelivered=false, sequenceSize=4, sequenceNumber=1, jms_messageId=ID:PC-CMICALLEF-61953-1335249128607-0:0:1:2:1}]
[springframework.integration.handler.ServiceActivatingHandler:72] - ServiceActivator for [org.springframework.integration.handler.MethodInvokingMessageProcessor@27b71c12] received message: [Payload=[SMS] [sender: icube+] [destination: +35611111111] [messageIdentifier: 1234] [clientId: 1]][Headers={timestamp=1335249137537, id=566d7d54-f4cc-4896-8d39-d95636c20a57, correlationId=fb9904da-f5b1-49e0-af25-6711015f1365, jms_redelivered=false, sequenceSize=4, sequenceNumber=1, jms_messageId=ID:PC-CMICALLEF-61953-1335249128607-0:0:1:2:1}] .... 

Upvotes: 1

Views: 2976

Answers (1)

Geert Claeys
Geert Claeys

Reputation: 31

I had the same issue. Adding a task executor to the outgoing channel of the splitter enables Spring to deliver all messages coming from the splitter:

<splitter input-channel="incoming-splitter" output-channel="outgoing-splitter"/>

<channel id="outgoing-splitter">
  <dispatcher task-executor="taskExecutor"/>
</channel>

<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
  <!-- Use 1 for sequential processing -->
  <property name="corePoolSize" value="1"/>
  <property name="maxPoolSize" value="1"/>
  <property name="threadNamePrefix" value="Splitter Message Handler "/>
  <property name="waitForTasksToCompleteOnShutdown" value="true"/>
</bean>

Upvotes: 1

Related Questions