11.07.2015 Views

y - Net Developer

y - Net Developer

y - Net Developer

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

amrameshreddy.blog.com274 CHAPTER 8 ■ IMPLEMENTING RELIABLE MESSAGING AND QUEUE-BASED COMMUNICATIONSramrameshreddy.blog.comListing 8-14. Creating the Service Host// Host the service within this EXE console application.public static void Main(){// Get MSMQ queue name from app settings in configurationstring queueName = ConfigurationManager.AppSettings["LegacyQueue"];// Create the transacted MSMQ queue if necessary.if (!MessageQueue.Exists(queueName))MessageQueue.Create(queueName, true);using (ServiceHost serviceHost = new ServiceHost(typeof(TradeService))){serviceHost.Open();// The service can now be accessed.Console.WriteLine("The service is ready.");Console.WriteLine("Press to terminate service.");Console.ReadLine();// Close the ServiceHostBase to shutdown the service.serviceHost.Close();}}Start the host, and you are good to receive and process messages from an MSMQ client.As you have seen, using queues with WCF is fairly easy. There is not a lot of complexity orcode required to integrate legacy applications using the integration channel with WCF.Some Pointers on Using MSMQAs you have seen, MSMQ offers you the ability to provide a durable store for your messagesand an easy way to integrate with other non-WCF applications that use MSMQ, but youshould keep in mind a few pitfalls and pointers when using MSMQ:• It is important to note that the durability of the messages depends on the durability ofthe queue. MSMQ queues have a property called Durable. This means that when set totrue, every message received on the queue will be written to disk until processed. If thisproperty is set to false, keep in mind that if the machine hosting the queue fails, allmessages in the queue will be lost. By default, this is set to true. It does have some performanceoverhead; however, it is not recommended that you change this to anythingelse, since that would mean that end-to-end reliability could no longer be guaranteed.Of course, both the client and server ends need to have durability enabled to providethe reliability that you want.ramrameshreddyramrameshreddy• Disabling the DLQ is not recommended. If you are developing for MSMQ 4.0 or later, itis recommended that you configure one DLQ per application and use the poison message–handlingcapabilities. For more information, please refer to the MSMQ guide onMSDN.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!