diff --git a/cnn_classification_service/main.py b/cnn_classification_service/main.py index 17c3490..5dd700d 100644 --- a/cnn_classification_service/main.py +++ b/cnn_classification_service/main.py @@ -27,6 +27,7 @@ def message_callback(channel, method, properties, body): routing_key='classification-result', body=json.dumps(results).encode("utf-8") ) + channel.basic_ack(delivery_tag = method.delivery_tag) def main(): @@ -57,12 +58,14 @@ def main(): channel = connection.channel() channel.exchange_declare(exchange=os.environ['PIKA_INPUT_EXCHANGE'], exchange_type='direct') - queue_declare_result = channel.queue_declare(queue='', exclusive=True) + queue_declare_result = channel.queue_declare(queue='cnnqueue', exclusive=True) queue_name = queue_declare_result.method.queue channel.queue_bind(exchange=os.environ['PIKA_INPUT_EXCHANGE'],routing_key='feature', queue=queue_name) - channel.basic_consume(queue=queue_name, on_message_callback=message_callback, auto_ack=True) + channel.basic_qos(prefetch_count=1) + + channel.basic_consume(queue=queue_name, on_message_callback=message_callback, auto_ack=False) logging.info("Connection complete! Listening to messages...") try: