Wrong order of callbacks
See original GitHub issueHello,
NATS documentation says, that messages from one publisher are received in the same order as they were published. But if we make few subscriptions, and publish messages for each one few times, callbacks will be called in different order. This is because each subscriber has own message queue. Here is example:
receive.py
import asyncio
from nats.aio.client import Client as NATS
async def run(loop):
await nc.connect("nats://nats:4222", loop=loop)
async def message_handler_A(msg):
print('message_handler_A')
async def message_handler_B(msg):
print('message_handler_B')
async def message_handler_C(msg):
print('message_handler_C')
await nc.subscribe("message_handler_A", cb=message_handler_A)
await nc.subscribe("message_handler_B", cb=message_handler_B)
await nc.subscribe("message_handler_C", cb=message_handler_C)
print('receiving')
if __name__ == '__main__':
nc = NATS()
loop = asyncio.get_event_loop()
loop.run_until_complete(run(loop))
loop.run_forever()
publish.py:
import asyncio
from nats.aio.client import Client as NATS
async def run(loop):
await nc.connect("nats://nats:4222", loop=loop)
for i in range(10):
await nc.publish("message_handler_B", b"")
await nc.publish("message_handler_C", b"")
await nc.publish("message_handler_A", b"")
if __name__ == '__main__':
nc = NATS()
loop = asyncio.get_event_loop()
loop.run_until_complete(run(loop))
loop.run_forever()
Just run publish.py after receive.py.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Javascript callback - executing in wrong order - Stack Overflow
I am writing a script which is to upload files. I want to check if the file exists before the upload takes place,...
Read more >[BUG] callbacks called in wrong order / too often #832 - GitHub
When I zoom in: update_limits callback should be called, which outputs to the limits store. update_data should now be called since it depends...
Read more >What is the execution order of callbacks? - Dash Python
If no callbacks depend on each other, then the order is random and if you are running the app with multiple workers (e.g....
Read more >Callback Execution - MATLAB & Simulink - MathWorks
The order in which listeners callback functions execute after the firing of an event is undefined. However, all listener callbacks execute synchronously ...
Read more >Wrong order status (Cancelled) - WordPress.org
And since the callbacks are never processed, the orders are never marked as paid. Furthermore it sounds like your WooCommerce is cancelling unpaid...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve found that asyncio.Lock doing job. I added lock around callbacks which should run in ordered way.
Closing as that is how the client is intended to work right now (similar behavior as in the Go client).