This documentation is not maintained. Please refer to doc.castsoftware.com/technologies to find the latest updates.

Extension ID

com.castsoftware.dotnet.nms

What's new?

See .NET NMS - 1.0 - Release Notes.

Description

This extension provides support for Apache NMS .NET APIs which are responsible for consumer and publisher operations in .NET applications. If your C# application utilizes Apache NMS for messaging-related operations and the producer and consumer are handled using the C# language, and you want to modelize the producer and consumer links with appropriate objects and links, then you should install this extension.

Supported libraries

LibraryVersionSupported
Apache NMSup to: 2.1.0

(tick)

Apache NMS ActiveMQup to 2.1.0

(tick)

Compatibility

CAST Imaging Core release

Supported

8.3.x(tick)

Dependencies with other extensions

  • CAST AIP Internal extension (internal technical extension)
  • Web Services Linker

Download and installation instructions

The extension will not be automatically downloaded and installed in CAST Imaging Console. If you need to use it, you should manually install the extension using the Application - Extensions interface.

What results can you expect?

Objects

The following objects are generated:

Icon

Description

Apache NMS ActiveMQ publisher

Apache NMS ActiveMQ Receiver

Apache NMS ActiveMQ unknown publisher

Apache NMS ActiveMQ unknown Receiver

Link Type

Source and Destination of link

Supported APIs

callLinkcallLink between the caller C# method and the  Publisher object

Apache.NMS.IMessageProducer.Send

Apache.NMS.IMessageProducer.SendAsync

Apache.NMS.ActiveMQ.IMessageProducer.Send

Apache.NMS.ActiveMQ.IMessageProducer.SendAsync

callLink

callLink between the  Receiver object and the caller  C# method 

Apache.NMS.IMessageConsumer.Receive

Apache.NMS.IMessageConsumer.ReceiveAsync

Apache.NMS.ActiveMQ.IMessageReceiver.Send

Apache.NMS.ActiveMQ.IMessageReceiver.SendAsync

Example code scenarios

Publisher APIs

 static void Main()
    {
        string brokerUri = "tcp://localhost:61616"; 
        string queueName = "dest_queue"; 

        using (IConnection connection = new ConnectionFactory(new Uri(brokerUri)).CreateConnection())
        {
            connection.Start();

            using (ISession session = connection.CreateSession())
            {
                IDestination destination = session.GetQueue(queueName);

                // Produce message
                ProduceMessage(session, destination);

                // Consume message
                ConsumeMessage(session, destination);

                connection.Stop();
            }
        }
    }

    static void ProduceMessage(ISession session, IDestination destination)
    {
        using (IMessageProducer producer = session.CreateProducer(destination))
        using (ITextMessage message = session.CreateTextMessage("Hello, ActiveMQ!"))
        {
            producer.Send(message);
            Console.WriteLine("Message sent: " + message.Text);
        }
    }

Receiver APIs

 static void ConsumeMessage(ISession session, IDestination destination)
    {
        using (IMessageConsumer consumer = session.CreateConsumer(destination))
        {
            ITextMessage receivedMessage = consumer.Receive() as ITextMessage;
            if (receivedMessage != null)
            {
                Console.WriteLine("Received message: " + receivedMessage.Text);
            }
            else
            {
                Console.WriteLine("No messages in the queue.");
            }
        }

Dotnet Publisher and Receiver

using Apache.NMS;
using Apache.NMS.ActiveMQ;
using System;

class Program
{
    static void Main()
    {
        string brokerUri = "tcp://localhost:61616"; 
        string queueName = "dest_queue"; 

        using (IConnection connection = new ConnectionFactory(new Uri(brokerUri)).CreateConnection())
        {
            connection.Start();

            using (ISession session = connection.CreateSession())
            {
                IDestination destination = session.GetQueue(queueName);

                // Produce message
                ProduceMessage(session, destination);

                // Consume message
                ConsumeMessage(session, destination);

                connection.Stop();
            }
        }
    }

    static void ProduceMessage(ISession session, IDestination destination)
    {
        using (IMessageProducer producer = session.CreateProducer(destination))
        using (ITextMessage message = session.CreateTextMessage("Hello, ActiveMQ!"))
        {
            producer.Send(message);
            Console.WriteLine("Message sent: " + message.Text);
        }
    }

    static void ConsumeMessage(ISession session, IDestination destination)
    {
        using (IMessageConsumer consumer = session.CreateConsumer(destination))
        {
            ITextMessage receivedMessage = consumer.Receive() as ITextMessage;
            if (receivedMessage != null)
            {
                Console.WriteLine("Received message: " + receivedMessage.Text);
            }
            else
            {
                Console.WriteLine("No messages in the queue.");
            }
        }
    }
}

Known limitations

  • Unknown Publisher/Receiver Objects will be created if the evaluation fails to resolve the necessary parameter.