Apache NMS
Apache NMS (NMS = .NET Messaging Service) is an open-source messaging API for .NET applications that is conceptually similar to JMS (Java Message Service) in the Java world. It’s commonly used with Apache ActiveMQ to send and receive messages in C# applications. The NMS API allows you to build .NET applications in C#, VB, or any other .NET language, using a single API to connect to multiple different providers using a JMS style API.
Why Apache NMS exists?
JMS is widely used in Java, but it’s not natively available in .NET. Apache NMS was created to:
• Provide a JMS-like API for .NET developers
• Enable cross-language messaging (Java ↔ .NET)
• Simplify integration with brokers such as ActiveMQ
How Apache NMS works?
Apache NMS is not a broker itself. It is a client library that connects to a messaging system.
Typical flow:
• A .NET application uses NMS API
• NMS connects to a broker (e.g., ActiveMQ)
• The app sends or receives messages via queues or topics
Key components of Apache NMS
The design mirrors JMS concepts:
• ConnectionFactory: Creates connections to the broker
• Connection: Represents an active link to the messaging system
• Session: Used to create messages, producers, and consumers
• Destination: Either Queue (point-to-point) or Topic (publish-subscribe)
• MessageProducer: Sends messages
• MessageConsumer: Receives messages
• Message: The data being transferred
Supported brokers and providers
Apache NMS works through provider implementations. Common ones include:
• Apache ActiveMQ (most common)
• Apache ActiveMQ Artemis
• Other brokers via compatible protocols (e.g., AMQP)
Each provider implements the NMS API for a specific transport or broker.
Why use Apache NMS?
Use it when you need:
• Messaging in .NET applications
• Integration with Java-based systems (JMS interoperability)
• A consistent abstraction layer over different message brokers
• Asynchronous communication in distributed systems
When to use Apache NMS?
Good fit:
• .NET services communicating with ActiveMQ or Artemis
• Enterprise integration systems
• Microservices using message queues
• Cross-platform systems (Java + .NET)
Not ideal:
• If you are using cloud-native messaging services (they usually have their own SDKs)
• If you don’t need messaging abstraction (direct broker SDK may be simpler)
Key features of NMS
• JMS-like API for .NET
• Supports queues and topics
• Pluggable provider model
• Asynchronous message consumption (listeners)
• Transaction support
• Message acknowledgment modes
Advantages
• Familiar model for teams with JMS experience
• Enables cross-language interoperability
• Decouples application code from broker implementation
• Open-source and flexible
• Works well with ActiveMQ ecosystem
Disadvantages
• Less popular than native .NET messaging libraries
• Documentation and community are smaller
• Adds abstraction layer (can increase complexity)
• Not as actively evolving as modern cloud messaging SDKs
• Requires compatible broker/provider setup
Alternatives in .NET ecosystem
Depending on your use case:
MassTransit
High-level abstraction over multiple brokers
NServiceBus
Enterprise-grade messaging framework
Azure Service Bus
Fully managed messaging in Microsoft Azure
RabbitMQ with .NET client
Lightweight and widely used
Apache NMS Providers
• ActiveMQ client which communicates with ActiveMQ using its own native wire protocol and provides many advanced features beyond the standard NMS API.
• STOMP which connects to any STOMP Broker. Also, when coupled with StompConnect, NMS can be used to communicate with pretty much any existing MOM provider! (Or at least those that support JMS which most MOM providers do).
• MSMQ is an implementation of NMS using Microsoft's MSMQ API.
• EMS provider for talking to TIBCO's EMS message broker. To use this, you will need to following TIBCO's licensing requirements to acquire the TIBCO client assembly DLL. NMS does not ship with the TIBCO client assembly.
• WCF provides support of Windows Communications Framework.
How to use Apache NMS?
You typically install NMS via NuGet:
Install-Package Apache.NMS
Install-Package Apache.NMS.ActiveMQ
Create a Connection
You connect to a broker (like ActiveMQ) using a connection factory:
using Apache.NMS;
using Apache.NMS.ActiveMQ;
IConnectionFactory factory = new ConnectionFactory("activemq:tcp://localhost:61616");
IConnection connection = factory.CreateConnection();
connection.Start();
Create a Session and a Destination (Queue or Topic)
Sessions are used to produce and consume messages:
ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
IDestination destination = session.GetQueue("test-queue");
Send a Message (Producer)
IMessageProducer producer = session.CreateProducer(destination);
ITextMessage message = producer.CreateTextMessage("Hello from Apache NMS!");
producer.Send(message);
Receive a Message (Consumer)
IMessageConsumer consumer = session.CreateConsumer(destination);
consumer.Listener += message =>
{
if (message is ITextMessage textMessage)
{
Console.WriteLine(textMessage.Text);
}
};
Clean Up
Always close resources:
connection.Close();