Issue
How to send integer parameter to rabbitMQ with aiormq. With this:
async def save_to_db(number: int):
# Perform connection
connection = await aiormq.connect("amqp://guest:guest@" + rabbitmqHost + "/")
# Creating a channel
channel = await connection.channel()
# Sending the message
await channel.basic_publish(number, routing_key=queueName)
I am getting:
TypeError: object of type 'int' has no len()
I tried to cast it to string and then it worked. I need it to be integer to insert it to database.
Solution
basic_publish
wants bytes, not arbitrary values. You'll need to encode your value (and then decode it when it's read from the queue).
# Sending the message
await channel.basic_publish(number.to_bytes(2, byte_order="big"))
# Receiving the message
async def on_Message(message):
number = int.from_bytes(message.body, byte_order="big")
Answered By - dirn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.