basic_publish back is None

29 views
Skip to first unread message

Alan Lee

unread,
Jun 16, 2024, 1:20:22 AMJun 16
to Pika
channel = connection.channel()
result = channel.basic_publish(exchange=exchange_name, routing_key=routing_key, body=message_body,
properties=pika.BasicProperties(
delivery_mode=2
))

The result is always None, even if the message has been successfully sent.

Alan Lee

unread,
Jun 16, 2024, 1:31:15 AMJun 16
to Pika

import pika

connection = pika.BlockingConnection(
pika.ConnectionParameters(host='172.26.22.201',
credentials=pika.PlainCredentials('guest', '123456'),
virtual_host="/"))
channel = connection.channel()

channel.confirm_delivery()

if channel.basic_publish(exchange='exchange.direct.order', routing_key='order', body='Hello, RabbitMQ!'):
print("sucessful delivery")
else:
print("failed delivery")

Alan Lee

unread,
Jun 16, 2024, 1:31:40 AMJun 16
to Pika
always None

terren...@gmail.com

unread,
Jun 17, 2024, 8:49:14 PMJun 17
to pika-...@googlegroups.com
basic_publish returns None, or will raise one of two exceptions. Just ensure the messages are sent as Mandatory and the channel mode is set to confirm, then catch these two to handle unroutable or returned messages, otherwise I think you can assume the message was publish successfully.



Sent from my iPhone

On Jun 16, 2024, at 1:31 AM, Alan Lee <al6...@gmail.com> wrote:

always None
--
You received this message because you are subscribed to the Google Groups "Pika" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pika-python...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pika-python/8d487445-1691-41e5-81be-f1f6aa35e157n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages