dcsimg
June 23, 2018
Hot Topics:

Extending Microsoft's Concurrency and Coordination Runtime with MSMQ

  • August 11, 2009
  • By Jeffrey Juday
  • Send Email »
  • More Articles »

Outbound

The MSMQGateway.AddQueueOut function appears below.

public Port<MessageBody> AddQueueOut(string pathToQueue)
{
   //This ties everything together, 
   //relates the MessageQueue to a
   //particular port, with a handler 
   //supplied by a component
   //inside of the application
   MessageQueue queue = null;
   Port<MessageBody> port = new Port<MessageBody>();
   MessageQueueMediator mediator;
   queue = MSMQHelper.GetQ(pathToQueue);
   mediator = new MessageQueueMediator(queue);
   _msmqQueuesOut.Add(queue);
   _mediatorsOut.Add(mediator);
   _portsOut.Add(port);
   Arbiter.Activate(_ccrQueue,
      Arbiter.Receive(true, port, mediator.SendMessage)
   );
    return port;
}

The code is very similar to AddQueueIn except that it configures a port for sending a message.

MessageQueueMediator also handles sending a message. The SendMessage function appears below.

public void SendMessage(MessageBody body)
{
   System.Messaging.Message msg = new Message();
   MessageMapper mapper = new MessageMapper(msg);
   mapper.Body = body;
   Console.WriteLine("From Mediator Sending Message " + 
      body.MessageId + " " + 
      body.CreatedDateTime);
   _queue.Send(mapper.Message);
}

Like a receive operation, sending leverages the MessageMapper class. MessageMapper serializes the message so its bytes can be inserted into the BodyStream of the Message class.

Conclusion

Originally built for Robotics, CCR is a library for coordinating tasks and handling concurrency in .NET Framework applications. CCR’s capabilities can be extended to coordinate processes across multiple machines, but doing so requires a distributed transport. Fortunately, MSMQ makes a fine transport choice.

Resources

For the source code click here





Page 3 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.

Sitemap

×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date