BlockingChannel.basic_nack single message
(self)
| 1211 | class TestBasicNack(BlockingTestCaseBase): |
| 1212 | |
| 1213 | def test(self): |
| 1214 | """BlockingChannel.basic_nack single message""" |
| 1215 | connection = self._connect() |
| 1216 | |
| 1217 | ch = connection.channel() |
| 1218 | |
| 1219 | q_name = 'TestBasicNack_q' + uuid.uuid1().hex |
| 1220 | |
| 1221 | # Place channel in publisher-acknowledgments mode so that the message |
| 1222 | # may be delivered synchronously to the queue by publishing it with |
| 1223 | # mandatory=True |
| 1224 | ch.confirm_delivery() |
| 1225 | |
| 1226 | # Declare a new queue |
| 1227 | ch.queue_declare(q_name, exclusive=True) |
| 1228 | |
| 1229 | # Deposit two messages in the queue via default exchange |
| 1230 | ch.basic_publish(exchange='', |
| 1231 | routing_key=q_name, |
| 1232 | body='TestBasicNack1', |
| 1233 | mandatory=True) |
| 1234 | ch.basic_publish(exchange='', |
| 1235 | routing_key=q_name, |
| 1236 | body='TestBasicNack2', |
| 1237 | mandatory=True) |
| 1238 | |
| 1239 | # Get the messages |
| 1240 | (rx_method, _, rx_body) = ch.basic_get(q_name, auto_ack=False) |
| 1241 | self.assertEqual(rx_body, as_bytes('TestBasicNack1')) |
| 1242 | |
| 1243 | (rx_method, _, rx_body) = ch.basic_get(q_name, auto_ack=False) |
| 1244 | self.assertEqual(rx_body, as_bytes('TestBasicNack2')) |
| 1245 | |
| 1246 | # Nack the second message |
| 1247 | ch.basic_nack(rx_method.delivery_tag, multiple=False, requeue=True) |
| 1248 | |
| 1249 | # Verify that exactly one message is present in the queue, namely the |
| 1250 | # second one |
| 1251 | self._assert_exact_message_count_with_retries(channel=ch, |
| 1252 | queue=q_name, |
| 1253 | expected_count=1) |
| 1254 | (rx_method, _, rx_body) = ch.basic_get(q_name, auto_ack=False) |
| 1255 | self.assertEqual(rx_body, as_bytes('TestBasicNack2')) |
| 1256 | |
| 1257 | |
| 1258 | class TestBasicNackNoRequeue(BlockingTestCaseBase): |
nothing calls this directly
no test coverage detected