.NET ActiveMQ Artemis Client is a lightweight library built on top of AmqpNetLite. The main goal of this project is to provide a simple API that allows fully leverage Apache ActiveMQ Artemis capabilities in .NET World.
.NET ActiveMQ Artemis Client is distributed via NuGet. You can add ActiveMQ.Artemis.Client NuGet package using dotnet CLI:
The API interfaces and classes are defined in the
The core API interfaces and classes are:
IConnection: represents AMQP 1.0 connection
ConnectionFactory: constructs IConnection instances
IConsumer: represents a message consumer
IProducer: represents a message producer attached to a specified address
IAnonymousProducer: represents a message producer capable of sending messages to multiple addresses
Before any message can be sent or received, a connection to the broker endpoint has to be opened. The AMQP endpoint where the client connects is represented as an
Endpoint object. The
Endpoint object can be created using the factory method
Create that accepts individual parameters specifying different parts of the Uri.
portparameters define TCP endpoint.
passwordparameters determine if authentication (AMQP SASL) should be performed after the transport is established. When
passwordare absent, the library skips SASL negotiation altogether.
schemeparameter defines if a secure channel (TLS/SSL) should be established.
To open a connection to an ActiveMQ Artemis node, first instantiate a
ConnectionFactory provides an asynchronous connection creation method that accepts
The following snippet connects to an ActiveMQ Artemis node on
localhost on port
5672 as a
guest user using
guest as a password via the insecure channel (AMQP).
Closing connection, the same as opening, is a fully asynchronous operation.
To disconnect, simply call
DisposeAsync on connection object:
Connections, producers, and consumers are meant to be long-lived objects. The underlying protocol is designed and optimized for long-running connections. That means that opening a new connection per operation, e.g. sending a message, is unnecessary and strongly discouraged as it will introduce a lot of network round trips and overhead. The same rule applies to all client resources.
The client uses
IAnonymousProducer interfaces for sending messages. To to create an instance of
IProducer you need to specify an address name and a routing type to which messages will be sent.
All messages sent using this producer will be automatically routed to address
Anycast routing type:
To send messages to other addresses you can create more producers or use
IAnonymousProducer is not connected to any particular address.
Each time you want to send a message, you need to specify the address name and the routing type:
The client uses
IConsumer interface for receiving messages.
IConsumer can be created as follows:
As soon as the subscription is set up, the messages will be delivered automatically as they arrive, and then buffered inside consumer object. The number of buffered messages can be controlled by
Consumer Credit . In order to get a message, simply call
If there are no messages buffered
ReceiveAsync will asynchronously wait and return as soon as the new message appears on the client.
This operation can potentially last an indefinite amount of time (if there are no messages), therefore
CancellationToken that can be used to communicate a request for cancellation.
This may be particularly useful when you want to shut down your application.