-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
I need to process messages in parallel but in some cases, they should be processed in sequence.
A good simple example is the order case: messages for different order ids should be processed in parallel
but for the same should be processed in sequence. This pattern is described in more details at Microsoft
https://docs.microsoft.com/en-us/azure/architecture/patterns/sequential-convoy
and at ActiveMQ http://activemq.apache.org/message-groups.html . It's a common use case for Event Sourcing scenarios.
Requirements:
- at least once delivery (and exactly one within a window is even better)
- messages have a sequence key: if it's null no limitations on parallelization, if it's not null its name of a sequence
- single workers' group (in worst case 2 groups for null and non-null sequence keys)
- timeouts for processing
- up to 5 attempts to process (in error case it's better to send failed messages into the dedicated topic)
I see several options:
- NATS JetStream Workers
- NATS JetStream Workers for jobs that can run in parallel
- messages with ID header for exactly once detection
- all preprocessing in a custom code with external storage for sequences
In this case, it's unclear how my code will receive notification that
some message was processed (to check if there are more messages to
process in the same sequence).
- NATS Core Services
- NATS Core Service for jobs that can run in parallel
- all preprocessing in a custom code with external storage for all messages in progress
It's clear how to implement this option but too many queue-related code outside of the queue.
Is this possible to implement the original pattern with storage inside JetStream? Or maybe even without custom code
(maybe I missed or misunderstood some options like MaxConsumers)? Is this pattern planned for implementation in the future?