Python STOMP client library supporting versions 1.0, 1.1 and 1.2 of the protocol
Interactive and batch STOMP client providing comprehensive command-line access to all stomp.py functionality including message sending, subscription management, transaction handling, and broker connectivity testing.
Command-line STOMP client with interactive shell for real-time broker interaction.
def main():
"""
Launch interactive STOMP CLI client.
Usage:
python -m stomp [options]
Options:
--host HOST: broker hostname (default: localhost)
--port PORT: broker port (default: 61613)
--user USER: authentication username
--password PASS: authentication password
--ssl: enable SSL/TLS connection
--ssl-key-file FILE: SSL private key file
--ssl-cert-file FILE: SSL certificate file
--ssl-ca-certs FILE: SSL CA certificates file
--listen DEST: listen-only mode for destination
--file FILE: execute commands from file
--version: show version information
"""
class StompCLI(Cmd, ConnectionListener):
"""
Interactive STOMP command processor.
Provides command-line interface for STOMP operations
with connection management, message handling, and
transaction support.
"""Connection management and broker interaction commands.
def do_connect(self, args):
"""
Connect to STOMP broker.
Usage: connect [username] [password]
Parameters:
- username: str, authentication username (optional)
- password: str, authentication password (optional)
Examples:
connect
connect admin secret
connect user@domain.com mypassword
"""
def do_disconnect(self, args):
"""
Disconnect from STOMP broker.
Usage: disconnect [receipt-id]
Parameters:
- receipt-id: str, receipt ID for disconnect confirmation (optional)
"""
def do_stats(self, args):
"""
Display connection statistics.
Usage: stats
Shows:
- Connection count and status
- Messages sent/received counters
- Error count and heartbeat statistics
- Timing information
"""Message sending, receiving, and destination management.
def do_send(self, args):
"""
Send message to destination.
Usage: send <destination> <message>
Parameters:
- destination: str, target queue or topic (required)
- message: str, message body content (required)
Examples:
send /queue/test Hello World
send /topic/events {"type": "notification", "data": "value"}
"""
def do_sendrec(self, args):
"""
Send message and wait for receipt confirmation.
Usage: sendrec <destination> <message>
Parameters:
- destination: str, target queue or topic (required)
- message: str, message body content (required)
Waits for receipt confirmation before returning.
"""
def do_sendreply(self, args):
"""
Send message with reply-to header.
Usage: sendreply <destination> <reply-to> <message>
Parameters:
- destination: str, target queue or topic (required)
- reply-to: str, reply destination (required)
- message: str, message body content (required)
"""
def do_sendfile(self, args):
"""
Send file contents as message body.
Usage: sendfile <destination> <filename>
Parameters:
- destination: str, target queue or topic (required)
- filename: str, path to file to send (required)
Reads entire file content and sends as message body.
"""Queue and topic subscription with acknowledgment handling.
def do_subscribe(self, args):
"""
Subscribe to destination for message delivery.
Usage: subscribe <destination> [ack-mode] [subscription-id]
Parameters:
- destination: str, queue or topic to subscribe to (required)
- ack-mode: str, acknowledgment mode (auto|client|client-individual)
- subscription-id: str, unique subscription identifier
Examples:
subscribe /queue/orders
subscribe /topic/events auto sub-1
subscribe /queue/work client work-subscription
"""
def do_unsubscribe(self, args):
"""
Unsubscribe from destination.
Usage: unsubscribe <destination|subscription-id>
Parameters:
- destination: str, destination to unsubscribe from
- subscription-id: str, subscription ID to cancel
Examples:
unsubscribe /queue/orders
unsubscribe sub-1
"""
def do_ack(self, args):
"""
Acknowledge message processing.
Usage: ack <message-id> [subscription-id]
Parameters:
- message-id: str, ID of message to acknowledge (required)
- subscription-id: str, subscription identifier (optional)
Used with 'client' and 'client-individual' ack modes.
"""
def do_nack(self, args):
"""
Negative acknowledge message (STOMP 1.1+).
Usage: nack <message-id> [subscription-id]
Parameters:
- message-id: str, ID of message to nack (required)
- subscription-id: str, subscription identifier (optional)
Signals processing failure, may trigger redelivery.
"""Atomic transaction management for grouped operations.
def do_begin(self, args):
"""
Begin transaction.
Usage: begin [transaction-id]
Parameters:
- transaction-id: str, unique transaction identifier (optional)
If no transaction-id provided, generates unique ID.
"""
def do_commit(self, args):
"""
Commit transaction.
Usage: commit [transaction-id]
Parameters:
- transaction-id: str, transaction to commit (optional)
Commits current transaction if no ID specified.
"""
def do_abort(self, args):
"""
Abort transaction.
Usage: abort [transaction-id]
Parameters:
- transaction-id: str, transaction to abort (optional)
Aborts current transaction if no ID specified.
"""Debugging, information, and control commands.
def do_run(self, args):
"""
Execute commands from file.
Usage: run <filename>
Parameters:
- filename: str, path to command file (required)
Executes each line as CLI command.
Command file format: one command per line.
"""
def do_version(self, args):
"""
Display version information.
Usage: version
Shows stomp.py library version and build information.
"""
def do_quit(self, args):
"""
Exit CLI client.
Usage: quit
Cleanly disconnects and exits interactive session.
"""# Start interactive client
python -m stomp --host broker.example.com --port 61613
# Inside interactive session:
(Cmd) connect admin password
(Cmd) subscribe /queue/orders auto
(Cmd) send /queue/orders {"order_id": 12345, "item": "widget"}
(Cmd) stats
(Cmd) disconnect
(Cmd) quit# Connect with SSL/TLS
python -m stomp \
--host secure-broker.com \
--port 61614 \
--ssl \
--ssl-key-file /path/to/client.key \
--ssl-cert-file /path/to/client.crt \
--ssl-ca-certs /path/to/ca.crt \
--user client_user \
--password client_pass# Listen to destination without interaction
python -m stomp \
--host broker.com \
--port 61613 \
--user monitor \
--password secret \
--listen /topic/events# Execute commands from file
python -m stomp \
--host broker.com \
--port 61613 \
--user automation \
--password script_pass \
--file /path/to/commands.txtExample commands.txt:
connect
subscribe /queue/batch-work client work-sub
send /queue/notifications Batch job started
begin batch-tx-001
send /queue/process-items Process item A
send /queue/process-items Process item B
commit batch-tx-001
unsubscribe work-sub
disconnect# Basic authentication
python -m stomp --host broker.com --user myuser --password mypass
# Domain authentication
python -m stomp --host broker.com --user user@domain.com --password pass
# Empty credentials (guest access)
python -m stomp --host broker.com --user "" --password ""# Custom heartbeats and timeouts
python -m stomp \
--host broker.com \
--port 61613 \
--heartbeats 10000,10000 \
--timeout 30.0 \
--user client \
--password secret#!/bin/bash
# Send notification via STOMP
echo "send /queue/alerts System maintenance starting" | \
python -m stomp \
--host monitoring.com \
--port 61613 \
--user alerting \
--password $ALERT_PASSWORD \
--file -#!/bin/bash
# Monitor queue activity
python -m stomp \
--host broker.com \
--port 61613 \
--user monitor \
--password $MONITOR_PASS \
--listen /queue/system-events > events.log &
STOMP_PID=$!
sleep 3600 # Monitor for 1 hour
kill $STOMP_PIDconfig.txt:
# Connection setup
connect admin secretpassword
# Setup subscriptions
subscribe /queue/orders client order-processor
subscribe /topic/events auto event-monitor
# Send startup notification
send /topic/system {"service": "processor", "status": "started"}
# Keep connection alive (comment to auto-exit)
# quitpython -m stomp --host broker.com --file config.txtInstall with Tessl CLI
npx tessl i tessl/pypi-stomp-py