TraX utilizes queues to enable event-driven process integration for time-critical flows. Access to these queues is established during the technical onboarding.
We recommend retrieving events, such as “sensor configuration has changed,” via queues. Alternatively, events can also be retrieved through the web API.
Broker endpoints and queue names are provided in the Integration Environments article.
APIs and Protocols
TraX utilizes the Apache ActiveMQ message broker, which supports a wide range of clients, including Java Message Service (JMS) 1.1, .NET Message Service (NMS), and various other languages such as Node.js, Go, Python, Ruby, and C++. ActiveMQ also supports wire-level protocols like AMQP, STOMP, OpenWire, WebSocket, and MQTT.
Connecting to an ActiveMQ Broker
You can connect to ActiveMQ using one of the many ActiveMQ Client implementations. See Cross Language Clients for more information.
The ActiveMQ service currently supports clients connecting using TLS versions 1.0 to 1.3, however, you MUST NOT use TLS version 1.0 or 1.1.
REQUIRED SKF requires that the client establishes a connection to queues over TLS 1.2, if possible, SKF recommends clients to connect using TLS 1.3. Lower TLS version, i.e. TLS 1.0 or 1.1, MUST NOT be used because these TLS versions are not secure.
Connecting Using .NET Message Service (NMS)
In this example, we're going to set up a development environment in Visual Studio Code and use the .NET 6.0 SDK and Active MQ NMS client library to establish a connection to ActiveMQ.
In this example, we will set up a development environment in Visual Studio Code and use the .NET 6.0 SDK along with the ActiveMQ NMS client library to establish a connection to ActiveMQ.
In Visual Studio Code, perform these steps:
- Get the C# for Visual Studio Code (powered by OmniSharp) extension and the NuGet Package Manager GUI from the Visual Studio Marketplace.
- Open the NuGet Package Manager GUI, and install the "Apache.NMS.ActiveMQ" package.
- Add the below code to a file and change "Username" and "Password" to your specific ActiveMQ credentials.
// Example: How to connect using .NET Message Service (NMS) using System; using Apache.NMS; using Apache.NMS.Util; using System.Threading; namespace Apache.NMS.ActiveMQ.Test { class Program { protected static AutoResetEvent semaphore = new AutoResetEvent(false); protected static ITextMessage message = null; protected static TimeSpan receiveTimeout = TimeSpan.FromSeconds(10); // Queue and authentication details private const string Queue = "queue://queue.to.connect"; private const string Username = ""; private const string Password = ""; // ActiveMQ environment private const string Url1 = "ssl://b-f3bf4075-a59b-48ed-a758-7cdf2d2d3dce-1.mq.eu-west-1.amazonaws.com:61617"; private const string Url2 = "ssl://b-f3bf4075-a59b-48ed-a758-7cdf2d2d3dce-2.mq.eu-west-1.amazonaws.com:61617"; private const string TransportProtocol = "failover"; static void Main(string[] args) { // Create connection URI string uri = string.Format("{0}:({1},{2})", TransportProtocol, Url1, Url2); Uri connecturi = new Uri(uri); Console.WriteLine("Connecting to " + connecturi); // Create connection factory IConnectionFactory factory = new ConnectionFactory(connecturi); // Using connection and session using (IConnection connection = factory.CreateConnection(Username, Password)) using (ISession session = connection.CreateSession()) { IDestination destination = SessionUtil.GetDestination(session, Queue); Console.WriteLine("Using destination: " + destination); // Create a consumer and producer using (IMessageConsumer consumer = session.CreateConsumer(destination)) using (IMessageProducer producer = session.CreateProducer(destination)) { // Start the connection to process messages connection.Start(); producer.DeliveryMode = MsgDeliveryMode.Persistent; producer.RequestTimeout = receiveTimeout; consumer.Listener += new MessageListener(OnMessage); // Send a message ITextMessage request = session.CreateTextMessage("Hello World!"); request.NMSCorrelationID = "abc"; request.Properties["NMSXGroupID"] = "cheese"; request.Properties["myHeader"] = "Cheddar"; producer.Send(request); // Wait for the message semaphore.WaitOne((int)receiveTimeout.TotalMilliseconds, true); if (message == null) { Console.WriteLine("No message received!"); } else { Console.WriteLine("Received message with ID: " + message.NMSMessageId); Console.WriteLine("Received message with text: " + message.Text); } } } } // Message listener protected static void OnMessage(IMessage receivedMsg) { message = receivedMsg as ITextMessage; semaphore.Set(); } } }
- In the Visual Studio Code terminal, change the current directory to the directory where your code is located, and type "dotnet run”
Complementary guidance is available in C# programming with Visual Studio Code
Comments
0 comments
Article is closed for comments.