Results 1 to 6 of 6

Thread: Intercept "end of processing"

  1. #1

    Default Intercept "end of processing"

    Currently, one of the steps in processing messages takes some data about the message and stores it in a "job context" using ThreadLocals, ala SecurityContextHolder. I'm looking for a clean way to clear that context at the end of processing, regardless of how the processing ends (exception, outbound JMS, another gateway).

    It seems like it should be possible to do this, without hooking everything into an explicit channel, but I seem to be missing something. Perhaps the only way to do this IS with an explicit channel (maybe a pub-sub for each path where the message ends)? Seems a little cumbersome though.

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,146

    Default

    It depends on the inbound endpoint. If it's a polled endpoint (or message-driven adapters that support the <transactional/> element - such as the imap idle mail adapter), you can use a 'PseudoTransactionManager', with 'onCommit' 'onRollback' expressions that can invoke a @bean to do the clean up.

    For other message-driven adapters, you can put an interceptor on the first channel, and do the clean up in the post-Send - this can do the clean up for "good" results; for exceptions, you'd use an error-channel and do the clean up there.

    You can also use this technique for polled adapters (put the error-channel on the poller).
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3

    Default

    The PseudoTransactionManager sounds like the surest solution to me. The reason for trying to do it at the end is that the context information is getting logged and some logging occurs before the messages reach the first channel. It's those first couple messages that look off in our logs. I'll see what I can come up with.

    Thanks!

  4. #4

    Default

    Hmm, the approach of using a PseudoTransactionManager seems to be "complicated" by the fact that the input is coming from a JMS listener adapter that has a TransactionManager already. Now I'm down the rabbit-hole of understanding the TransactionSynchronizationManager stuff but can't seem to get a grip on it from Javadoc or the (sparse) available blog entries around the web.

    We're already using a subclass of DefaultMessageListenerContainer to generate a selector string for JMS Messages, and from what I gather I need to register my TransactionSynchronization in there somewhere. I can probably fumble through it but not before my deadline. Any advice on where to learn some more about this for the future?
    Last edited by nickspacek; Feb 28th, 2013 at 12:17 PM.

  5. #5
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,146

    Default

    Well, I suggested the PseudoTM only for polled adapters; the message-driven case is much more complex, especially with something that already has transactional semantics such as the JMS adapter.

    Yes, it can be done but, as you have discovered, Transaction sychronization is not trivial.

    You have to register a synchronization object and the TM will call it during the tx synch. process.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  6. #6

    Default

    Sounds good, thanks for the advice. I took the lame way out in the meantime and hacked it into commitIfNecessary. I will replace it with the sync stuff as soon as possible.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •