ActiveMQ Client
View SourceActiveMQ client library for Artemis ActiveMQ using STOMP protocol connection.
This library provides a high-level interface for connecting to and interacting with Apache ActiveMQ Artemis using the STOMP protocol. It handles message publishing, consuming, subscription management, and job scheduling/cancellation.
Features
- STOMP-based connection to Artemis ActiveMQ
- Message publishing and consuming with automatic reconnection
- Topic and queue subscription management with selectors
- Job scheduling and cancellation with reply handling
- Callback-based message processing for flexible integration
- Automatic error handling and connection recovery
Installation
Add activemq_client
to your list of dependencies in mix.exs
:
def deps do
[
{:activemq_client, "~> 0.1.0"}
]
end
Quick Start
# Start the client
{:ok, _} = ActiveMQClient.start_link([
host: "localhost",
port: 61613,
username: "artemis",
password: "artemis"
])
# Publish a message
ActiveMQClient.publish_message("Hello World!", "/queue/test")
# Subscribe to a queue
ActiveMQClient.subscribe_to_queue("/queue/test")
# Start listening for job commands
ActiveMQClient.start_listening()
Configuration
The client can be configured with the following options:
:host
- ActiveMQ server hostname (default: "localhost"):port
- ActiveMQ STOMP port (default: 61613):username
- Authentication username (default: "artemis"):password
- Authentication password (default: "artemis"):queue
- Default queue destination (default: "/queue/artemis_queue"):topic
- Default topic destination (default: "/topic/artemis_topic"):message_handler
- Custom message handler function
Job Handling
The library supports job scheduling and cancellation through STOMP message selectors:
# Start listening for SCHEDULE_JOB_COMMAND and CANCEL_JOB_COMMAND messages
ActiveMQClient.start_listening()
Job commands are automatically processed and integrated with the timer system's database and scheduler.
Dependencies
This library depends only on:
stomp_client
- Custom STOMP protocol implementationjason
- JSON encoding/decoding
Documentation
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/activemq_client.
License
MIT License