The interface uses two queue listener information and has two test environments, so you need to send test data to MQ:
Python uses the Pika package: Pika is a RabbitMQ (amqp-0-9-1) the client library for Python.
can refer to: Https://github.com/pika/pika
= Connection.channel () channel.basic_publish (exchange=' Examplerouting_key=' Test Body=' Test Message') connection.close ()
Encapsulates the sending message into a function: stream.py
The specific code is as follows:
Import Pika
Import JSON
From config import env
def send_msg (Msg_exchange, Msg_key, MSG, msg_type=none):
If str (env.__name__) = = ' Beta ':
If Msg_type is None:
Connection = Pika. Blockingconnection (Pika. Urlparameters(
' Amqp://talaris:[email Protected]:5672/talaris '))
Else
Connection = Pika. Blockingconnection (Pika. Urlparameters (
' Amqp://talaris:[email Protected]:5672/clair '))
Elif str (env.__name__) = = ' Alpha ':
If Msg_type is None:
Connection = Pika. Blockingconnection (Pika. Urlparameters (
' Amqp://talaris:[email Protected]:5672/talaris '))
Else
Connection = Pika. Blockingconnection (Pika. Urlparameters (
' Amqp://talaris:[email Protected]:5672/clair '))
Channel = Connection.channel ()
Channel.basic_publish (Exchange=msg_exchange,
Routing_key=msg_key,
Body=json.dumps (msg))
Print ("[x] Sent%r:%r"% (Msg_key, msg))
Connection.close ()
PS: I use the pika. Urlparameters, you can also use Pika. Connectionparameters (host=' localhost'), refer to GitHub for details
RABBITMQ Send Message +python