user2101699
user2101699

Reputation: 257

Kotlin with Spring - perform actions after response

I'm using Spring to answer a few http requests using Kotlin. I wanna perform an action (specifically monitoring action) that has nothing to do with the response to the user, therefore I'd like to perform it after the response so there would be no penalty for the user.

Is this possible?

Upvotes: 1

Views: 208

Answers (1)

ByteWelder
ByteWelder

Reputation: 5604

You generally do this by using some kind of queueing/messaging/action system that passes this work onto another thread.

In Spring, you could start a service that performs these actions for you. This service can then leverage coroutines to do the actual work in a background thread.

Alternatively/additionally, if your actions take up a long time, you could use a message queue system to handle these actions. There are various message queue projects, like RabbitMQ, that allow you to create messages on one machine, and let them be handled on 1 or more other machines. That way, your front-end server can leave some of the hard work to other servers.

Upvotes: 1

Related Questions