Reputation: 21
I am working on a stateless microservice and need to run some timers in it. Now timers are inherently stateful and I need to run them in a way that the service remains stateless. The major point in this implementation is that the timers should start and stop on demand depending on different events received by the service.
A little bit about the service.
The service is created in Java / spring boot.
It's a service in a contact centre chat application. A chat has two participants: 1) Customer (inquiring about something) 2) Human Agent (helping customer with the query).
There are two timers
Customer Inactivity Timeout: means the customer didn't reply in a certain time. On expiry, chat is ended assuming the customer has left.
Agent Inactivity Timeout: means the agent didn't reply in a certain time. On expiry, chat is routed to another agent.
Now let's talk about only the first timer. It works like this:
The timer doesn't start again if it is already running.
How to implement a timer like this which can be started and stopped on demand given that the service remains stateless?
I have tried implementing these two options:
Activemq delayed message: The issue is that there is an inefficient way of removing message (stopping timer). We need to get the whole list of scheduled messages and then loop over to find the ScheduledMessageId of the desired message and then remove it.
Redis pub/sub with delayed delivery: Redis Pub/Sub is fire and forget, I don't want to miss a timer expiry in case of network glitches.
Upvotes: 1
Views: 572