0

Publishing to a non-existing exchange with rabbitpy does not raise an exception if not using with block:

>>> conn = rabbitpy.Connection('amqp://user:passw@ms7:5672/MyHost')
>>> ch = conn.channel()
>>> msg = rabbitpy.Message(ch, body_value='hello')
>>> msg.publish(exchange='invalid')
>>>

Using Channel as a context manager does raise the error:

>>> conn = rabbitpy.Connection('amqp://myuser:mypass@ms7:5672/myhost')
>>> with conn.channel() as ch:
...     msg = rabbitpy.Message(ch, body_value='hello')
...     msg.publish(exchange='invalid')
...
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "D:\Programming\mqclient\env36x64\lib\site-packages\rabbitpy\channel.py", line 101, in __exit__
    self.close()
  File "D:\Programming\mqclient\env36x64\lib\site-packages\rabbitpy\channel.py", line 147, in close
    super(Channel, self).close()
  File "D:\Programming\mqclient\env36x64\lib\site-packages\rabbitpy\base.py", line 204, in close
    self._check_for_pending_frames()
  File "D:\Programming\mqclient\env36x64\lib\site-packages\rabbitpy\base.py", line 318, in _check_for_pending_
frames
    self._check_for_rpc_request(value)
  File "D:\Programming\mqclient\env36x64\lib\site-packages\rabbitpy\channel.py", line 271, in _check_for_rpc_r
equest
    super(Channel, self)._check_for_rpc_request(value)
  File "D:\Programming\mqclient\env36x64\lib\site-packages\rabbitpy\base.py", line 328, in _check_for_rpc_requ
est
    self._on_remote_close(value)
  File "D:\Programming\mqclient\env36x64\lib\site-packages\rabbitpy\base.py", line 380, in _on_remote_close
    raise exceptions.AMQP[value.reply_code](value)
rabbitpy.exceptions.AMQPNotFound: <pamqp.specification.Channel.Close object at 0x333e438>
  • Python 3.6.8 x64
  • rabbitpy 2.0.0
  • RabbitMQ server 3.7.4
R01k
  • 735
  • 3
  • 12
  • 26
  • Did you try to ``close`` the channel manually? – MisterMiyagi Jun 17 '19 at 20:04
  • 2
    Why not report this as an issue here? [repo](https://github.com/gmr/rabbitpy) – Luke Bakken Jun 17 '19 at 20:12
  • @MisterMiyagi I'm not trying to close the channel, but I need the exception to be aware that the publication failed. – R01k Jun 17 '19 at 21:13
  • @R01k I am asking because close usually does an implicit flushing of outstanding messages. This is why ˋwithˋ is commonly used for buffered IO. If closing does not replicate the exception, you have shown that it is indeed broken. – MisterMiyagi Jun 18 '19 at 04:50
  • can you show the complete Code ? I use this and it does not throw an Exception for me. I'm wondering whether it is really an Issue. I dont think so,in the second approach you are using a Context manager so the channel will close after the Code execution but the first one is not, so you should close the channel manually after the publish Code execution. – basilisk Aug 20 '19 at 19:34
  • 1
    @basilisk Having to close the channel to know if the publication went to a valid exchange is impractical. Below I posted the the answer from the rabbitpy developer. – R01k Aug 22 '19 at 11:59
  • @R01k yeah that's right thnx – basilisk Aug 22 '19 at 12:39

0 Answers0