blacked
This commit is contained in:
parent
fce35894b4
commit
f2c1ee5a95
@ -14,7 +14,9 @@ def callback(ch, method, properties, body):
|
||||
|
||||
def init_params():
|
||||
credentials = pika.PlainCredentials(CONFIG.rabbitmq.user, CONFIG.rabbitmq.password)
|
||||
parameters = pika.ConnectionParameters(host=CONFIG.rabbitmq.host, port=CONFIG.rabbitmq.port, heartbeat=CONFIG.rabbitmq.heartbeat, credentials=credentials)
|
||||
parameters = pika.ConnectionParameters(
|
||||
host=CONFIG.rabbitmq.host, port=CONFIG.rabbitmq.port, heartbeat=CONFIG.rabbitmq.heartbeat, credentials=credentials
|
||||
)
|
||||
return parameters
|
||||
|
||||
|
||||
@ -24,10 +26,8 @@ def consume(parameters, queue):
|
||||
channel = connection.channel()
|
||||
while True:
|
||||
try:
|
||||
channel.basic_consume(queue=queue,
|
||||
auto_ack=True,
|
||||
on_message_callback=callback)
|
||||
print(' [*] Waiting for messages. To exit press CTRL+C')
|
||||
channel.basic_consume(queue=queue, auto_ack=True, on_message_callback=callback)
|
||||
print(" [*] Waiting for messages. To exit press CTRL+C")
|
||||
|
||||
channel.start_consuming()
|
||||
except pika.exceptions.ConnectionClosedByBroker:
|
||||
@ -36,7 +36,3 @@ def consume(parameters, queue):
|
||||
pass
|
||||
except pika.exceptions.AMQPConnectionError:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -7,8 +7,6 @@ def produce_response(parameters, queue, body):
|
||||
connection = pika.BlockingConnection(parameters)
|
||||
channel = connection.channel()
|
||||
channel.queue_declare(queue=queue, durable=True)
|
||||
channel.basic_publish("",
|
||||
queue,
|
||||
body)
|
||||
channel.basic_publish("", queue, body)
|
||||
print(f" [x] Sent {body} on {queue}")
|
||||
connection.close()
|
||||
connection.close()
|
||||
|
||||
@ -4,11 +4,12 @@ from mini_queue.producer import produce_response
|
||||
from mini_queue.utils.config import CONFIG
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
credentials = pika.PlainCredentials(CONFIG.rabbitmq.user, CONFIG.rabbitmq.password)
|
||||
queue = CONFIG.rabbitmq.queues.input
|
||||
parameters = pika.ConnectionParameters(host=CONFIG.rabbitmq.host, port=CONFIG.rabbitmq.port, heartbeat=CONFIG.rabbitmq.heartbeat, credentials=credentials)
|
||||
parameters = pika.ConnectionParameters(
|
||||
host=CONFIG.rabbitmq.host, port=CONFIG.rabbitmq.port, heartbeat=CONFIG.rabbitmq.heartbeat, credentials=credentials
|
||||
)
|
||||
body = "Pika pika!"
|
||||
produce_response(parameters, queue, body)
|
||||
produce_response(parameters, queue, body)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user