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",
    )
    # 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.2.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: AmosMsg-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 f7c30f94aa709842de559a7aafef0464dc6d157f8c8013d59ba7376ec620c7b3
MD5 688094b6e90ae6a14661a30dd6aa784e
BLAKE2b-256 b6c49aa2b357524e774590e61d6c57a6cbb95b512b7d222edd082d13aaf90b10

See more details on using hashes here.

File details

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

File metadata

  • Download URL: AmosMsg-0.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 add662e4b52f62ed5e0b75e5766b3598d08388d595415ad5fedd065c8553795e
MD5 b28702b89404df00496aaf1ce56ac87a
BLAKE2b-256 2f9949ea2e5ede8313bc081f6534b0d18aa10136696c0012e57fb49b0b1d33b9

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