How to do async things, in order?

We have some code which is first writing to a primary db then dispatching
an event to write the same to a secondary different db.

However it seems the dispatched events do not get consumed in the order
they were sent.

Is there some way to guarantee the order sent is the order those events get
executed?

And if not, can this be done with an rpc.call_async instead?

It depends on how many consumers you have. AMQP makes certain guarantees
about ordering of messages in queues, but it means nothing if you have
multiple consumers processing the messages. This stack overflow question
<queue - RabbitMQ - Message order of delivery - Stack Overflow;
is a good reference.

The only way to do this with Nameko Events or RPC is to either use a single
consumer, or add something at the application layer to enforce ordering,
like a distributed lock that prevented parallel consumption . A more
elegant solution for this problem would probably be a new set of extensions
that used a transport with stronger ordering guarantees, such as kafka.

ยทยทยท

On Thursday, October 12, 2017 at 1:04:53 PM UTC+1, Richard wrote:

We have some code which is first writing to a primary db then dispatching
an event to write the same to a secondary different db.

However it seems the dispatched events do not get consumed in the order
they were sent.

Is there some way to guarantee the order sent is the order those events
get executed?

And if not, can this be done with an rpc.call_async instead?