Skip to main content

A Python package for RabbitMQ interactions

Project description

# my_rabbitmq_package

A Python package for RabbitMQ interactions.

## Installation

You can install the package using pip:

```bash
pip install my-rabbitmq-package==0.1.2

Publisher Usage

from my_rabbitmq_package.publisher import RabbitMQPublisher

# Initialize the publisher
rabbitmq_publisher = RabbitMQPublisher(host='localhost', port=5672, username='guest', password='guest')

# Declare the queue
rabbitmq_publisher.declare_queue('hello')

# Publish a message
message = "Hello, RabbitMQ!"
rabbitmq_publisher.publish_message(message, 'hello')

# Close the connection
rabbitmq_publisher.close_connection()

Consumer Usage

from my_rabbitmq_package.consumer import RabbitMQConsumer
import threading

# Initialize the consumer
rabbitmq_consumer = RabbitMQConsumer(host='localhost', port=5672, username='guest', password='guest')

# Declare the queue
rabbitmq_consumer.declare_queue('hello')

# Define event handler functions
@rabbitmq_consumer.event_manager.on(event="message_received")
def handle_message_received(data: bytes):
    print(" [*] Event handler 'handle_message_received' triggered")
    print(f"Processing message: {data.decode()}")

@rabbitmq_consumer.event_manager.on(event="stop_consumer")
def handle_stop_consumer():
    print(" [*] Event handler 'handle_stop_consumer' triggered")
    rabbitmq_consumer.stop()

# Start consuming messages in a separate thread
consume_thread = threading.Thread(target=rabbitmq_consumer.consume_messages, args=('hello',))
consume_thread.start()
consume_thread.join()

# Close the connection
rabbitmq_consumer.close_connection()

Running Tests

You can run the tests using pytest. First, make sure you have pytest installed:

pip install pytest

Then, run the tests:

pytest tests/

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

my_rabbitmq_package-0.1.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

my_rabbitmq_package-0.1.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file my_rabbitmq_package-0.1.2.tar.gz.

File metadata

  • Download URL: my_rabbitmq_package-0.1.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.0

File hashes

Hashes for my_rabbitmq_package-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9e57eb4e4bc399e0dcf043937d0b767ef191f09edf0493231a853046e155ed86
MD5 be668c60054f8be0000e99ee57e01336
BLAKE2b-256 93fbaa9572a9b561634db6fcc2d45d0be73b2c9839e0ab16b61a029a34d1966e

See more details on using hashes here.

File details

Details for the file my_rabbitmq_package-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for my_rabbitmq_package-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 24260f155d60ddf69ccf0e4eee17b035c5dc008127f50b12dfae80b1da644d2d
MD5 68769aa088f3d8ceb465344a3be7545d
BLAKE2b-256 f6e814dafea29f4b4974299cb2196d82f8486f7541a1f4b63bed1d28350ad4f0

See more details on using hashes here.

Supported by

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