1
votes

I have one spring integration application. It has various channels, transformers, routers and service activators configured.

Requirement

Whenever any service activators will be called, the request and response should be persisted.

Solution:

I have written one interceptor to intercept all the required channels. then based on the configuration all the required requests and responses are getting persisted in DB.

Problem with above approach

Whenever I restart my application server, 1st time it is taking too much time to initialize database configuration. second problem is whenever persistence logic is getting executed, flow is on wait state.

so, it is taking time to provide the response.

Guidance I am looking to make persistence asynchronously.

Is there any way to achieve the same? should I implement threading for persistence implementation?

Any help would be appreciated.

Thanks.

1

1 Answers

2
votes

The technique you are looking for is called WireTap: https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-channels-section.html#channel-wiretap.

So, whatever is going to be send to the service activator, will be send to the "tapping" channel as well. And this indeed can shift to other thread for async save to the DB. For this purpose you can consider to make that wire-tap channel as a QueueChannel or an ExecutorChannel.

1st time it is taking too much time to initialize database configuration

That's something wrong from the architecture perspective. It's OK to initialize a test environment, but in production your DB must be prepared in advance and no any schema modifications from the application.