Configure Platform-Level Message Queues

Apprenda allows Platform owners to register a common message queuing infrastructure that can be leveraged by multiple applications hosted on the Platform.

Message Queueing Overview

Apprenda uses the Apache .Net Messaging Service (NMS) as an abstraction layer over multiple underlying messaging systems. Out-of-the-box, NMS supports the following queue providers:

  • ActiveMQ
  • MSMQ
  • WCF

If your queue provider is not listed, please contact Apprenda to discuss building an additional provider.

Registering Your Queue Provider with Apprenda

Setting up a queue provider requires copying the NMS provider DLL to the Apprenda repository and configuring two Apprenda Regsitry settings.  As an example, the following process can be used to set up an ActiveMQ provider with Apprenda:

The DLL that allows Apache NMS to talk to an ActiveMQ messaging system is Apache.NMS.ActiveMQ.dll. In order for guest applications to use the queueing functionality, that DLL must be included in the WCF service and UI workloads of the application. The easiest way to achieve that is is by configuring an Application Bootstrap Policy that will bootstrap the DLL into any guest application components that will use queueing functionality.

The final step is configuring the Apprenda Platform with the specific messaging provider. This is accomplished by adding the following settings to the Platform Registry:

  • Messaging.NmsProvider: The class name, library name of the NMSProvider class (separated by a comma and a space). In our example, the value would be “Apache.NMS.ActiveMQ.ConnectionFactory, Apache.NMS.ActiveMQ”
  • Messaging.NmsUri: The URL to connect to the queue instance. For example, “activemq:tcp://localhost:61616?wireFormat.tightEncodingEnabled=true

For more information on how to add Registry Settings, please refer to the Managing the Platform Registry documentation.

Using Multi-Tenant Queues

For your SaaS-style application, Apprenda allows you to flow tenant context across message queues and re-establish the tenant context at the consumer level. This allows for easy use of asynchronous communications within your multi-tenant application.

Message Producers

When an application sends a message, it will, by default, flow the tenant context along with the queued message. If this behavior is not desired, you can wrap the sending in a ContextSuppressionScope that will cause the message to be sent without context.

 using (var producer = session.CreateProducer(dest))
 using (new ContextSuppressionScope())

     var request = session.CreateTextMessage("My Message");
     request.NMSCorrelationID = "MSG";



Message Consumers

On the receiving side, the flowed context is not automatically established (to protect against cases where you don’t want the consuming application to act as the calling tenant). If you’d like to establish context, use the QueuedContextScope as exemplified below.

 using (var consumer = session.CreateConsumer(dest))
 using (new QueuedContextScope())
   var message = consumer.Receive(new TimeSpan(0, 0, 5)) as ITextMessage;