We will use the same credentials that we created during the installation of rabbimq-server. * credentials- In this we will define the username and password which is known by the rabbitmq-server(refer installation segment above) * host- by default we use ‘localhost’ or 0.0.0.0 as the listening server, but it can have any other IP addresses on cloud that has rabbitmq-server listening * port- this is by default 5672, but it should point to the port where our server is listening * exchange- this can be assumed as a bridge name which needed to be declared so that queues can be accessed * routing_key- this is a binding key corresponding to that key, we can set it to be any name * basic_publish- this is the method which we call to send the message to the corresponding queue #producer import pika #declaring the credentials needed for connection like host, port, username, password, exchange etc credentials = pika.PlainCredentials(‘tester’,’secretPass’) connection= pika.BlockingConnection(pika.ConnectionParameters(host=’localhost’, credentials= credentials)) channel= connection.channel() channel.exchange_declare(‘test’, durable=True, exchange_type=’topic’) channel.queue_declare(queue= ‘A’) channel.queue_bind(exchange=’test’, queue=’A’, routing_key=’A’) channel.queue_declare(queue= ‘B’) channel.queue_bind(exchange=’test’, queue=’B’, routing_key=’B’) channel.queue_declare(queue= ‘C’) channel.queue_bind(exchange=’test’, queue=’C’, routing_key=’C’) #messaging to queue named C message= ‘hello consumer!!!!!’ channel.basic_publish(exchange=’test’, routing_key=’C’, body= message) channel.close() So there are two sides of This design, One is Producer and other is Consumer we will see both ends and write a python script for that. Simple Pictorial representation of an exampleĪs described in this diagram we have producer and consumer of messages. You’re all set for accessing and managing rabbitmq from python And you are now all set for accessing it using an AMQP rabbitmq client called pika in python. Sudo rabbitmqctl set_permissions -p / user "." "." "." #user is the username and password is the new password sudo rabbitmqctl add_user user password #giving that user adiministraitve rights sudo rabbitmqctl set_user_tags user administrator create an username and password to login to rabbitmq management. * Install erlang * Install rabbitmq-server * Enable rabbitmq-server as system program * Start rabbitmq-server at backend * Enable rabbitmq management plugin sudo apt-get update & sudo apt-get upgrade sudo apt-get install erlang sudo apt-get install rabbitmq-server sudo systemctl enable rabbitmq-server sudo systemctl start rabbitmq-server sudo rabbitmq-plugins enable rabbitmq_management But first we need to install “rabbitmq-server” which will run as a system program at backend. To access RabbitMQ in python or what we call it as “ a pure-Python AMQP 0–9–1 client for rabbitMQ”, there is a package(library) called pika which can be installed using pip.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |