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