This seems like such an obvious requirement! How can there be no way to detect that basic_publish failed? I tried all kinds of stuff including transactions and add_on_return_callback (all of which seemed clunky and overly complicated), but came up with nothing. Pika does not appear to have a way to detect delivery failure, which means that data may be lost if the connection drops. I attempted to refactor your code to make it work as I think you wanted it to, but ran into another problem. It does not cause a reconnect if the connection is interrupted. This is not safe.Īlso, SimpleReconnectionStrategy does not seem to do anything useful. The main problem with your script is that it is interacting with a single channel from both your main thread (where the ioloop is running) and the "Broker" thread (calls submitData in a loop). Logging.basicConfig(level=logging.DEBUG, format=format) ('Submitting data to broker.')įormat=('%(asctime)s %(levelname)s %(name)s %(message)s') _consume(self.processData, queue='sandbox')ĭef processData(self, ch, method, properties, body): Self.submitData(om_broker.get(block=True)) nnection = SelectConnection(self.parameters, self.on_connected, reconnection_strategy=self.srs) Self.properties = pika.BasicProperties(delivery_mode=2) Self.parameters = pika.ConnectionParameters(host='sandbox',heartbeat=True) Could someone have a look at the code so see what I'm doing wrong?įrom pika.reconnection_strategies import SimpleReconnectionStrategyįrom pika.adapters import SelectConnection So it looks like I can't get the reconnection strategy working as it should be. When the script runs locally on the RabbitMQ server and I kill the RabbitMQ then the script exits with error: "ERROR pika SelectConnection: Socket Error on 3: 104" This might be explained because of network issues, packets dropped although I find the connection not really robust. When I run my script on the same host on which RabbitMQ is installed it runs fine and keeps running.When I run my script from one host connecting to rabbitmq on another host (inside a vm) then this scripts exits on random moments without producing an error. ![]() Get item from Queue.Queue(0) and produce it back into the broker queue.Consume this queue and put result into a python Queue.Queue(0).Connect to Broker, retry until successful.I wrote this test app which does following: ![]() I'm using Pika to process data from RabbitMQ.Īs I seemed to run into different kind of problems I decided to write a small test application to see how I can handle disconnects.
0 Comments
Leave a Reply. |