Open marcosfromrio opened 4 years ago
You're not closing the connection. You might want to try with a connection manager to make sure the socket is closed and flushed correctly (this is only a guess).
with rabbitpy.Connection() as conn:
with conn.channel() as channel:
for message_number in range(0, 10):
...
I am running into the same problem with the same exact code. I added this:
if message.publish(exchange, 'example-routing-key', mandatory=True):
print("Message " + str(message_number) + " confirmed")
else:
print("Message " + str(message_number) + " failed")
and i get a failed for every published messge. But when it is all done, and i do a:
connection.close()
all the messages do appear in the queue. I do not understand why the publishing is failing, but they do get sent over when i close the connection.
I am using Python 3.9.5.
EDIT: it turns out that it is not closing per se. if i put in a sleep after all the publish calls, the message eventually get into the queue. So it seems like it is a timing issue.
OBS: when i run this code in shell python instead run the file with python file.py, the code works normally.
The video show the print for all loop in range, but only one or two messages is sent: https://vimeo.com/412936004
Terminal examples:
/\ i run this file 10 times.
And i get this messages:
Source code without comments:
publisher.py:
consumer.py: