Columb1a Columb1a - 1 year ago 71
Java Question

Spring: Send multiple messages using a loop

Let's say I have a custom module in Spring XD (I'm using Spring XD + Spring Integration + hibernate). The module basically gets something from the DB (let's say I store it using an hibernate entity, so I use an objet called "DataFromDB"). DataFromDB is a list, then I get each element from the list and I want to send it using something like:

String payload = convertDataFromDBToJson(record);
return MessageBuilder.createMessage(payload, message.getHeaders());

  • The problem is every time I have to send a message I have to return a Message.

  • So I would like to loop over the DataFromDB list and send each element as a message.

Is there a way to send multiple messages?

Answer Source

If you return a Collection<Message<?>>, they will be sent as separate messages.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download