Package: greendeck-rabbitmq
GD-rabbitMQRight now this package is only forgreendeck'sinternal use. This will help to publish and consume messages with your rabbitMQInstall from piphttps://pypi.org/project/greendeck-rabbitmq/pip install greendeck-rabbitmqRead details about all default parameters and core functions here in RabbitMQ official website. (https://www.rabbitmq.com)How to use ?import the libraryimportgreendeck_rabbitmqimportRabbitMQclassfromgreendeck_rabbitmqimportRabbitMQinitializeRabbitMQclient connectionHere default values of some arguments areRMQ_PORT=5672RMQ_VHOST='/'username=Nullpassword=Nullfromgreendeck_rabbitmqimportRabbitMQ# declare variablesRMQ_HOST=<YOUR_RMQ_HOST># RabbitMQ host addressRMQ_PORT=<YOUR_RMQ_PORT># RabbitMQ portRMQ_VHOST=<YOUR_RMQ_VHOST># RabbitMQ virtual hostusername=<YOUR_USERNAME># RabbitMQ usernamepassword=<YOUR_PASSWORD># RabbitMQ password```HeredefaultvaluesareRMQ_PORT=5672,RMQ_VHOST='/',username=Null,password=Null```rabbitmq_client=RabbitMQ(RMQ_HOST,RMQ_PORT,RMQ_VHOST=RMQ_VHOST,username=username,password=password)closeRabbitMQclient connectionrabbitmq_client.rabbitmq_close_connection()check size of a rabbitmq queuequeue="test_library"print(rabbitmq_client.size(queue))check if a size of queue is empty or notqueue="test_library"print(rabbitmq_client.is_empty(queue))consume all messages of a queuequeue="test_library"rabbitmq_client.rabbitmq_get_all(queue)single message producerHere default parameters and their values are:exchange=""delivery_mode=2mode="single"message="hello world"queue="test_library"routing_key="test_library"exchange=''delivery_mode=2mode="single"```Theroutingkeyisamessageattribute.Theexchangemightlookatthiskeywhendecidinghowtoroutethemessagetoqueues(dependingonexchangetype).``````deliverymode=1meansnonpersistent,anddeliverymode=2meanspersistent``````availablemodesare'single'&'multi'andin'multi'modeitexpectsmessageaslistofmessagesrabbitmq_client.rabbitmq_publisher(message,queue,routing_key,exchange=exchange,delivery_mode=delivery_mode,mode=mode)rabbitmq_client.rabbitmq_close_connection()multi messages producerHere default parameters and their values are:exchange=""delivery_mode=2mode="single"message=["hello world"]*100#list of messagesqueue="test_library"routing_key="test_library"exchange=''delivery_mode=2mode="multi"rabbitmq_client.rabbitmq_publisher(message,queue,routing_key,exchange=exchange,delivery_mode=delivery_mode,mode=mode)rabbitmq_client.rabbitmq_close_connection()messages consumerHere default parameters and their values are:size=1queue="test_library"size=1# mention number of required messagesresults=rabbitmq_client.rabbitmq_consumer(queue,size)print("number of messages",len(results))rabbitmq_consumer.rabbitmq_close_connection()create an exchangeThis will create an exchange and bind the list of queues to the same exchange.
Default arguments and their values are:exchange_type = "fanout"routing_key = ""exchange="test_exchange"queues=["queue1","queue2","queue3"]exchange_type="fanout"# for now exchange_type only supports 'fanout'routing_key=""# make sure to keep this one same in your project for easy use```Heredefaultargumentsareexchange_type="fanout",routing_key=""```rabbitmq_client.make_rabbitmq_exchange(exchange,queues,exchange_type=exchange_type,routing_key=routing_key)produce single message to an exchangeProduce a single message to an exchangeDefault arguments and their values are:exchange_type = "fanout"routing_key = ""mode = "single"exchange="test_exchange"message="hello"exchange_type="fanout"routing_key=""mode="single"```Hereavilablemodesaresingleormulti.Whenitisinmultimodeitexpectstypeofmessagefieldaslist```rabbitmq_client.rabbitmq_exchange_publisher(exchange,message,exchange_type=exchange_type,routing_key=routing_key,mode=mode)produce single message to an exchangeProduce a single message to an exchangeDefault arguments and their values are:exchange_type = "fanout"routing_key = ""mode = "single"exchange="test_exchange"message=["hello1","hello2","hello3"]exchange_type="fanout"routing_key=""mode="multi"```Hereavilablemodesaresingleormulti.Whenitisinsinglemodeitexpectstypeofmessagefieldasastring```rabbitmq_client.rabbitmq_exchange_publisher(exchange,message,exchange_type=exchange_type,routing_key=routing_key,mode=mode)How to build your pip packageopen an account herehttps://pypi.org/In the parent directorypython setup.py sdist bdist_wheeltwine upload dist/*Update your packagepython setup.py sdisttwine upload dist/*referenceshttps://medium.com/small-things-about-python/lets-talk-about-python-packaging-6d84b81f1bb5https://packaging.python.org/tutorials/packaging-projects/RabbitMQThank You