3
votes

I am working on adding logging/monitoring functionality for multiple spring integration deployments. I want to create a logger transaction at the start of the workflow and close the log transaction at the end of the workflow. At the end of the logger transaction I will send out the logs and metrics to a centralized logging server. At the end of the day I want to see the logs for all the messages that went through workflows across multiple spring integration deployments.

The spring integration deployments are across a lot of teams and I cant count on each team to add the logging code for me, so I want to write code that will run across the spring integration deployments.

To start a log transaction,the solution was to use a global-channel interceptor on a set of inbound messaging channels. All the workflows built across deployments use the same set of inbound channels, so the start log transaction interceptor will run. Also I pass the logger transaction details as part of the message headers

But I am having trouble figuring out a solution for ending the transaction. The workflows can be synchronous as well as asynchronous. Also not all endpoints within the workflow will have a output channel.

Any strategies/ideas on how can I close the logger transaction ?

An example of a sample workflow is shown in the image below:

enter image description here

1

1 Answers

1
votes

When you have a flow that ends with a channel adapter (or other endpoint that produces no result), make the last channel a publish-subscribe-channel; subscribe a second endpoint to that channel that terminates the "transaction".

I generally prefer to add an order attribute on such endpoints - make the regular endpoint order="1" and the flow terminator order="2" - clearly indicating it is called after the main endpoint.

It is important that no task executor is added to the channel so the endpoints are called serially on the same thread.