0
votes

I am polling for files for a service-activator, using a PseudoTransactionManager to move them into processed/failed directories. If/when the move fails, I would like to log this, including the file name.

As the information being passed around the flows is the Message object, I tried enriching the file name onto its header, but as we make copies of it for each step, this won't work unless I can move the header-enricher between the inbound channel adapter and transaction manager.

In simplified form the main flow I now have is this:

  • inbound-channel-adapter -> a) header-enricher -> service-activator

Because I want the files moved to a processed or failed directory, there is a second flow:

  • inbound-channel-adapter -> b) pseudo transaction-manager -> logging-channel-adapter (in case of problems moving the processed file).

I think this follows because the transaction manager definition is nested within the channel adapter definition in the xml.

How can I pass this information through the example setup here to a logging channel adapter?

1

1 Answers

0
votes

The transaction stuff only has access to the original message. You can add an error-channel to the poller; the default error channel (errorChannel) is a pub/sub channel and has a logging channel adapter subscribed to it.

When an exception occurs, an ErrorMessage is sent to the error channel (if configured); the payload is a MessagingException with cause and failedMessage properties. The failedMessage is the message at the point the failure occurred.

The default error flow will simply log the message so your "transaction" will "commit".

Instead, you need a custom error flow; log what you want and then re-throw the cause and your "transaction" will "rollback".