A characteristic of an asynchronous behaviour is that it doesn't wait on the handling of the current request to be completed before attending to the next one.
In my recent exploration with Pika + RabbitMQ, I wanted to verify the above by using the Pika SelectConnection()
adapter. I have written the publisher code (pub.py) and the consumer code (cons.py) for the experiment.
I planned to run pub.py and cons.py once seperately in shell terminal, where the publisher will send arbitrary messages in quick succession and see it being received live by the consumer. In order to see the asynchronous behaviour in effect, the consumer will fake a long process (10 secs delay using time.sleep(10)
) whenever it received a message suffixed with "-10s".
I was expecting the consumer to display subsequent messages that were sent while the consumer is still working on a "-10s" message. However, this was not the case.
What I saw was the consumer pausing on the "-10s" message and only display the subsequent messages ALL AT ONCE after the work on the "-10s" message is completed. This suggests a synchronous behaviour.
Is there something wrong either with my understanding or the test codes I have written? I think I can really use some advise here.