ActiveMQClient (activemq_client v0.0.2)
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
- Topic and queue subscription management
- 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
ActiveMQClient.subscribe_to_queue("/queue/test")
# Subscribe to topic with message filter
ActiveMQClient.subscribe_to_topic_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 a destination.
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 topics/queues with different selectors.
Subscribes to a queue destination.
Subscribes to a topic destination.
Subscribes to a topic with a message selector.
Unsubscribes from a destination.
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 a destination.
Parameters
message
- Message content as stringdestination
- Destination queue or topic (optional, uses default if nil)
Returns
:ok
on 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
:ok
on 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"):topic
- Default topic destination (default: "/topic/artemis_topic"):message_handler
- Custom message handler function
Subscribes to multiple topics/queues with different selectors.
Parameters
subscriptions
- List of {destination, selector, subscription_id} tuples
Returns
:ok
on success{:error, reason}
on failure
Subscribes to a queue destination.
Parameters
queue
- Queue destination (optional, uses default if nil)
Returns
:ok
on success{:error, reason}
on failure
Subscribes to a topic destination.
Parameters
topic
- Topic destination (optional, uses default if nil)
Returns
:ok
on success{:error, reason}
on failure
Subscribes to a topic with a message selector.
Parameters
topic
- Topic destinationselector
- Message selector for filteringsubscription_id
- Unique subscription identifier
Returns
:ok
on success{:error, reason}
on failure
Unsubscribes from a destination.
Parameters
destination
- Destination to unsubscribe from
Returns
:ok
on success{:error, reason}
on failure