Tihom
Tihom

Reputation: 3394

Akka: Adding a delay to a durable mailbox

I am wondering if there is some way to delay an akka message from processing?

My use case: For every request I have, I have a small amount of work that I need to do and then I need to additional work two hours later.

Is there any easy way to delay the processing of a message in AKKA? I know I can probably setup an external distributed queue such as ActiveMQ, RabbitMQ which probably has this feature but I rather not.

I know I would need to make the mailbox durable so it can survive restarts or crashes. We already have mongo setup so I probably be using the MongoBasedMailbox for durability.

Upvotes: 5

Views: 1193

Answers (3)

Maxim Fateev
Maxim Fateev

Reputation: 6880

Temporal Workflow is capable of supporting your use case with minimal effort. You can think about it as a Durable Actor platform. When actor state including threads and local variables is preserved across process restarts.

Temporal offers a lot of other features for task processing.

  • Built it exponential retries with unlimited expiration interval
  • Failure handling. For example, it allows executing a task that notifies another service if both updates couldn't succeed during a configured interval.
  • Support for long running heartbeating operations
  • Ability to implement complex task dependencies. For example to implement chaining of calls or compensation logic in case of unrecoverable failures (SAGA)
  • Gives complete visibility into the current state of the update. For example, when using queues all you know if there are some messages in a queue and you need additional DB to track the overall progress. With Temporal every event is recorded.
  • Ability to cancel an update in flight.
  • Throttling of requests

See the presentation that goes over the Temporal programming model. It talks about Cadence which is the predecessor of Temporal.

Upvotes: 2

Elyran
Elyran

Reputation: 313

you could still use the normal Akka scheduler, you will just have to keep a state on the actor persistence to avoid loosing the job if the server restarted.

I have recently used PersistentFsmActor - which will keep the state of the actor persisted

I'm not sure in your case you have to use FSM (Finite State Machine) , so you could basically just use a persistentActor to save the time the job was inserted, and start a scheduler to that time. this way - even if you restarted the server, the actor will start and create a new scheduled job use the persistent data to calculate the time left to run it

Upvotes: 0

jamie
jamie

Reputation: 2161

It's not ideal, but the Akka Camel Quartz scheduler would do the trick. More heavyweight than the built-in ActorSystem scheduler, but know that Quartz has its own issues.

Upvotes: 0

Related Questions