Skip to main content

MQ Consumer

Project description

Amos

AmosMsg is a MQ consumer

1. MQ Consumer

your code

import json
from AmosMsg.AmosMsg import AmosMsg


def call_back(ch, method, properties, body):
    message = json.loads(body.decode())
    print(message)
    ch.basic_ack(delivery_tag=method.delivery_tag)
    print("%r" % body)


if __name__ == '__main__':
    amos = AmosMsg(
        msg_user='consumer_user', 
        msg_pass='consumer_password', 
        enable_ssl=False, # disable SSL
        host="your.rabbitmq.host", 
        port=5672,  # MQ default port is 5672
        v_host="your_virtual_host",
        exchange="your_exchange", 
        queue="your_queue",
    )
    amos.create_channel()
    amos.create_queue()
    amos.connect_exchange()
    amos.run_consumer(call_back)

2. Use SSL

your code

import json
from AmosMsg.AmosMsg import AmosMsg


def call_back(ch, method, properties, body):
    message = json.loads(body.decode())
    print(message)
    ch.basic_ack(delivery_tag=method.delivery_tag)
    print("%r" % body)


if __name__ == '__main__':
    amos = AmosMsg(
        msg_user='consumer_user', 
        msg_pass='consumer_password', 
        enable_ssl=True, # enable SSL
        host="your.rabbitmq.host", 
        port=5671,  # MQ SSL default port is 5671
        v_host="your_virtual_host",
        exchange="your_exchange", 
        queue="your_queue",
        ca="your/path/to/ca",
        crt="your/path/to/crt", 
        key="your/path/to//key"
    )
    amos.create_channel()
    amos.create_queue()
    amos.connect_exchange()
    amos.run_consumer(call_back)

3. Use config file

your code

import json
from AmosMsg.AmosMsg import AmosMsg


def call_back(ch, method, properties, body):
    message = json.loads(body.decode())
    print(message)
    ch.basic_ack(delivery_tag=method.delivery_tag)
    print("%r" % body)


if __name__ == '__main__':
    amos = AmosMsg(
        msg_user='consumer_user', 
        msg_pass='consumer_password', 
        config_path="path/to/your/config.yaml",
        enable_ssl=False, # disable SSL
    )
    amos.create_channel()
    amos.create_queue()
    amos.connect_exchange()
    amos.run_consumer(call_back)

config.yaml

host: "your.rabbitmq.host"
port: 5672 # Non-SSL default port is 5672
virtual_host: "your_virtual_host"
exchange: "your_exchange"
queue: "your_queue"

4. Use config file with SSL

your code

import json
from AmosMsg.AmosMsg import AmosMsg


def call_back(ch, method, properties, body):
    message = json.loads(body.decode())
    print(message)
    ch.basic_ack(delivery_tag=method.delivery_tag)
    print("%r" % body)


if __name__ == '__main__':
    amos = AmosMsg(
        msg_user='consumer_user', 
        msg_pass='consumer_password', 
        config_path="path/to/your/config.yaml",
        enable_ssl=True, # enable SSL
    )
    amos.create_channel()
    amos.create_queue()
    amos.connect_exchange()
    amos.run_consumer(call_back)

config.yaml

host: "your.rabbitmq.host"
port: 5671 # SSL default port is 5672
virtual_host: "your_virtual_host"
exchange: "your_exchange"
queue: "your_queue"
ca: "your/path/to/ca"
crt: "your/path/to/crt"
key: "your/path/to/key"

5. Send your message to MQ

your code v1

import json
from AmosMsg.AmosMsg import AmosMsg

if __name__ == '__main__':
    amos = AmosMsg(
        msg_user='consumer_user', 
        msg_pass='consumer_password', 
        enable_ssl=False,               
        host="your.rabbitmq.host", 
        port=5672,
        v_host="your_virtual_host",
        exchange="your_exchange",  # could be empty follow v2
        queue="your_queue",        # could be empty
    )
    amos.create_channel()
    amos.send_msg("""{"abc":"123"}""")

your code v2

import json
from AmosMsg.AmosMsg import AmosMsg

if __name__ == '__main__':
    amos = AmosMsg(
        msg_user='consumer_user', 
        msg_pass='consumer_password', 
        enable_ssl=False,               
        host="your.rabbitmq.host", 
        port=5672,
        v_host="your_virtual_host",
    )
    amos.create_channel()
    # The value of exchange and queue could be empty 
    # Please use below method to config exchangeß
    amos.send_conf(exchange='your_exchange')
    amos.send_msg("""{"abc":"123"}""")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

AmosMsg-0.0.3.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

AmosMsg-0.0.3-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file AmosMsg-0.0.3.tar.gz.

File metadata

  • Download URL: AmosMsg-0.0.3.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for AmosMsg-0.0.3.tar.gz
Algorithm Hash digest
SHA256 4666010b85f74fc17e9cbc2178f85091411d5a1f2e42160b8a550fc1e187f587
MD5 21c33edb3697bf8dc584aa8298549ee1
BLAKE2b-256 a44a0432b8442b87d504e49fa3952d34436e80f95e3a26c6951d906ec9cdee2c

See more details on using hashes here.

File details

Details for the file AmosMsg-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: AmosMsg-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for AmosMsg-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 306da89c00d00323c82791eed159bf078ddcd741be59c4b3cce619af8c6c13a3
MD5 b09c33da5dfbc6c1ad50769a21f88739
BLAKE2b-256 78e1dca7601ab9f951f41a59f204333032df856f20c464e713132db6fd0dd1e5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page