Skip to main content

pika-based RabbitMQ connector with built in JSON serialization/deserialization

Project description

rabbitqm-alphamoon

image image

pika-based RabbitMQ connector with built in JSON serialization/deserialization


Features

  • publishing: publish(message)
  • getting number of messages in the queue: message_count
  • consuming (forever, i.e. with a callback function): consume_forever(callback_fun)
  • setting up a dead letter exchange (number of retries passed to the consumer in the info argument)

See code examples in the "Examples" section.

Requirements

pika==1.2.0

Installation

You can install "rabbitmq-alphamoon" via pip from PyPI:

$ pip install rabbitmq-alphamoon

Examples

Initialization

import pika
from rabbitmq_alphamoon import RabbitMQConnector

parameters = pika.ConnectionParameters(
    host=rabbitmq_host,
    port=rabbitmq_port,
    credentials=pika.PlainCredentials(
        username=rabbitmq_username,
        password=rabbitmq_password,
    ),
)

queue = RabbitMQConnector(
    connection_parameters=parameters,
    queue=queue_name,
)

Publishing

message = {'foo': 'bar'}

with queue.open_connection():
    queue.publish(message)

Getting a number of the messages in the queue

message_count = queue.message_count

Consuming

def process_message(message, info):
    print(message)
    print(info)

with queue.open_connection():
    queue.consume_forever(process_message_callback=process_message)

Short form for one-time usage of connector

If you do not need to reuse the connector, you can initialize and open connection without assignment of connector to a variable before calling open_connection context manager. This may come in handy especially in case of consuming, where connector is usually used only to call consume_forever function.

with RabbitMQConnector(
    connection_parameters=parameters,
    queue=queue_name,
).open_connection() as queue:
   queue.consume_forever(process_message_callback=process_message)

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the MIT license, "rabbitmq-alphamoon" is free and open source software

Issues

If you encounter any problems, please email us at dev@alphamoon.ai, along with a detailed description.

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

rabbitmq-alphamoon-0.7.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

rabbitmq_alphamoon-0.7.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file rabbitmq-alphamoon-0.7.0.tar.gz.

File metadata

  • Download URL: rabbitmq-alphamoon-0.7.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.10

File hashes

Hashes for rabbitmq-alphamoon-0.7.0.tar.gz
Algorithm Hash digest
SHA256 8a31e93599876b6d861aba8c8c46a2435e638c17b3894682d4e4e91603af422b
MD5 03e0b4bd4fbf65bc5d86259aadc9371b
BLAKE2b-256 6589a0c79a74af0a68fe13021515efd0d91dfc209569b14b96d69c2aed464e03

See more details on using hashes here.

File details

Details for the file rabbitmq_alphamoon-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: rabbitmq_alphamoon-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.10

File hashes

Hashes for rabbitmq_alphamoon-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 93eda03558ebac1967b74fc9e6bec16616b8a90a3165db6344db635cd6fa5fa0
MD5 d0b0802eae9cdd590a36b319abeb49f0
BLAKE2b-256 28fbd1165f9a199e1131cc15b3d038093c0afff9954b5f2a732e6b930f0c2530

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