Tuesday 15 June 2010

python - How to ensure that messages get delivered? -


How do you ensure that you receive the message?

Many messages can be sent in this example before pika accepts that the connection was down. PICA connection = pika.BlockingConnection (pika.ConnectionParameters (host = 'localhost')) channel = connection.channel () xrange (10) for index.queue_declare (Q = 'Hello'): channel.basic_publish (exchange = '', routing_key = 'hello', body = 'Hello world #% s!'% Index) Print ('Total messages sent:% s'% x) connection.close channel.confirm_delivery ()

Before publishing messages, / Code> flag is required to set up. This is important so that the crop can confirm that every message has been sent successfully before sending the next message. However, the time it takes to send the messages will increase, as the delivery must be confirmed before proceeding with the next message in the program. Try

  channel.confirm_delivery (): (10) for index in xrange: channel.basic_publish (exchange = '', routing_key = 'hello', body = 'hello world #% s ! '% Index') Print ('Total Messages Sent:% s'% x) Excluding pika.exceptions Connection: Closed as Excel: Print ('Error connection is closed, and message was never given'.)   

original_light a Boolean will return depending on whether the message was sent or not. However, it is important to hold potential exceptions in the case of closing the connection and handling it properly during the transfer. In those cases, the exception will obstruct the flow of the program.

No comments:

Post a Comment