ActiveMQClient (activemq_client v0.0.3)
View SourceGeneric ActiveMQ client using STOMP protocol for Artemis ActiveMQ.
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, and subscription management with configurable message filtering.
Features
- STOMP-based connection to Artemis ActiveMQ
- Message publishing and consuming
- Address subscription management with ANYCAST (queue) and MULTICAST (topic) routing
- Configurable message filtering with selectors
- Automatic reconnection and error handling
- Callback-based message processing
Usage
# Start the client
{:ok, _} = ActiveMQClient.start_link([
host: "localhost",
port: 61613,
username: "artemis",
password: "artemis",
message_handler: &MyApp.handle_message/1
])
# Publish a message
ActiveMQClient.publish_message("Hello World!", "/queue/test")
# Subscribe to a queue (ANYCAST routing)
ActiveMQClient.subscribe_to_queue("/queue/test")
# Subscribe to address with MULTICAST routing and message filter
ActiveMQClient.subscribe_to_address_with_selector(
"/topic/events",
"type = 'MY_EVENT'",
"my_subscription"
)
Summary
Functions
Returns a specification to start this module under a supervisor.
Gets the current client status.
Publishes a message to an address.
Triggers a manual reconnection attempt.
Sends a reply message to a destination with message type.
Sets a custom message handler function.
Starts the ActiveMQ client process.
Subscribes to multiple addresses with different selectors.
Subscribes to an address with a message selector.
Subscribes to an address with MULTICAST routing (topic semantics).
Subscribes to an address with ANYCAST routing (queue semantics).
Unsubscribes from an address.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Gets the current client status.
Returns
Map containing connection status, host, port, subscriptions, etc.
Publishes a message to an address.
Parameters
message- Message content as stringdestination- Destination address with ANYCAST or MULTICAST routing (optional, uses default if nil)
Returns
:okon success{:error, reason}on failure
Triggers a manual reconnection attempt.
Sends a reply message to a destination with message type.
Parameters
reply_json- JSON reply contentreply_destination- Destination to send reply tomessage_type- Message type header
Returns
:okon success
Sets a custom message handler function.
Parameters
handler- Function to handle incoming messages
Starts the ActiveMQ client process.
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"):multicast_address- Default multicast address destination (default: "/topic/artemis_topic"):message_handler- Custom message handler function
Subscribes to multiple addresses with different selectors.
Parameters
subscriptions- List of {address, selector, subscription_id} tuples
Returns
:okon success{:error, reason}on failure
Subscribes to an address with a message selector.
Parameters
address- Address destination (can be ANYCAST or MULTICAST)selector- Message selector for filteringsubscription_id- Unique subscription identifier
Returns
:okon success{:error, reason}on failure
Subscribes to an address with MULTICAST routing (topic semantics).
Parameters
address- Address with MULTICAST routing (optional, uses default if nil)
Returns
:okon success{:error, reason}on failure
Subscribes to an address with ANYCAST routing (queue semantics).
Parameters
queue- Address with ANYCAST routing (optional, uses default if nil)
Returns
:okon success{:error, reason}on failure
Unsubscribes from an address.
Parameters
address- Address to unsubscribe from
Returns
:okon success{:error, reason}on failure