0
votes

I'introducin spring integration instead legacy integration architecture in our project. This architecture supports Senders and Recievers. Each sender can be configured with 3 destinations.

  1. The main data flow, where messages should delivered. That can be file system, jms, mail, etc
  2. Backup flow. Store each received message into backup destination. Usually it's file appender where each message stored at the end of the file. That can also be jms queue. Backup gives us a chance to get message and replay if entire system failed and data loss
  3. Fail flow. If we cannot send message to destination (no connection, formatted failed to create message) messages are placed into this queue.

Spring integration gateways looks suitable. I can use default-request-channel for main flow, error-channel for fail flow. The problem with backup flow. How can I copy gateway incoming message and place it to the backup channel?

PS To be more precise here is a test and code.

https://github.com/semenodm/Coding-Exercises/tree/master/spring-integration/spring-integration/src

Test i_want_my_sender_put_message_into_fail_queue_when_sending_failed is failed because Wire Tap will always put message into its queue regardless of fail or success of main stream.

I don't want to add custom interceptors to handle this logic and cope with this problem using configuration.

2

2 Answers

0
votes

You might want to consider adding a Wire Tap that sends to "backupChannel".

See: http://static.springsource.org/spring-integration/docs/2.1.x/reference/htmlsingle/#channel-wiretap

0
votes

If you subscribe both adapters to a direct channel, with no load balancing and set an order attribute on each subscriber, the framework will automatically fail over to the second adapter if the first throws an exception.

<int:channel id="foo>
    <int:dispatcher load-balancer="none" />
</int:channel>

<... id="primary" order="1" .../>

<... id="secondary" order="2" .../>

The default load-balancer is round-robin.

Another option would be to use the new ExpressionEvaluatingMessageHandlerAdvice in the upcoming 2.2 release...

http://blog.springsource.org/2012/10/09/spring-integration-2-2-retry-and-more/