.NET Integration (TCP / OpenWire)
.NET Integration (TCP / OpenWire)
Section titled “.NET Integration (TCP / OpenWire)”Overview
Section titled “Overview”This guide explains how to connect a .NET client to the JMS Bridge using OpenWire over TCP (not AMQP).
Ensure your JMS Bridge (ActiveMQ Artemis) is configured with an OpenWire acceptor, for example:
<acceptor name="artemis-openwire">tcp://0.0.0.0:61616?protocols=OPENWIRE</acceptor>
Prerequisites
Section titled “Prerequisites”- .NET 6.0 or later
- NuGet package:
dotnet add package Apache.NMS.ActiveMQ
Sample Code
Section titled “Sample Code”using System;using Apache.NMS;using Apache.NMS.ActiveMQ;
class Program{ static void Main() { // Replace with your JMS Bridge hostname and TCP port string brokerUri = "tcp://localhost:61616"; string queueName = "demo-queue";
IConnectionFactory factory = new ConnectionFactory(brokerUri); using (IConnection connection = factory.CreateConnection("admin", "admin")) // Use your credentials { connection.Start();
using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) { IDestination destination = session.GetQueue(queueName);
// Producer: Send a message using (IMessageProducer producer = session.CreateProducer(destination)) { ITextMessage message = session.CreateTextMessage("Hello from .NET client over TCP!"); producer.Send(message); Console.WriteLine("Message sent."); }
// Consumer: Receive a message using (IMessageConsumer consumer = session.CreateConsumer(destination)) { IMessage received = consumer.Receive(TimeSpan.FromSeconds(5)); if (received is ITextMessage textMessage) { Console.WriteLine("Received: " + textMessage.Text); } else { Console.WriteLine("No message received."); } } }
connection.Close(); } }}
TLS / SSL (Optional)
Section titled “TLS / SSL (Optional)”To enable secure connections, configure the broker with a secure acceptor (e.g., ssl://...
).
Then update the URI in the client accordingly:
string brokerUri = "ssl://your-hostname:61617"; // Example SSL port