Skip to main content

High-level IBM MQ consumer and producer library for Python

Project description

stream-pymqi

High-level IBM MQ consumer and producer library for Python

Features

  • Simple consumer/producer API for IBM MQ
  • Automatic connection management and reconnection
  • Stream-style message processing (async/await ready)
  • Configuration via Python dict or YAML files
  • Thread-safe operations
  • Error handling and retry mechanisms
  • Compatible with Python 3.8+

Installation

pip install stream-pymqi

Usage

Consumer

from stream_pymqi import Consumer, StreamConfig

config = StreamConfig(
    host='localhost',
    port=1414,
    channel='CHANNEL1',
    queue_manager='QM1',
    queue_name='QUEUE1'
)

consumer = Consumer(config)

@consumer.on_message()
def handle_message(message):
    print(f"Received: {message}")

consumer.start()

Producer

from stream_pymqi import Producer, StreamConfig, Message

config = StreamConfig(
    host='localhost',
    port=1414,
    channel='CHANNEL1',
    queue_manager='QM1',
    queue_name='QUEUE1'
)

producer = Producer(config)

# Send a message
producer.send(Message(data=b"Hello, IBM MQ!"))

# Or send a string directly
producer.send_string("Hello, IBM MQ!")

producer.disconnect()

Configuration via YAML

from stream_pymqi import Consumer, StreamConfig

config = StreamConfig.from_yaml('config.yaml')
consumer = Consumer(config)
consumer.start()

Example config.yaml:

host: localhost
port: 1414
channel: CHANNEL1
queue_manager: QM1
queue_name: QUEUE1
ssl: false
auto_reconnect: true

With SSL

from stream_pymqi import Consumer, StreamConfig

config = StreamConfig(
    host='localhost',
    port=1414,
    channel='CHANNEL1',
    queue_manager='QM1',
    queue_name='QUEUE1',
    ssl=True,
    ssl_cipher_spec='TLS_RSA_WITH_AES_128_CBC_SHA'
)

consumer = Consumer(config)
consumer.start()

Error Handling

from stream_pymqi import Consumer, StreamConfig

def on_error(exception):
    print(f"Error: {exception}")

config = StreamConfig(
    host='localhost',
    port=1414,
    channel='CHANNEL1',
    queue_manager='QM1',
    queue_name='QUEUE1',
    on_error=on_error
)

consumer = Consumer(config)
consumer.start()

API Reference

StreamConfig

Configuration class for IBM MQ connection.

Parameters:

  • host: IBM MQ host address
  • port: IBM MQ port (default: 1414)
  • channel: IBM MQ channel name
  • queue_manager: IBM MQ queue manager name
  • queue_name: IBM MQ queue name
  • user: IBM MQ user (optional)
  • password: IBM MQ password (optional)
  • connect_retries: Number of connection retries (default: 3)
  • connect_retry_interval: Interval between retries in seconds (default: 5)
  • message_wait_interval: Wait interval for message consumption in seconds (default: 5)
  • auto_reconnect: Enable automatic reconnection (default: True)
  • max_message_size: Maximum message size in bytes (default: 1048576)
  • ssl: Enable SSL connection (default: False)
  • ssl_cipher_spec: SSL cipher specification (optional)
  • cert_store_location: Certificate store location (optional)

Consumer

IBM MQ consumer with automatic connection management.

Methods:

  • on_message(): Decorator to register a message handler
  • register_handler(handler): Register a message handler
  • start(): Start consuming messages in a background thread
  • stop(): Stop consuming messages
  • is_running(): Check if consumer is running

Producer

IBM MQ producer with automatic connection management.

Methods:

  • connect(): Establish connection to IBM MQ
  • disconnect(): Disconnect from IBM MQ
  • send(message): Send a message to the queue
  • send_string(text): Send a string message
  • send_bytes(data): Send a bytes message
  • is_connected(): Check if connected to IBM MQ

License

Apache-2.0

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

stream_pymqi-0.1.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

stream_pymqi-0.1.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file stream_pymqi-0.1.0.tar.gz.

File metadata

  • Download URL: stream_pymqi-0.1.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.12.3 Linux/6.17.0-1015-azure

File hashes

Hashes for stream_pymqi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4cc526a151bcc0e6c0ab2b824ace227be80bc9f924b15c1be592dcce43577f08
MD5 34e331f2ee395579d2e0bac4bc43e33f
BLAKE2b-256 06f64d096ca0277266b09a484a0d7c8f4753f5b838e7d4961a8211b18da0f787

See more details on using hashes here.

File details

Details for the file stream_pymqi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: stream_pymqi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.12.3 Linux/6.17.0-1015-azure

File hashes

Hashes for stream_pymqi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 682a8624ba17d0ba04f6a60ecf99c5e45b590bbe3873f832d075ac2876324590
MD5 77d5be48c515797bcc6f4b8630fd8320
BLAKE2b-256 2a696956023c09c1999f9a809c34d093371c97e75f2922e0a2f9af81b40cc790

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