TraX uses queues to provide event-driven process integration for time-critical integration flows. Access to queues is set up during the technical onboarding.
We recommend that you get events (e.g. "sensor configuration has changed" events) over queues. It is also possible to retrieve events over the web API.
Broker URLs and queue names are listed in the Integration environments and accounts article.
APIs and Protocols
ActiveMQ supports a wide range of clients including Java Message Service (JMS) 1.1, .NET Message Service (NMS), and a range of other languages including Node.js, Go, Python, Ruby, and C++. ActiveMQ also supports wire-level protocols including AMQP, STOMP, OpenWire, WebSocket, and MQTT.
How to connect to an ActiveMQ broker
You can connect to ActiveMQ brokers using various ActiveMQ clients. We recommend using the ActiveMQ Client.
The ActiveMQ service currently accepts clients establishing a connection using TLS version 1.0 to 1.3.
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.
Example: How to connect 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.
Start by downloading and installing Visual Studio Code and .NET 6.0 SDK for your architecture.
Next, in Visual Studio Code, perform these steps:
- From the Visual Studio Marketplace, download the C# for Visual Studio Code (powered by OmniSharp) extension, and the NuGet Package Manager GUI
- Open the NuGet Package Manager GUI, search for "Apache.NMS.ActiveMQ" and select it for installation.
- Add the below code to a file to a new file and save it. Change "Username" and "Password" to your specific ActiveMQ credentials. Note that the example connects to the SKF TraX ActiveMQ staging environment.
// Example How to connect using .NET Message Service (NMS)
using System;
using Apache.NMS;
using Apache.NMS.Util;
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);
private const string Queue = "queue://queue.to.connect>";
private const string Username = "<add username>";
private const string Password = "<add password>";
// ActiveMQ in staging
private const string Url1 = "ssl://b-cc560fb5-e1ad-449c-85aa-a45cc1f6b078-1.mq.eu-west-1.amazonaws.com:61617";
private const string Url2 = "ssl://b-cc560fb5-e1ad-449c-85aa-a45cc1f6b078-2.mq.eu-west-1.amazonaws.com:61617";
private const string TransportProtocol = "failover";
static void Main(string[] args)
{
String uri = String.Format("{0}:({1},{2})", TransportProtocol, Url1, Url2);
Uri connecturi = new Uri(uri);
Console.WriteLine("Connecting to " + connecturi);
IConnectionFactory factory = new ConnectionFactory(connecturi);
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 so that messages will be processed.
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);
}
}
}
}
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.