{"id":333,"date":"2012-02-22T09:17:00","date_gmt":"2012-02-22T09:17:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/cesardelatorre\/2012\/02\/22\/cqrs-bus-and-windows-azure-technologies\/"},"modified":"2012-02-22T09:17:00","modified_gmt":"2012-02-22T09:17:00","slug":"cqrs-bus-and-windows-azure-technologies","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/cqrs-bus-and-windows-azure-technologies\/","title":{"rendered":"CQRS BUS and Windows Azure technologies"},"content":{"rendered":"<p><a href=\"http:\/\/martinfowler.com\/bliki\/CQRS.html\">CQRS<\/a> has several internal patterns and objects types like <b>Commands<\/b>, <b>CommandHandlers<\/b>, <b>Events<\/b>, <b>EventHandlers<\/b>, and a few others. In the following diagram I show a basic diagram positioning those topics:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/5224.image_054D5D98.png\"><img decoding=\"async\" style=\"border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/8666.image_thumb_1DCCD51B.png\" width=\"777\" height=\"583\" \/><\/a><\/p>\n<p>I am not going to explain CQRS philosophy here, as you can read about it in many posts from <b>Greg Young<\/b>, <b>Udi Dahan<\/b>, <b>Martin Fowler<\/b>, etc.<\/p>\n<p>The only thing I want to highlight before going further is that CQRS is not a top-level architecture. On the other hand, it should be used only for certain scenarios\/contexts, certain areas within a complex application: Only for selected <b>BOUNDED-CONTEXTS<\/b> (in <b>DDD<\/b> lingo).<\/p>\n<p>The point is that this kind of pattern or approach provides (as a consequence) very high scalable applications; therefore, it fits great in <i>Cloud-Computing<\/i> platforms, like <b>Windows Azure<\/b>.<\/p>\n<p>In this post I only want to focus about what Windows Azure technologies we could use for the CQRS Buses.<\/p>\n<p>First of all, all the communications based on the CQRS Buses are asynchronous. The Bus could be implemented in many different ways. For a <strong>Proof of concept<\/strong> and having a single server, it could even be an <em><strong>In-Memory Bus<\/strong><\/em>. But, if we have a real and scalable system, we\u2019d need a Bus implementation placed on a global position, accessible from any Front-End and Back-End server.<\/p>\n<p>We put\/send COMMANDS into the Bus from the Presentation Layer (if using a server UI, like ASP.NET MVC. If the UI is remote, like HTML5, Silverlight, WPF, etc., then, we\u2019d probably have a Web-Service Layer in between, like WCF or REST Web-API). But, the important point here is that COMMANDS will be taken from a single point (COMMAND-HANDLER) and they will be processed only once (like process \u2018RegisterAttendee\u2019 COMMAND). It is something we order to our system, so it is an imperative verb.<\/p>\n<p>In any case, <span style=\"text-decoration: underline\">for handling COMMANDS, we\u2019d need any asynchronous system that will allow to process messages, and each message will be taken and processed just once. A <b>Message-Queue system<\/b> would be nice for this purpose<\/span>. Talking about Windows Azure technologies, we could use <b>Windows Azure Storage Queues,<\/b> based on the <b>Put<\/b> message and <b>Peek<\/b> message functions.<\/p>\n<p>On the other hand, EVENTS are generated when a COMMAND is already processed and persisted. It is done &amp; finished, so all events\u2019 names are past tense verbs, like \u2018AttendeeRegistered\u2019 EVENT. But, and here comes an important difference, EVENTS can be consumed from many systems in order to propagate changes. They can be processed by the EVENT-HANDLER, but also from other BOUNDED-CONTEXTS and event from external systems. Therefore, <span style=\"text-decoration: underline\">we could use a <b>Publish\/Subscription approach<\/b> for this topic<\/span>. Talking about Windows Azure technologies, we could use <b>Windows Azure Service Bus<\/b>.<\/p>\n<p>Below is shown a more specific diagram where Windows Azure technologies are highlighted:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/5444.clip_image004_67366D51.jpg\"><img decoding=\"async\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"clip_image004\" border=\"0\" alt=\"clip_image004\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/4061.clip_image004_thumb_32496814.jpg\" width=\"810\" height=\"636\" \/><\/a><\/p>\n<p>It seems clear that in order to have a publish\/subscription approach (for EVENTS), we need the Windows Azure Service Bus. <b><span style=\"text-decoration: underline\">Regarding COMMANDS, we could use Windows Azure Storage Queues, but the Service Bus is also a possibility here, too<\/span><\/b>.<\/p>\n<p>A few months ago, before having the Windows Azure SDK 1.5, the Service Bus was not supporting message queues, but now, it supports persistent queues plus a richer set of functionality like integration with <b>WCF<\/b> communication stack, transactional behavior, a guaranteed first-in-first-out (FIFO) ordered delivery, publish and consume message batches, etc.<\/p>\n<p>Additionally, the Windows Azure Service-Bus price is quite similar to the Windows Azure Storage Queues price.<\/p>\n<p>In the following link you can see a <b>detailed comparison between the Windows Azure Service-Bus and the Windows Azure Storage Queues<\/b>, taking into account <b>Capabilities<\/b>, <b>Capacity<\/b>, <b>Quotas<\/b>, <b>Management<\/b>, <b>Operations<\/b>, <b>Performance<\/b> and <b>Prices<\/b>:<\/p>\n<p><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/hh767287(VS.103).aspx\">http:\/\/msdn.microsoft.com\/en-us\/library\/hh767287(VS.103).aspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>CQRS has several internal patterns and objects types like Commands, CommandHandlers, Events, EventHandlers, and a few others. In the following diagram I show a basic diagram positioning those topics: I am not going to explain CQRS philosophy here, as you can read about it in many posts from Greg Young, Udi Dahan, Martin Fowler, etc. [&hellip;]<\/p>\n","protected":false},"author":362,"featured_media":12806,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[40,114],"class_list":["post-333","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cesardelatorre","tag-cqrs","tag-window-azure"],"acf":[],"blog_post_summary":"<p>CQRS has several internal patterns and objects types like Commands, CommandHandlers, Events, EventHandlers, and a few others. In the following diagram I show a basic diagram positioning those topics: I am not going to explain CQRS philosophy here, as you can read about it in many posts from Greg Young, Udi Dahan, Martin Fowler, etc. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/posts\/333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/users\/362"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/comments?post=333"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/posts\/333\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/media\/12806"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/media?parent=333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/categories?post=333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/tags?post=333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}