<?xml version="1.0" encoding="UTF-8" standalone="no"?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"><channel><title>A Vietnamese developer in Australia</title><description></description><managingEditor>noreply@blogger.com (Anonymous)</managingEditor><pubDate>Sun, 16 Aug 2026 20:21:28 +1000</pubDate><generator>Blogger http://www.blogger.com</generator><openSearch:totalResults xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">53</openSearch:totalResults><openSearch:startIndex xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">1</openSearch:startIndex><openSearch:itemsPerPage xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">25</openSearch:itemsPerPage><link>http://thoai-nguyen.blogspot.com/</link><language>en-us</language><itunes:explicit>no</itunes:explicit><itunes:subtitle/><itunes:owner><itunes:email>noreply@blogger.com</itunes:email></itunes:owner><item><title>OutputCache &amp; Instrument using Flatwhite</title><link>http://thoai-nguyen.blogspot.com/2015/12/outputcache-instrument-using-flatwhite.html</link><category>Autofac</category><category>Caching</category><category>Flatwhite</category><category>Intercept</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Tue, 29 Dec 2015 15:10:00 +1100</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-1857500659009107962</guid><description>&lt;br/&gt;
&lt;em&gt;If you are looking for OutputCache for WebApi, &lt;a href="https://github.com/vanthoainguyen/Flatwhite/wiki/Flatwhite.WebApi" target="_blank"&gt;go here&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;
&lt;br/&gt;
&lt;h3&gt;What is Flatwhite?&lt;/h3&gt;
Flatwhite is an AOP library with MVC and WebAPI ActionFilter style using Castle dynamic proxy. There are many libraries out there to help you intercept a method call such as PostSharp, recently CodeCop and they're really cool tools. However, I've been using Castle dynamic proxy for a many years and I think it offers enough needs for my projects. Therefore, Flatwhite is an opinionated library to facilitate usages of Castle dynamic proxy for method interceptions.
&lt;br/&gt;&lt;br/&gt;
Current release only supports Autofac but I think other IOC containers also use Castle dynamic proxy when they come to interception so they will be supported in the future.
&lt;br/&gt;&lt;br/&gt;
You can create MethodFilterAttribute to add custom logic to any methods as soon as it is interceptable by Castle Dynamic Proxy (virtual not final). Flatwhite has a built-in OutputCacheFilter to cache method result which can auto refresh stale content. You can use Flatwhite simply for caching or extending behavior of your code such as profiling, logging by implement MethodFilterAttribute similar to MVC's ActionFilterAttribute
&lt;br/&gt;&lt;br/&gt;
&lt;h3&gt;When to use Flatwhite?&lt;/h3&gt;
You have classes implemented interfaces and registered using Autofac (for now). You have a need to intercept method calls so you possibly have 2 quick options:
&lt;br/&gt;&lt;br/&gt;
&lt;ul&gt;
&lt;li&gt;Use Autofac.Extras and call &lt;em&gt;EnableInterfaceInterceptor()&lt;/em&gt; on type registrations then create/register custom IInterceptor.&lt;/li&gt;
&lt;li&gt;Or use Flatwhite, implement an &lt;em&gt;MethodFilterAttribute&lt;/em&gt; and decorate on the methods on your interfaces which you want to intercept.&lt;/li&gt;
&lt;/ul&gt;
&lt;br/&gt;
As mentioned above, Flatwhite has a built-in OutputCacheFilter to cache method output. It works for methods that have a return value both sync and async methods. Beside caching, you can also implement &lt;em&gt;MethodFilterAttribute&lt;/em&gt; and &lt;em&gt;ExceptionFilterAttribute&lt;/em&gt; to add custom logic to your code.
&lt;br/&gt;&lt;br/&gt;
&lt;h3&gt;How to use Flatwhite?&lt;/h3&gt;
** Required packages: &lt;a href="https://www.nuget.org/packages/Autofac/3.5.2" target="_blank"&gt;&lt;img src="https://img.shields.io/badge/Autofac-3.5.2-yellow.svg"/&gt;&lt;/a&gt;  and &lt;a href="https://www.nuget.org/packages/Castle.Core/3.3.3" target="_blank"&gt;&lt;img src="https://img.shields.io/badge/Castle.Core-3.3.3-yellow.svg"/&gt;&lt;/a&gt;
&lt;br/&gt;
For now, Flatwhite needs to be used with Autofac (except Flatwhite.WebApi package). It requires Castle Dynamic proxy to intercept methods so it's a requirement to have public interface or your methods must be virtual and not final to be intercepted.
&lt;br/&gt;&lt;br/&gt;

&lt;h4 style="font-size:1.5em"&gt;For caching:&lt;/h4&gt;
&lt;br/&gt;
&lt;strong&gt;1/ Enable class interceptor&lt;/strong&gt;
&lt;br/&gt;
If you modify the class to make the method virtual and decorate the method with &lt;em&gt;OutputCacheAttribute&lt;/em&gt;, you will register the class like this:
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public class UserService
{
    [OutputCache(Duration = 2, VaryByParam = "userId")]
    public virtual object GetById(Guid userId) 
    {
        // ...
    }    
}
var builder = new ContainerBuilder().EnableFlatwhite();
builder
    .RegisterType&amp;lt;CustomerService&amp;gt;()    
    .EnableInterceptors();
&lt;/pre&gt;
&lt;br/&gt; 
&lt;strong&gt;2/ Enable interface interceptor&lt;/strong&gt;
&lt;br/&gt;
If the methods are not virtual, but the class implements an interface, you can decorate the methods on the interface with OutputCacheAttribute and register the type like this
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public interface IUserService
{
    [OutputCache(Duration = 2, VaryByParam = "userId")]
    object GetById(Guid userId);

    [NoCache]
    object GetByEmail(string email);

    IEnumerable&amp;lt;object&amp;gt; GetRoles(Guid userId);
}

var builder = new ContainerBuilder().EnableFlatwhite();
builder.RegisterType&amp;lt;UserService&amp;gt;()   
       .As&amp;lt;IUserService&amp;gt;()   
       .EnableInterceptors();
&lt;/pre&gt;
&lt;br/&gt;
&lt;strong&gt;3/ Quick enable cache on all methods&lt;/strong&gt;
&lt;br/&gt;
If you don't want to decorate the OutputCache attribute on the interface, you can do like this to enable cache on all methods
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;var builder = new ContainerBuilder().EnableFlatwhite();
builder.RegisterType&amp;lt;UserService&amp;gt;()   
       .As&amp;lt;IUserService&amp;gt;()   
       .CacheWithStrategy(CacheStrategies
            .AllMethods()
            .Duration(5)
            .VaryByParam("*")
        );
&lt;/pre&gt;
&lt;br/&gt;  
&lt;strong&gt;4/ Choose the method to cache without using Attribute filter&lt;/strong&gt;
&lt;br/&gt;
If you want to cache on just some methods, you can selectively do like below. Again, it works only on virtual methods if you are registering class service; interface services are fine.
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;var builder = new ContainerBuilder().EnableFlatwhite();
builder.RegisterType&amp;lt;BlogService&amp;gt;()
       .As&amp;lt;IBlogService&amp;gt;()
       .CacheWithStrategy(
               CacheStrategies.ForService&amp;lt;IBlogService&amp;gt;()
                              .ForMember(x =&amp;gt; x.GetById(Argument.Any&amp;lt;Guid&amp;gt;()))
                              .Duration(2)
                              .VaryByParam("postId")

                              .ForMember(x =&amp;gt; x.GetComments(Argument.Any&amp;lt;Guid&amp;gt;(), Argument.Any&amp;lt;int&amp;gt;()))
                              .Duration(2)
                              .VaryByCustom("custom")
                              .VaryByParam("postId")
                              .WithChangeMonitors((i, context) =&amp;gt; 
                              {
                                    return new[] {new YourCustomCacheChangeMonitor()};
                              })                                    
       );
&lt;/pre&gt;
&lt;br/&gt;    
&lt;strong&gt;5/ Enable interceptors on all previous registrations&lt;/strong&gt;
&lt;br/&gt;
If you're a fan of assembly scanning, you can decorate the OutputCache attribute on classes &amp; interfaces you want to cache and enable them by RegisterModule &lt;em&gt;FlatwhiteBuilderInterceptModule&lt;/em&gt; before building the container
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;var builder = new ContainerBuilder();
builder
        .RegisterType&amp;lt;BlogService&amp;gt;()
        .AsImplementedInterfaces()
        .AsSelf();

// Register other types normally
...

// Register FlatwhiteBuilderInterceptModule at the end
builder.RegisterModule&amp;lt;FlatwhiteBuilderInterceptModule&amp;gt;();            
var container = builder.Build();
&lt;/pre&gt;
&lt;br/&gt;
Note that you don't have to call EnableFlatwhite() after creating ContainerBuilder like the other methods.
&lt;br/&gt;&lt;br/&gt;
&lt;strong&gt;6/ Auto refresh stale data&lt;/strong&gt;
&lt;br/&gt;
Flatwhite can auto refresh the stale content if you set &lt;em&gt;StaleWhileRevalidate&lt;/em&gt; with a value greater than 0. This should be used with Duration to indicates that caches MAY serve the cached result in which it appears after it becomes stale, up to the indicated number of seconds The first call comes to the service and gets a stale cache result will also make the cache system auto refresh once in the background. So if the method is not called many times in a short period, it's better to turn on AutoRefresh to make the cache alive and refreshed as soon as it starts to be stale
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public interface IBlogService
{
    // For method with too many cache variations because of VaryByParam settings
    [OutputCache(Duration = 5, VaryByParam = "tag, from, authorId", StaleWhileRevalidate = 5)]
    IEnumerable&amp;lt;object&amp;gt; Search(string tag, DateTime from, Guid authorId);    


    // For method with not many cache variations and data is likely to changed every 5 seconds
    [OutputCache(Duration = 5, VaryByParam = "blogId", StaleWhileRevalidate = 5)]
    object GetById(int blogId);    


    // You can turn on AutoRefresh to keep the cache active if there are limited variations of the cache
    [OutputCache(Duration = 5, VaryByParam = "blogId", StaleWhileRevalidate = 5, AutoRefresh = true)]
    IEnumerable&amp;lt;string&amp;gt; GetBlogCategory();    
}
&lt;/pre&gt;
&lt;br/&gt;
&lt;strong&gt;7/ Using CacheProfile&lt;/strong&gt;
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public interface IUserService
{
    [OutputCache(CacheProfile="profileName")]
    object GetById(Guid userId);
}
&lt;/pre&gt;
&lt;br/&gt;
Profile setting default file name is &lt;em&gt;cacheProfile.yaml&lt;/em&gt; located at the same folder of your app.config/web.config file and has a "yaml like" format:
&lt;br/&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;-- Cache profile settings, everything is case-sensitive
-- Profile name
Profile1-Two-Seconds
    -- Profile propertyName:propertyValue, start with a tab or 4+ empty spaces
    Duration:2
    StaleWhileRevalidate:5
    VaryByParam:packageId   
    VaryByCustom:*
    AutoRefresh:true
    RevalidationKey:anything-about-user

Web-Profile2-Three-Seconds  
    MaxAge:3
    StaleWhileRevalidate:6
    VaryByParam:*
    VaryByHeader:UserAgent
    IgnoreRevalidationRequest:true      
&lt;/pre&gt;
&lt;br/&gt;
You can implement another &lt;em&gt;IOutputCacheProfileProvider&lt;/em&gt; and set to &lt;em&gt;Global.OutputCacheProfileProvider&lt;/em&gt; or simply change the location/name of the yaml file. At the moment, only yaml file is supported.

&lt;br/&gt;&lt;br/&gt;
&lt;strong&gt;8/ Revalidate cache&lt;/strong&gt;
&lt;br/&gt;
Even though you can use &lt;em&gt;AutoRefresh&lt;/em&gt; or &lt;em&gt;StaleWhileRevalidate&lt;/em&gt; to auto refresh cache data. Some time you want to remove the cache item after you call a certain method. You can use &lt;em&gt;RevalidateAttribute&lt;/em&gt; to remove the cache item or some related cache items. Decorate the attribute on another method and the cache item will be removed once the method is invoked successfully. On example below, when you call method DisableUser, because it has the Revalidate attribute decorated with "User" as the key, all related caches created for method with attribute OutputCache which has &lt;em&gt;RevalidationKey = "User"&lt;/em&gt; will be reset.
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public interface IUserService
{
    [OutputCache(Duration = 2, StaleWhileRevalidate = 2, VaryByParam = "userId", RevalidationKey = "User")]
    object GetById(Guid userId);

    [OutputCache(Duration = 2, VaryByParam = "userId", RevalidationKey = "User")]
    Task&amp;lt;object&amp;gt; GetByIdAsync(Guid userId); 

    [Revalidate("User")]
    void DisableUser(Guid userId);  
}
&lt;/pre&gt;
&lt;br/&gt;
Unfortunately, this is not working for distributed services. That means the method is called on one server cannot notify the other service instances on remote servers. However, it's technically achievable to extend this filter using queueing or something like that to notify remote system.
&lt;br/&gt;&lt;br/&gt;

&lt;h4 style="font-size:1.5em"&gt;For additional logic before/after calling methods&lt;/h4&gt;
&lt;br/&gt;&lt;br/&gt;
Flatwhite is inspired by WebAPI and ASP.NET MVC ActionFilterAttribute, so it works quite similar. The base filter attribute has following methods. So simply implement your filter class and do whatever you want.
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public abstract class MethodFilterAttribute : Attribute
{

    public virtual void OnMethodExecuting(MethodExecutingContext methodExecutingContext);    
    public virtual Task OnMethodExecutingAsync(MethodExecutingContext methodExecutingContext);   
    public virtual void OnMethodExecuted(MethodExecutedContext methodExecutedContext);    
    public virtual Task OnMethodExecutedAsync(MethodExecutedContext methodExecutedContext);    
}
&lt;/pre&gt;
If you decorate the filter on async methods, only &lt;em&gt;OnMethodExecutingAsync&lt;/em&gt; and &lt;em&gt;OnMethodExecutedAsync&lt;/em&gt; are called. During the filters are being executed, if the Result value is set to the MethodExecutingContext, the remaining filters will be ignored.
&lt;br/&gt;&lt;br/&gt;
&lt;h4 style="font-size:1.5em"&gt;For error handling&lt;/h4&gt;
&lt;br/&gt;
Similar to &lt;em&gt;MethodFilterAttribute&lt;/em&gt;, you can implement &lt;em&gt;ExceptionFilterAttribute&lt;/em&gt; to provide custom error handling logic. If the property &lt;em&gt;MethodExceptionContext.Handled&lt;/em&gt; is true, all remaining ExceptionFilter will be ignored.
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public abstract class ExceptionFilterAttribute : Attribute
{    
    public virtual void OnException(MethodExceptionContext exceptionContext);    
    public virtual Task OnExceptionAsync(MethodExceptionContext exceptionContext);       
}
&lt;/pre&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;h3&gt;What's else?&lt;/h3&gt;
Flatwhite for WebAPI: &lt;a href="https://github.com/vanthoainguyen/Flatwhite/wiki/Flatwhite.WebApi" target="_blank"&gt;https://github.com/vanthoainguyen/Flatwhite/wiki/Flatwhite.WebApi&lt;/a&gt;&lt;br/&gt;
Wiki: &lt;a href="https://github.com/vanthoainguyen/Flatwhite/wiki" target="_blank"&gt;https://github.com/vanthoainguyen/Flatwhite/wiki&lt;/a&gt;



&lt;script language="javascript" type="text/javascript"&gt;SyntaxHighlighter.config.TypeNames = "UserService CustomerService BlogService OutputCache ContainerBuilder IUserService NoCache IEnumerable CacheStrategies IBlogService Argument YourCustomCacheChangeMonitor FlatwhiteBuilderInterceptModule Attribute MethodFilterAttribute ExceptionFilterAttribute MethodExecutingContext MethodExecutedContext MethodExceptionContext Task Revalidate";&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></item><item><title>Book Review RabbitMQ Essentials</title><link>http://thoai-nguyen.blogspot.com/2014/06/book-review-rabbitmq-essentials.html</link><category>RabbitMQ</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Wed, 25 Jun 2014 17:03:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-2596586196365263731</guid><description>&lt;br/&gt;&lt;br/&gt;
&lt;p&gt;I've had a chance to read through the book &lt;a href="http://bit.ly/1mASQR1"&gt;"RabbitMQ Essentials"&lt;/a&gt; published by Packtpub.com&lt;/p&gt;
&lt;br/&gt;
&lt;p&gt;
This book is an excellent book for those who is thinking about integrating their software architect with RabbitMQ. The book is using an Application Inbox to step by step walk you through different technical decision to design and build an Inbox using RabbitMQ. Well, I personally wouldn't build an Inbox application using RabbitMQ because I think RabbitMQ is not a database, messages suppose to be consumed as fast as possible and shouldn't be queued up. Another debate is that it would require you to have each queue for each users which is not ideal to me. The book mentioned we can create thousand of queues without any problem, I wouldn't say yes or say no to that claim because I've never tried it but I wouldn't try to do that to my solution if I have other approach. I've been experimenting enough problem from RabbitMQ cluster network partitioning that made me to rebuild the cluster from scratch. Having thousand queues to backup and restore when disaster happen is possibly a pain. However, I think the application example in this book is fine and a perfect example to help someone who has never used RabbitMQ to look into messaging world. I strongly think you would learn all the skills you need to work with RabbitMQ from basic knowledge such as Exchange, Queue and Binding to setting up a HA cluster or using federation.
&lt;/p&gt;&lt;br/&gt;&lt;p&gt;
In some beginning chapters, It was very interesting to know why RabbitMQ hasn't supported latest AMQP standard and I completely agree with that. I would expect to read more about RabbitMQ ops in later chapters such as trouble shooting network partition, or ideal cluster set-up depend on hosting environments but It's not there in the book. Anyway, here is a brief table of contents:
&lt;/p&gt;&lt;br/&gt;&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;Chapter 1. A Rabbit Spring to Life&lt;/li&gt;
&lt;li&gt;Chapter 2. Creating an Application Inbox&lt;/li&gt;
&lt;li&gt;Chapter 3. Switching to Server-push&lt;/li&gt;
&lt;li&gt;Chapter 4. Handling Application Logs&lt;/li&gt;
&lt;li&gt;Chapter 5. Tweaking Message Delivery&lt;/li&gt;
&lt;li&gt;Chapter 6. Smart Message Routing&lt;/li&gt;
&lt;li&gt;Chapter 7. Taking RabbitMQ to Production&lt;/li&gt;
&lt;li&gt;Chapter 8. Testing and Tracing Applications&lt;/li&gt;
&lt;/ul&gt;


&lt;/p&gt;
&lt;br/&gt;
&lt;p&gt;
In summary, If you are about to learn RabbitMQ, you should read it. It's short enough for you to read on the train but still cover all important aspect. If you are using RabbitMQ but still want to reinforce your knowledge about RabbitMQ, you should also read it. The only thing I think the book doesn't have is more real-life production experiences from people. But I'm sure we can always find it from online community.
&lt;/p&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
Cheers
&lt;br/&gt;
&lt;br/&gt;
</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>How did we recover from RabbitMQ network partition</title><link>http://thoai-nguyen.blogspot.com/2014/06/how-did-we-recover-from-rabbitmq-cluster-network-partition.html</link><category>RabbitMQ</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Wed, 25 Jun 2014 08:54:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-7918875178322610074</guid><description>
&lt;br /&gt;
&lt;p&gt;
We have a RabbitMQ cluster of 3 nodes hosting with Storm. Everything has been very smooth for a years without a problem until Storm upgraded their switches recently, twice actually. Unfortunately, both times they caused network partition problem to our cluster even though Storm said that the upgrade wouldn't affect their customers, just a little bit latency between servers :). 
&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;
Anyway, our mode in the cluster is &lt;strong&gt;pause_minority&lt;/strong&gt; which based on an incorrect assumption. It worked great when a single node crashed for some reason but it's absolutely a bad choice in network partition. In this case, all these 3 servers couldn't communicate with any of the other 2 so they all thought they were minority and paused. As a result, the whole cluster stopped working even after the server could ping each others again.
&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;
So what did I do? It was a little panic actually because every second we don't have the queue, we lost real time data for that moment. I tried to&lt;strong&gt; rabbitmqctl stop_app&lt;/strong&gt;, none of these servers responded immediately. So I tried to CTRL C and &lt;strong&gt;rabbitmqctl start_app&lt;/strong&gt; again, same thing, it didn't seem to response. I thought the backlog on the queue/disk needed time to start the app. Fortunately, I had a backup json file of the whole cluster so I decided to reset everything and rebuild the cluster from scratch accepting that we would lost all the backlog existing in those queues.
&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;
With this approach, I had to kill the &lt;strong&gt;beam.smp&lt;/strong&gt; process, delete all files/folders in mnesia directory, reboot the nodes and restored the backup file. That was cool and whole cluster configuration was load successfully and we had the cluster back. It took me a few hours to make this happen, we lost the real time data and the backlog but we had a way to get those data back from other sources so It was just some more hours for us to get the system back to normal.
&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;
One thing to note here about the second network partition, those servers recovered quickly after the switch upgrade but they seemed to lost all the backlog on their queues, apparently they were all in pause_minotiry mode but I would expect they wouldn't lost data on the queue. I was pretty sure those data was published to the queue with persistence mode 1 which made the servers write the data to disk. I guess RabbitMQ was right when saying that "Other undefined and weird behaviour may occur" during a network partition.
&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;
After this disaster, I've changed our cluster mode to &lt;strong&gt;autoheal&lt;/strong&gt; and wait to see how it would cope with the next network partition. With this setting, we can have 2 nodes cluster and we could have 2 nodes running separately after the next network partition but at least we wouldn't lost the backlog. I've been thinking about another approach using federation which possibly a better approach for us in such not so reliable network situation where the second nodes will have everything published to the first node via a upstream. Anyway, we'll wait and see. 
&lt;/p&gt;
&lt;br /&gt;
&lt;br /&gt;
Hope this information help someone ;)</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">7</thr:total></item><item><title>Using RabbitMQ Header exchange with Burrow.NET</title><link>http://thoai-nguyen.blogspot.com/2014/06/using-rabbitmq-header-exchange-with.html</link><category>Burrow.NET</category><category>RabbitMQ</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Mon, 23 Jun 2014 10:06:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-6567941073248984463</guid><description>In RabbitMQ, messages are published to the Exchange. However, subscription will be made against queues. Binding is the key to make the right messages to go to the expected queue.
In this post, we will setup an exchange to filter messages that have ip = 1"0.10.0.1" in the header go to an expected queue.

This will involve following steps:
&lt;ul&gt;
&lt;li&gt;- Create an exchange type Header &lt;/li&gt;
&lt;li&gt;- Create a queue&lt;/li&gt;
&lt;li&gt;- Bind the queue to the exchange with following arguments
&lt;pre&gt;
   ip = "10.10.0.1"
   x-match = "all"
&lt;/pre&gt;
   
&lt;li&gt;- Publish messages to the exchange with the ip in the header&lt;/li&gt;
&lt;li&gt;- Subscribe the the queue and process such messages&lt;/li&gt;
&lt;/ul&gt;
&lt;br/&gt;
RabbitMQ header exchange is capable of filtering multiple header value by allowing us to set x-match = all or any. And using a combination of the bindings will facilitate any complex routing logics.
In this post, we are filtering only the ip in the header so x-match = all or any doesn't matter.

Creating exchange, queue and binding can be done manually. However, below is the code to do those using Burrow.NET library:
&lt;br/&gt;
&lt;pre&gt;
Assume that the exchange name is : Burrow.Demo.E.Headers
the queue name is                : Burrow.Demo.Q.Message
and the message to use is        : IpMessage
&lt;/pre&gt;
&lt;br /&gt;
&lt;h2&gt;1/ Setup queue, exchange and binding using Burrow.NET&lt;/h2&gt;

&lt;pre class="brush: csharp; smart-tabs: true; highlight: [11]; toolbar: false"&gt;var setup = new RabbitSetup(_connectionString);
var routeSetupData = new RouteSetupData
{
    RouteFinder = new ConstantRouteFinder("Burrow.Demo.E.Headers", "Burrow.Demo.Q.Message", "IpMessage"),
    ExchangeSetupData = new ExchangeSetupData
    {
        ExchangeType = ExchangeType.Headers,
    },
    QueueSetupData = new QueueSetupData
    {
        MessageTimeToLive = 100000,
    },
    SubscriptionName = SubscriptionName,
};
routeSetupData.OptionalBindingData["ip"] = "10.10.0.1";
routeSetupData.OptionalBindingData["x-match"] = "all";

setup.CreateRoute&amp;lt;AndreyMessage&amp;gt;(routeSetupData);
&lt;/pre&gt;

Normally, an application should have an implementation of IRouteFinder, I use ConstantRouteFinder in this example for simple demonstration. After executing the above code, if you check the created queue or exchange,
you should see the expected binding. 
&lt;br /&gt;
&lt;img src="https://dl.dropboxusercontent.com/u/81698224/2014-06-23/binding.png" /&gt;
&lt;br /&gt;
Note: I set MessageTimeToLive = 100 seconds, it's optional. 
&lt;br /&gt;
&lt;br /&gt;

&lt;h2&gt;2/ Publishing data to RabbitMQ Exchange&lt;/h2&gt;

&lt;pre class="brush: csharp; smart-tabs: true; highlight: [6]; toolbar: false"&gt;var tunnel = RabbitTunnel.Factory.Create(_connectionString);
tunnel.SetSerializer(new JsonSerializer());
tunnel.SetRouteFinder(new ConstantRouteFinder("Burrow.Demo.E.Headers", "Burrow.Demo.Q.Message", "IpMessage"));
tunnel.Publish(new IpMessage(), new Dictionary&amp;lt;string, object&amp;gt;{{"ip", "10.10.0.1"}});
&lt;/pre&gt;

&lt;br /&gt;
&lt;h2&gt;3/ Subscribe data from Burrow.Demo.Q.Message&lt;/h2&gt;

&lt;pre class="brush: csharp; smart-tabs: true; highlight: [6]; toolbar: false"&gt;var tunnel = RabbitTunnel.Factory.Create(_connectionString);
tunnel.SetSerializer(new JsonSerializer());
tunnel.SetRouteFinder(new ConstantRouteFinder("Burrow.Demo.E.Headers", "Burrow.Demo.Q.Message", "IpMessage"));
tunnel.Subscribe(new SubscriptionOption&amp;lt;IpMessage&amp;gt;
{
    MessageHandler = msg =&amp;gt; { /* Handle the message here */},
    SubscriptionName = "AwesomeApp",
    QueuePrefetchSize = 10, 
    BatchSize = 2 // 2 threads
});
&lt;/pre&gt;

&lt;br /&gt;
&lt;br /&gt;
Summary, I normally make a wrapper class on top of the publishing code to set the required header value to the dictionary from the message fields. We should have in mind fields in the header we're going to use to create the correct binding. However, if later in your project, a new field is added and it's a criteria to put in the header for routing messages, a new binding including that field should be added and we can simply delete the old binding.
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;

Cheers
&lt;br /&gt;
&lt;br /&gt;

&lt;script language="javascript" type="text/javascript"&gt;SyntaxHighlighter.config.TypeNames = "RouteSetupData ConstantRouteFinder ExchangeSetupData QueueSetupData RabbitTunnel JsonSerializer IpMessage Dictionary SubscriptionOption";&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>Monitor RabbitMQ queues &amp; count total messages</title><link>http://thoai-nguyen.blogspot.com/2013/07/monitor-rabbitmq-queues-count-message.html</link><category>Burrow.NET</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Thu, 18 Jul 2013 16:47:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-7574341517227364599</guid><description>&lt;br /&gt;
- I used to do the hard way which is creating another queue which is bound to the same exchange with same parameters, routing keys. Then consume from that queue and count the message in 5 minutes, 15 minutes, 1 hour etc. 
&lt;br /&gt;
&lt;br /&gt;
- I've just got another idea which is more simple. The solution is similar to the first approach, but you apply &lt;a href="https://www.rabbitmq.com/ttl.html" target="_blank"&gt;"Message TTL"&lt;/a&gt; parameter when creating the queue. So you will have to create 3 queues with Message TTL to 5 minutes, 15 minutes, 1 hour. At any point, the total messages in each queue is the actual number you want. And with latest Burrow.NET (From 1.0.17) you can actually count the message in the queue this way:
&lt;br /&gt;
&lt;br /&gt;
&lt;img src="https://dl.dropboxusercontent.com/u/81698224/2013-07-18/MessageTTL.png" /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;ITunnel tunnel = RabbitTunnel.Factory.Create();
// Set routeFinder if you have custom routefinder
var messageCount = tunnel.GetMessageCount&amp;lt;YourMessageType&amp;gt;("");


//Or if you want to count all the messages in priority queues:

ushort maxLevel = 5;
ITunnel tunnel = RabbitTunnel.Factory.WithPrioritySupport()
                             .Create().WithPrioritySupport();
// Set routeFinder if you have custom routefinder 
var messageCount = tunnel.GetMessageCount&amp;lt;YourMessageType&amp;gt;("", maxLevel);
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
Cheers
&lt;br /&gt;
&lt;br /&gt;

&lt;script language="javascript" type="text/javascript"&gt;SyntaxHighlighter.config.TypeNames = "ITunnel RabbitTunnel YourMessageType";&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></item><item><title>Deploy .NET window service artifact to a remote server from TeamCity (Updated)</title><link>http://thoai-nguyen.blogspot.com/2012/10/deploy-dot-NET-window-service-TeamCity-Updated.html</link><category>Deployment</category><category>Dotnet</category><category>RPC</category><category>TeamCity</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Mon, 15 Oct 2012 16:09:00 +1100</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-1548131306432760335</guid><description>&lt;br/&gt;
&lt;br/&gt;
- This post is an update of my &lt;a href="/2012/04/deploy-windows-service-teamcity-remote.html" target="_blank"&gt;previous post&lt;/a&gt;. Basically, it's the same approach of 90% similar except I won't use Remote Powershell in this post. Config remote PowerShell is such a pain in the ass, I reckon. I had to setup a deployment on another box which have IIS actually but someone in my team had already removed the Default Web Site so I couldn't find any quick and easy way to make Remote Powershell work. The error message Powershell prints out is so stupid which does not even tell me what it wants.
&lt;br/&gt;&lt;br/&gt;
&lt;quote style="color:red;font-size=0.8em;font-style:italic"&gt;
“Set-WSManQuickConfig : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: “winrm quickconfig”. At line:50 char:33 + Set-WSManQuickConfig &amp;lt;&amp;lt;&amp;lt;&amp;lt; -force + CategoryInfo : InvalidOperation: (:) [Set-WSManQuickConfig], InvalidOperationException + FullyQualifiedErrorId : WsManError,Microsoft.WSMan.Management.SetWSManQuickConfigCommand“
&lt;/quote&gt;
&lt;br/&gt;&lt;br/&gt;
- Ok, there is another reason to hate Microsoft. It's time to abandon PS, I tried pstools before Remote Power Shell and got other problems so I won't waste time to go back to the very old tool as Power Shell is much more power full. So writting a simple console WCF application to communitcate between TeamCity and the Remote server is my choice.
&lt;br/&gt;&lt;br/&gt;
- And the tool's name is &lt;a href="https://github.com/vanthoainguyen/DistributedDeploymentTool" target="_blank"&gt;DD&lt;/a&gt; which is a shortname of "Distributed Deployment". In this post, I'll sum up with details how to setup deployment for a windows service from TeamCity.
&lt;br/&gt;&lt;br/&gt;

- Unlike web application, a window service is often a long running process in background. A .NET windows service has an OnStop method for you to clean up resource before stopping, which is cool. HOWEVER, when you try to stop the service using &lt;em&gt;"net stop servicename"&lt;/em&gt;, it does stop the service but the process will not end as fast as it can. I reckon a .NET window service can host multiple window services which are classes inherit from &lt;em&gt;ServiceBase&lt;/em&gt; class so it could be a reason that makes the window services manager wait a little while for all potential services within a process to stop before ending the main process.
&lt;br/&gt;&lt;br/&gt;
- In some cases like mine, I want the service stop immediately when it can so I have to somehow call Environment.Exit to make the process stop asap. Apparently I cannot use TASK KILL like the &lt;a href="/2012/04/deploy-windows-service-teamcity-remote.html" target="_blank"&gt;previous post&lt;/a&gt; as it was such a hacky way and it could corrupt my data. So my approach is letting the program listen to a command, when receiving an exit signal, the app should cleanup resources and invoke Enrironment.Exit. So if you need something like this, go on reading.
&lt;br/&gt;
&lt;br/&gt;
&lt;h3&gt;I/ Things you need to prepare:&lt;/h3&gt;
&lt;ul class="circle"&gt;
&lt;li&gt;Remote server: aka target server, a server that we'll install the service on&lt;/li&gt;
&lt;li&gt;TeamCity server: aka build server, a server that has TeamCity installed&lt;/li&gt;
&lt;li&gt;1 Project slot in Teamcity as I want to deploy whenever I click "Run" on a Teamcity deployment project instead of auto deployment after code build, so it'll cost you 1 project in 20 available slots of free TeamCity&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.gnu.org/software/wget/" target="_blank"&gt;Wget&lt;/a&gt;: this tool will download a compressed artifac from Teamcity&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.7-zip.org/download.html" target="_blank"&gt;7zip&lt;/a&gt;: this tool will be used to decompressed the artifac&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/vanthoainguyen/DistributedDeploymentTool" target="_blank"&gt;DD&lt;/a&gt;: this tool will do 2 things: listen on a deployment command from teamcity and send exit signal to your long running window service&lt;/li&gt;
&lt;/ul&gt;

&lt;br/&gt;
&lt;br/&gt;
&lt;h3&gt;II/ Code involved:&lt;/h3&gt;
1/ Assume that your service class is AwesomeService.cs, implement interface &lt;strong&gt;ISignalListener&lt;/strong&gt; and add event &lt;strong&gt;WhenStop&lt;/strong&gt;:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public partial class AwesomeService : ServiceBase, ISignalListener
{
    public Action WhenStop { get; set; }
    public void Exit()
    {
        Stop();
        if (WhenStop != null)
        {
            WhenStop();
        }
    }
    
    // ...
}
&lt;/pre&gt;
&lt;br /&gt;
2/ In your service code, anywhere before service start such as &lt;strong&gt;Program.cs&lt;/strong&gt;, add this code:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;var svc = new AwesomeService();            
//NOTE: Wait for signal from Teamcity Deployment
Server.Start&amp;lt;ISignalListener&amp;gt;(svc, "AwesomeService");
Timer timer;
svc.WhenStop = () =&amp;gt;
{
    // NOTE: Will end process after 1 second
    timer = new Timer(o =&amp;gt; Environment.Exit(0), null, 1000, Timeout.Infinite);
};
ServiceBase.Run(svc);
// ...
&lt;/pre&gt;
&lt;br /&gt;
3/ Prepare the &lt;strong&gt;deploy.bat&lt;/strong&gt; script. I like to control the deployment process in a batch file instead of implement the steps in a program as I think people will have their own steps and a batch file is simple enough to manage. Again this batch file will basically do these things:

&lt;ul class="circle"&gt;
&lt;li&gt;Use wget to download the latest artifact from TeamCity.&lt;/li&gt;
&lt;li&gt;Use 7zip to extract the artifact, copy it to a temporary folder.&lt;/li&gt;
&lt;li&gt;Save the artifact to Artifacts folder&lt;/li&gt;
&lt;li&gt;Backup the whole current service folder&lt;/li&gt;
&lt;li&gt;Stop target window service&lt;/li&gt;
&lt;li&gt;Copy over new files and old configuration files&lt;/li&gt;
&lt;li&gt;Start target window service&lt;/li&gt;
&lt;li&gt;Clean up&lt;/li&gt;
&lt;/ul&gt;

&lt;br /&gt;
Here is the basic code that anyone can use, just keep it somewhere, we'll need to copy the batch file to RemoteServer.

&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;@echo off
SETLOCAL
:: 0/ --------- Set some local variables
SET Environment.ExecutingFolder="C:\Deployment"
SET Environment.7zip="C:\Program Files (x86)\7-Zip\7z.exe"
SET Environment.Wget="C:\Deployment\wget.exe"

SET TeamCity.User=your-teamcity-account
SET TeamCity.Password=your-teamcity-password
SET TeamCity.BuildTypeId=teamcity-build-type
SET TeamCity.Artifact=awesomeservice.{build.number}.zip ::

SET AwesomeService.TargetFolderName=AwesomeService
SET AwesomeService.TargetFolderPath=C:\AwesomeService
SET AwesomeService.ServiceName=AwesomeService
SET AwesomeService.ImageName=AwesomeService.exe
CD /D %Environment.ExecutingFolder%
 
ECHO 1/ --------- Get latest artifact from TeamCity, AwesomeService
%Environment.Wget% -q --http-user=%TeamCity.User% --http-password=%TeamCity.Password% --auth-no-challenge http://your.teamcity.url.com/repository/download/%TeamCity.BuildTypeId%/.lastSuccessful/%TeamCity.Artifact%
REN *.zip* *.zip
ECHO Found following artifact
DIR /B *zip


ECHO 2/ --------- Extract the artifact to folder __Temp ---------------
%Environment.7zip% e -y -o__Temp *.zip


ECHO 3/ --------- Store the artifact ------------------ 
MOVE /Y *.zip Artifacts\


ECHO 4/ --------- Backup current service folder --------------- 
for %%a in (%AwesomeService.TargetFolderPath%) do set Temp.LastDate=%%~ta
SET Temp.LastDate=%Temp.LastDate:~6,4%-%Temp.LastDate:~0,2%-%Temp.LastDate:~3,2% %Temp.LastDate:~11,2%%Temp.LastDate:~14,2%%Temp.LastDate:~17,2%
ECHO Last deployment: %Temp.LastDate%
ECHO Now backup files to folder %AwesomeService.TargetFolderName%.%Temp.LastDate%
XCOPY /E /I /H /R /Y %AwesomeService.TargetFolderPath% "%AwesomeService.TargetFolderName%.%Temp.LastDate%"


ECHO 5/ --------- Stop %AwesomeService.ServiceName% service ---------------
DD AwesomeService /wait 50
ECHO Wait 2 more seconds
ping 1.1.1.1 -n 1 -w 2000 &amp;gt; NUL

ECHO 6/ --------- Deploy new files and copy over old configs ----------------------
ECHO ... Deploy latest assemblies
XCOPY /E /H /R /Y __Temp %AwesomeService.TargetFolderPath%

ECHO ... Deploy old configs 
COPY /Y "%AwesomeService.TargetFolderName%.%Temp.LastDate%\*.config" %AwesomeService.TargetFolderPath%

ECHO ... Delete log files 
DEL /F /Q %AwesomeService.TargetFolderPath%\Logs\log.txt* &amp;gt; NUL
pause

ECHO 7/ --------- Start %AwesomeService.ServiceName% service ---------------
net start %AwesomeService.ServiceName% 

ECHO 8/ --------- Cleanup --------------------------------- 
::DEL /F /Q /S *jsessionid*
RD /S /Q __Temp
ENDLOCAL
&lt;/pre&gt;
&lt;br/&gt;

- The url to the artifac in TeamCity will look like:
&lt;br /&gt;
&lt;span style="font-style:italic"&gt;http://teamcity-ip-address:80/repository/download/&lt;strong&gt;bt2&lt;/strong&gt;/3907:id/service.name.1.12.1234.zip&lt;/span&gt;
- So dedend on the build type id of your artifac, change it in the above deploy.bat
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;III/ Setup steps:&lt;/h3&gt;
&lt;h4 style="font-size:1.4em"&gt;* On Remote Server&lt;/h4&gt;
- Download and install 7zip
&lt;br/&gt;
- Assume that you put all custom tools and Deploy.bat in &lt;em&gt;C:\Deployment&lt;/em&gt;. Create folder &lt;em&gt;C:\Deployment\Artifacs&lt;/em&gt; to store your teamcity artifacs.

&lt;br/&gt;
The Deployment folder should look like this:
&lt;br/&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;
 Volume in drive C is OS
 Volume Serial Number is ABCD-EFGH

 Directory of C:\Deployment

14/10/2012  02:59 PM    &amp;lt;DIR&amp;gt;          .
14/10/2012  02:59 PM    &amp;lt;DIR&amp;gt;          ..
14/10/2012  02:58 PM    &amp;lt;DIR&amp;gt;          Artifacts
14/10/2012  02:58 PM            38,912 DD.exe
14/10/2012  02:58 PM             2,558 Deploy.bat
14/10/2012  02:58 PM           401,408 wget.exe
               4 File(s)        442,878 bytes
               3 Dir(s)  405,532,868,608 bytes free
&lt;/pre&gt;
&lt;br/&gt;
- Run DD tool:
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;C:\Deployment\DD -listen 5555 -token YourS3cur!tyTok3n
&lt;/pre&gt;
&lt;br/&gt;
- Or install it as a window service, remember to start it once installed ;)
&lt;br/&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /listen=5555 /token=YourS3cur!tyTok3n /i C:\Deployment\DD.exe
&lt;/pre&gt;
&lt;br/&gt;
&lt;h4 style="font-size:1.4em"&gt;* On Team City Server&lt;/h4&gt;
- Copy DD.exe and put somewhere such as &lt;strong&gt;C:\Program Files\DD.exe&lt;/strong&gt;
&lt;br /&gt;
- Add new project such as: Awesome service deployment
&lt;br /&gt;
- Add 1 build step like this picture:
&lt;br /&gt;
&lt;a href="https://dl.dropbox.com/u/81698224/2012-10-14/Teamcity-build-step.png" class="fancybox"&gt;
&lt;img src="https://dl.dropbox.com/u/81698224/2012-10-14/Teamcity-build-step.png" /&gt;&lt;/a&gt;
&lt;br /&gt;
Command parameters:
&lt;br /&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;-execute C:\Deployment\deploy.bat -target remoteserver-ip:5555 -token YourS3cur!tyTok3n
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;

That's it. Your AwesomeService should be deployed whenever you click Run on the deployment project from TeamCity. 
&lt;a href="https://dl.dropbox.com/u/81698224/2012-10-14/Teamcity-run-button.png" class="fancybox"&gt;&lt;img src="https://dl.dropbox.com/u/81698224/2012-10-14/Teamcity-run-button.png" /&gt;&lt;/a&gt;
Obviously you could adjust some thing in the deploy.bat to suit your needs, let me know if you have any problems.
&lt;br /&gt;
&lt;br /&gt;
Cheers

&lt;script language="javascript" type="text/javascript"&gt;SyntaxHighlighter.config.TypeNames="AwesomeService ServiceBase ISignalListener Action Server Timer Environment Timeout";&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">8</thr:total></item><item><title>RPC with Burrow.NET and RabbitMQ</title><link>http://thoai-nguyen.blogspot.com/2012/10/rpc-with-burrownet-and-rabbitmq.html</link><category>Burrow.NET</category><category>RabbitMQ</category><category>RPC</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Tue, 2 Oct 2012 16:45:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-5369536323833812999</guid><description>&lt;br /&gt;
Definitely RPC is nothing new, I just implemented it in a slightly different way. &lt;strong&gt;Burrow.RPC&lt;/strong&gt; is some code I made recently for my project. It helps applications communicate in a RPC style using Burrow.NET. 
&lt;br /&gt;&lt;br /&gt;
To use &lt;strong&gt;Burrow.RPC&lt;/strong&gt; you definitely need &lt;strong&gt;Burrow.NET&lt;/strong&gt; package, and that's all. If you need some more utilities like &lt;strong&gt;JsonSerializer&lt;/strong&gt;, you have to grab &lt;strong&gt;Burrow.Extras&lt;/strong&gt;. So if you only need Burrow.NET for your RabbitMQ stuff, &lt;strong&gt;Burrow.RPC is absolutely not neccessary&lt;/strong&gt;.
&lt;br /&gt;&lt;br /&gt;
The way Burrow.RPC works is that it wraps your method call in a request object and wait for response object. Everything is done via &lt;strong&gt;Castle Dynamic Proxy&lt;/strong&gt; at client and .NET Reflection at server so you don't have to write much extra code to make your application work in RPC way. 
&lt;br /&gt;&lt;br /&gt;
Let's say you have a "basic" interface and its implementation, now you want these existing code work remotely, just download package Burrow.RPC, declate the client using RpcFactory and create a listener at server side, also using RpcFactory and it just works.
&lt;br /&gt;&lt;br /&gt;
I mentioned the "basic" interface because this library will work for all basic methods except methods have &lt;strong&gt;Action&lt;/strong&gt; or &lt;strong&gt;Func&lt;/strong&gt; param. It can work with methods have &lt;strong&gt;"out"&lt;/strong&gt; or &lt;strong&gt;"ref"&lt;/strong&gt; params as soon as the paramether is serializable, just don't make the method be so fancy ;), it will work. I recommend using JsonSerializer from Burrow.Extras package as it using Json.NET which is pretty awesome.
&lt;br /&gt;&lt;br /&gt;
It's time for some sample. Given that you have following interface and its implementation:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public interface ISomeService
{
    [Async] // This method will be called asynchronously
    void Delete(string userId);        
    
    [RpcTimeToLive(100)] // in seconds
    void SendWelcomeMessage(EmailMessage message);
    
    IEnumerable&amp;lt;User&amp;gt; Get(int page, int pageSize, out int totalCount);    
}

public class SomeServiceImplementation : ISomeService
{
     // Implementation here
}&lt;/pre&gt;
&lt;br /&gt;
There are something to note about the above interface:
&lt;br /&gt;&lt;br /&gt;
&lt;ol class="decimal"&gt;
&lt;li&gt;Attribute &lt;strong&gt;Async&lt;/strong&gt; decorated on method &lt;strong&gt;Delete&lt;/strong&gt; will make this "void" method work asynchronously. That means the client code will not wait until it receives response after calling the method. It's pretty convenient in some casee when you don't need to wait for the result. So you cannot use &lt;strong&gt;Async&lt;/strong&gt; attribute on methods that have return type or have &lt;strong&gt;"out"&lt;/strong&gt; param.&lt;/li&gt;
&lt;li&gt;Attribute &lt;strong&gt;RpcTimeToLive&lt;/strong&gt; decorated on method &lt;strong&gt;SendWelcomeMessage&lt;/strong&gt; will make the request valid in 100 seconds. If the server is so busy to pickup messages on the request queue, and when it has a chance to do that but it's over 100 seconds since the request was created, the TimeOutException will be thrown from server and certainly the client will get that Excepton.&lt;/li&gt;
&lt;li&gt;The last method of this interface has an out param and a return type, so whenever you call this method, the client thread will be blocked until it receives the result from server. The out parameter "totalCount" will definitely have value&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
So at client code, you will need an instance of &lt;strong&gt;ISomeService&lt;/strong&gt; which is just a mock object created by Castle dynamic proxy. All the method of this object will be intercepted and the method call together with its parameters will be wrapped in a &lt;strong&gt;RpcRequest&lt;/strong&gt; which eventually will be published to the RabbitMQ server:
&lt;br /&gt;&lt;br /&gt;

&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;var client = RpcFactory.CreateClient&amp;lt;ISomeService&amp;gt;();
client.Delete("van-the-shark");
&lt;/pre&gt;
&lt;br /&gt;
Ideally, the client code is a class which has dependency on ISomeService and we just have to register the proxy instance using your favorite IOC container.
&lt;br /&gt;&lt;br /&gt;
At server side, we will need to do similar thing for the server, there must be a real instance of ISomeService which eventually handle the method call.
&lt;br /&gt;&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;ISomeService realService = new SomeServiceImplementation();
IRpcServerCoordinator server = RpcFactory.CreateServer&amp;lt;ISomeService&amp;gt;(realService, serverId: "TestApp");
server.Start();
&lt;/pre&gt;
&lt;br /&gt;
The RpcFactory basically will use Burrow.NET to subscribe to request queue, when a request comes, it will try to map the request to a valid method on ISomeService and delegate the invocation to the correct method of the real service object. After that, the result value if any together with all the params which are potentially changed during the method call will be wrapped in a &lt;strong&gt;RpcRespone&lt;/strong&gt; object and sent back to the response queue. Please explicitly specify the generic type when creating the server as the type will be a part of the queue/exchange names for Requests and Responses.
&lt;br /&gt;&lt;br /&gt;
There is one interesting thing to note here: every instance of the proxied client will have a separated response queue. Let's say you have 2 instances of your application running on different machine, these instances of the same application create the same RPC request and send to the same request queue, the server will somehow need to know where to send the response back to the correct client. That's why the response address (which is a queue name) will be different between clients. If the service is singleton and shared accross different objects in your client code, you have to guarantee the RPC method call in different threads should be synchronize properly. Otherwise, you could face some silly sittuation where result for the second call arrives to the code block where the first call happened. Anyway, too much information will make more confuse &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/07.gif" /&gt;, please just know that Burrow.RPC is not thread safe for singleton object.
&lt;br /&gt;&lt;br /&gt;
By default, Burrow.RPC will create queues and exchanges for you. It's neccessary as the response queue should be deleted once the client disconnected. When the client connect again, new response queue will be generated. You can change the exchange name, type and queue names by implementing following interface:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;/// &amp;lt;summary&amp;gt;
/// This route finder is created for RPC communication.
/// Implement this interface if you want to use custom naming conventions for your Response/Request queue
/// &amp;lt;/summary&amp;gt;
public interface IRpcRouteFinder
{
    /// &amp;lt;summary&amp;gt;
    /// If set to true, the library will create exchange and queue for you
    /// &amp;lt;/summary&amp;gt;
    bool CreateExchangeAndQueue { get; }

    /// &amp;lt;summary&amp;gt;
    /// Default can be empty as the empty exchange is the built-in exchange
    /// &amp;lt;/summary&amp;gt;
    string RequestExchangeName { get; }

    /// &amp;lt;summary&amp;gt;
    /// Should be either direct or fanout
    /// &amp;lt;/summary&amp;gt;
    string RequestExchangeType { get; }
    
    /// &amp;lt;summary&amp;gt;
    /// If RequestExchangeName is empty, Burrow.RPC will route the RpcRequest object to this queue by publishing the msg to the empty exchange with the routing key is equal to this queue name
    /// &amp;lt;/summary&amp;gt;
    string RequestQueue { get; }

    /// &amp;lt;summary&amp;gt;
    /// The response queue must be unique per instance of the RPC client
    /// &amp;lt;para&amp;gt;If you have 2 instances of the rpc clients, these instances should subscribe to different response queue as the responses from the rpc server must be routed to correct client&amp;lt;/para&amp;gt;
    /// &amp;lt;/summary&amp;gt;
    string UniqueResponseQueue { get; }
}&lt;/pre&gt;
&lt;br /&gt;
There are a few more things about the code but I think it's better for you to findout yourself if you're interested, there are quite a few comments in the code which could make thing clear &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/17.gif" /&gt; eventhough I always believe if I try to comment to make thing clear, that means the code is not cleared enough. This blogspot should show only basic usage of the library. And furthur more, there are probably changes in the future for this RPC API so I'll leave it for now. Please grab the source code from &lt;a href="https://github.com/vanthoainguyen/Burrow.NET"&gt;github&lt;/a&gt;, and run the TestRPC console demo project to see how it works &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/50.gif" /&gt;. Nuget package is also available: &lt;a href="http://nuget.org/packages/Burrow.RPC" target="_blank"&gt;Burrow.RPC&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;
Cheers.

&lt;script language="javascript" type="text/javascript"&gt;SyntaxHighlighter.config.TypeNames = "ISomeService EmailMessage Async RpcTimeToLive User SomeServiceImplementation RpcFactory IRpcRouteFinder IEnumerable IRpcServerCoordinator";&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>Dual-invocation using Autofac interception - AOP</title><link>http://thoai-nguyen.blogspot.com/2012/09/dual-invocation-autofac-interception-aop.html</link><category>Autofac</category><category>Dotnet</category><category>FilterAttribute</category><category>Mock</category><category>Mongo</category><category>UnitTest</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Tue, 11 Sep 2012 15:09:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-5968825435165315732</guid><description>
&lt;br/&gt;
- The project I've been working on used to have SQL as its primary datastore. We're implementing another data store using MongoDB as it will replace the SQL one soon. During the migration process, we have 2 versions of the website running parallel. The production version is using SQL which is viewed by customers and the other one using MongoDB which is being tested by our staff. So once the Mongo version development is finished, it will be kept running in parallel with the SQL version until we're completely confident that all the features are working fine. During that time, any changes made by users to the SQL db have to be applied to MongoDB. 
&lt;br/&gt;&lt;br/&gt;
- There're quite a few solutions in my mind. However, we've had some sort of DataAccess dlls to access Sql database before and another implementation of same interfaces which talk to MongoDB have been implemented. So the options is narrowed down to something like an adapter pattern which takes 2 instances of the same interface, invoke method on the first one and then invoke the same method on the second instance. Being a good fan of &lt;em&gt;Composition over Inheritance&lt;/em&gt;, I was thinking of something like:

&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public class DualService&amp;lt;T&amp;gt; : T
{
    private readonly T _primary;
    private readonly T _secondary;
    
    public DualService(T primary, T secondary)    
    {
        _primary = primary;
        _secondary = secondary;    
    }
    
    public void MethodA()
    {
        _primary.MethodA();
        _secondary.MethodA();    
    }
    
    // So on
}&lt;/pre&gt;
&lt;br/&gt;
- Well, this approach is good only if the generic T interface has just a few methods. Ours has over 30 methods and it keeps counting ;), it's implemented by the "Outsource team" &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/17.gif" /&gt;
So I dropped this option, and thought about the Autofac Interceptor. The intercepter I'm gonna implement will take the secondary implementation and invoke the same method as the invocation if:
&lt;br/&gt;&lt;br/&gt;
&lt;ol class="decimal"&gt;
&lt;li&gt;The method is not decorated by &lt;em&gt;IgnoreInterceptAttribute&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;The method has a result type &lt;em&gt;void&lt;/em&gt;. (Well, a command should not have return type here if you're curios about the reason)&lt;/li&gt;
&lt;li&gt;The method is decorated by &lt;em&gt;DualInvocationAttribute&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br/&gt;
- Here is the implementation. This approach requires &lt;em&gt;Castle.Core&lt;/em&gt; and &lt;em&gt;AutofacContrib.DynamicProxy2&lt;/em&gt;. The 2 attributes are just simple attributes I created to enhance the filter:
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;[AttributeUsage(AttributeTargets.Method)]
public class IgnoreInterceptAttribute : Attribute
{
}

[AttributeUsage(AttributeTargets.Method)]
public class DualInvocationAttribute : Attribute
{
}

public class DualInvocation&amp;lt;T&amp;gt; : IInterceptor where T: class 
{
    private readonly T _secondaryImplementation;
    private readonly Action&amp;lt;Exception&amp;gt; _onSecondaryImplementationInvokeError;

    public DualInvocation(T secondaryImplementation, Action&amp;lt;Exception&amp;gt; onSecondaryImplementationInvokeError = null)
    {
        _secondaryImplementation = secondaryImplementation;
        _onSecondaryImplementationInvokeError = onSecondaryImplementationInvokeError ?? (ex =&amp;gt; Trace.WriteLine(ex));
    }

    public void Intercept(IInvocation invocation)
    {
        invocation.Proceed();
        var returnType = invocation.Method.ReturnType;
        var att = invocation.Method.GetCustomAttributes(typeof(IgnoreInterceptAttribute), true);
        if (att.Any())
        {
            return;
        }

        if (returnType != typeof(void))
        {
            att = invocation.Method.GetCustomAttributes(typeof(DualInvocationAttribute), true);
            if (!att.Any())
            {
                return;
            }
        }

        var methodInfo = invocation.Method;
        try
        {
            methodInfo.Invoke(_secondaryImplementation, invocation.Arguments);
        }
        catch (Exception ex)
        {
            _onSecondaryImplementationInvokeError(ex);
        }
    }
}&lt;/pre&gt;

&lt;br/&gt;
- You might wonder about how to use this class, take a look at the unit tests. You should probably do something either in code or autofac xml config, similar to what I did in the &lt;strong&gt;SetUp&lt;/strong&gt;:
&lt;br/&gt;
- Here is a dummy interface to demonstrate the Autofac registrations
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public interface ISomeService
{
    void Update();

    void Update(int userId);

    [IgnoreIntercept]
    void Update(int userId, bool multi);

    int GetUser(int userId);

    [DualInvocation]
    bool DeleteUser(int userId);
}&lt;/pre&gt;
&lt;br/&gt;
- And here is the tests, the tests are using NSubstitute to mock the interface. (Pretty similar to Moq, etc)
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;[TestFixture]
public class MethodIntercept
{
    private ISomeService primary,
                         secondary;

    private IContainer container;
    private Action&amp;lt;Exception&amp;gt; exceptionHandler;

    [SetUp]
    public void RegisterAutofacComponents()
    {
        primary = Substitute.For&amp;lt;ISomeService&amp;gt;();
        secondary = Substitute.For&amp;lt;ISomeService&amp;gt;();

        var builder = new ContainerBuilder();

        builder.RegisterInstance(secondary).Named&amp;lt;ISomeService&amp;gt;("secondary").SingleInstance();

        builder.RegisterInstance(primary)
               .Named&amp;lt;ISomeService&amp;gt;("primary").SingleInstance()
               .EnableInterfaceInterceptors()
               .InterceptedBy(typeof (DualInvocation&amp;lt;ISomeService&amp;gt;));

        builder.RegisterType&amp;lt;DualInvocation&amp;lt;ISomeService&amp;gt;&amp;gt;()
               .WithParameters(new Parameter[]
               {
                   new ResolvedParameter((p, c) =&amp;gt; p.Name == "secondaryImplementation", (p, c) =&amp;gt; c.ResolveNamed("secondary", typeof (ISomeService))),
                   new NamedParameter("exceptionHandler", exceptionHandler)
               })
               .AsSelf()
               .InstancePerLifetimeScope();

        container = builder.Build();
    }

    [Test]
    public void Should_invoke_secondary_method_if_it_is_not_ignored()
    {
        // Arrange
        var primaryService = container.ResolveNamed&amp;lt;ISomeService&amp;gt;("primary");
        var secondaryService = container.ResolveNamed&amp;lt;ISomeService&amp;gt;("secondary");

        // Action
        primaryService.Update();

        // Assert
        secondaryService.Received(1).Update();
    }

    [Test]
    public void Should_invoke_secondary_overload_method_if_it_is_not_ignored()
    {
        // Arrange
        var primaryService = container.ResolveNamed&amp;lt;ISomeService&amp;gt;("primary");
        var secondaryService = container.ResolveNamed&amp;lt;ISomeService&amp;gt;("secondary");

        // Action
        primaryService.Update(1);

        // Assert
        secondaryService.Received(1).Update(1);
    }

    [Test]
    public void Should_invoke_secondary_overload_method_if_it_is_decorated_by_DualInvocationAttribute()
    {
        // Arrange
        var primaryService = container.ResolveNamed&amp;lt;ISomeService&amp;gt;("primary");
        var secondaryService = container.ResolveNamed&amp;lt;ISomeService&amp;gt;("secondary");

        // Action
        primaryService.DeleteUser(1);

        // Assert
        secondaryService.Received(1).DeleteUser(1);
    }

    [Test]
    public void Should_not_invoke_secondary_method_if_it_is_not_void()
    {
        // Arrange
        var primaryService = container.ResolveNamed&amp;lt;ISomeService&amp;gt;("primary");
        var secondaryService = container.ResolveNamed&amp;lt;ISomeService&amp;gt;("secondary");

        // Action
        primaryService.GetUser(1);

        // Assert
        secondaryService.DidNotReceive().GetUser(Arg.Any&amp;lt;int&amp;gt;());
    }

    [Test]
    public void Should_not_invoke_secondary_method_if_it_is_ignored()
    {
        // Arrange
        var primaryService = container.ResolveNamed&amp;lt;ISomeService&amp;gt;("primary");
        var secondaryService = container.ResolveNamed&amp;lt;ISomeService&amp;gt;("secondary");

        // Action
        primaryService.Update(1, true);

        // Assert
        secondaryService.DidNotReceive().Update(Arg.Any&amp;lt;int&amp;gt;(), Arg.Any&amp;lt;bool&amp;gt;());
    }

    [Test]
    public void Should_not_throw_exception_if_cannot_invoke_secondary_method()
    {
        // Arrange
        exceptionHandler = ex =&amp;gt; Trace.WriteLine(ex);
        secondary.When(x =&amp;gt; x.Update()).Do(callInfo =&amp;gt; { throw new Exception(); });

        var primaryService = container.ResolveNamed&amp;lt;ISomeService&amp;gt;("primary");
        var secondaryService = container.ResolveNamed&amp;lt;ISomeService&amp;gt;("secondary");

        // Action
        primaryService.Update();

        // Assert
        secondaryService.Received(1).Update();
    }
}&lt;/pre&gt;
&lt;br/&gt;&lt;br/&gt;
- I reckon this approach is clean, simple and It works on my machine &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/50.gif" /&gt;. Cheers.




&lt;script language="javascript" type="text/javascript"&gt;SyntaxHighlighter.config.TypeNames = "DualService Attribute AttributeUsage AttributeTargets IgnoreInterceptAttribute DualInvocationAttribute DualInvocation IInterceptor Action Exception IInvocation ISomeService MethodIntercept Substitute ContainerBuilder IgnoreIntercept Trace IContainer ResolvedParameter NamedParameter Parameter";&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></item><item><title>Priority With RabbitMQ implementation in .NET</title><link>http://thoai-nguyen.blogspot.com/2012/07/priority-queue-rabbitmq-burrownet.html</link><category>Burrow.NET</category><category>Dotnet</category><category>RabbitMQ</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Thu, 26 Jul 2012 12:30:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-7294835242564135169</guid><description>&lt;br/&gt;&lt;br/&gt;
- Follow up several &lt;a href="/search/label/Burrow.NET" target="_blank"&gt;posts&lt;/a&gt; about RabbitMQ and Burrow.NET, this post is about the Priority implementation for RabbitMQ in Burrow.NET. Actually, We have it implemented in the library a few weeks ago. However, the code probably has bugs and we need more time to tune and fix those bugs. At this point, I'm confident to say the implementation is quite stable and It's time for a blog post.
&lt;br/&gt;&lt;br/&gt;
- Basically, the implementation is following &lt;a href="http://dougbarth.github.com/2011/07/01/approximating-priority-with-rabbitmq.html" target="_blank"&gt;this post&lt;/a&gt;. We split the logical queue to several physical queues and use a memory queue to aggregate messages from those physical queues. The in-memory-queue is implemented using the IntervalHeap from C5 library and the code rests in side Burrow.Extras package as I hope RabbitMQ will support priority in the future. If they do, it will be the good time to get rid of this implementation without modifying much code in core Burrow.NET core. 
- We've followed the same pattern mentioned in &lt;em&gt;Doug Barth&lt;/em&gt; post. We let each physical queue decide how much unacked messages can be delivered to client using PrefetchSize so if you have n priority, the internal queue will have capacity of &lt;em&gt;n x PrefetchSize&lt;/em&gt;. It will block RabbitMQ from sending more messages to client if the internal memory queue is full so the client has to process and ack messages from high priorty to low priority order and then get more messages.
&lt;br/&gt;&lt;br/&gt;
- The physical queues have the same prefetch size and we would recommend to keep the prefetch size approximately as double as the processing velocity. if you set prefetsize too high compare to the processing velocity, the only drawback we can think of is that the internal memory queue will unnecessary contain so much messages, and that could lead to high memory consumption.
&lt;br/&gt;&lt;br/&gt;
- In our production code, we need 5 priorities so there will be 5 threads created to consume messages from those physical queues. We got several issues with ThreadPool and TPL in our production environment as the window service was getting slow after a while running. We figured out that should never used ThreadPool for long running processing. I'll post about this topic later in Aug but for now if you have a long running window service and it takes time plus lot of IO operations to process your messages, use normal Thread instead of threads from pool. In order to do that, set following line at your BootStrapper:
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;Global.DefaultTaskCreationOptionsProvider = () =&amp;gt; TaskCreationOptions.LongRunning;

&lt;/pre&gt;
&lt;br/&gt;
- This implementation uses an exchange type Header to delivery messages with a priority value to the expected queue. Someone said the exchange Header has lower performance than the others but I'm think it's good because I do need the messages alive after server reboot, that means I need the messages to be persited to disk by setting the PersistentMode to true. That eventually reduces the maximum potential performance of RabbitMQ as mentioned in their docs. Anyway, it's not very difficult to switch to different exchange type such as Topic or Direct if we really need.
&lt;br/&gt;&lt;br/&gt;
- So, here are the steps to setup and consume from the priority queues:
&lt;br/&gt;&lt;br/&gt;
&lt;h4&gt;1/ Declare exchange and queues&lt;/h4&gt;

&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;ExchangeSetupData exchangeSetupData = new HeaderExchangeSetupData();
QueueSetupData queueSetupData = new PriorityQueueSetupData(3)
{
    SubscriptionName = "YourApplicationName", 
};

var connectonString = ConfigurationManager.ConnectionStrings["RabbitMQ"].ToString();
var environment = "PROD";

Func&amp;lt;string, string, IRouteFinder&amp;gt; factory = (environment, exchangeType) =&amp;gt; new YourRouteFinderImplementation();
var setup = new PriorityQueuesRabbitSetup(factory, Global.DefaultWatcher, connectonString, environment);
setup.SetupExchangeAndQueueFor&amp;lt;YourMessageType&amp;gt;(exchangeSetupData, queueSetupData);
&lt;/pre&gt;

&lt;h4&gt;2/ Publish a priority message&lt;/h4&gt;

&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;using(var tunnel = RabbitTunnel.Factory.WithPrioritySupport().Create().WithPrioritySupport())
{
    tunnel.SetSerializer(new JsonSerializer());
    tunnel.SetRouteFinder(new YourRouteFinderImplementation());

    uint priority = 3;

    tunnel.Publish(new YourMessageType() , priority);     
}
&lt;/pre&gt;

&lt;h4&gt;3/ Consume from a logical queue with priority support asynchronously&lt;/h4&gt;

&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;const ushort maxPriorityLevel = 3;
Global.PreFetchSize = 64;
var tunnel = RabbitTunnel.Factory.WithPrioritySupport()
                         .Create().WithPrioritySupport();

tunnel.SubscribeAsync&amp;lt;YourMessageType&amp;gt;("YourApplicationName", maxPriorityLevel, msg =&amp;gt; {
    // Process message here
});
&lt;/pre&gt;

&lt;h4&gt;4/ Consume from a logical queue with priority support synchronously&lt;/h4&gt;

&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;MessageDeliverEventArgs arg = null;
var subscriber = tunnel.Subscribe&amp;lt;YourMessageType&amp;gt;("YourApplicationName", maxPriorityLevel, (msg, eventArgs) =&amp;gt;
{
    arg = eventArgs;
    // Process message here 
});

// Later on
subscriber.Ack(arg.ConsumerTag, arg.DeliveryTag);
&lt;/pre&gt;
&lt;br /&gt;&lt;br /&gt;
Hope it can help someone's problem &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/03.gif" /&gt;
&lt;br /&gt;
Cheers
&lt;script language="javascript" type="text/javascript"&gt;SyntaxHighlighter.config.TypeNames = "RabbitTunnel JsonSerializer YourRouteFinderImplementation YourMessageType Global MessageDeliverEventArgs QueueSetupData ExchangeSetupData HeaderExchangeSetupData ConfigurationManager Func PriorityQueuesRabbitSetup TaskCreationOptions IRouteFinder";&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total></item><item><title>DotNet Hotfix KB 2640103</title><link>http://thoai-nguyen.blogspot.com/2012/07/dotnet-hotfix-kb-2640103.html</link><category>Dotnet</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Mon, 23 Jul 2012 09:28:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-2785250087712097158</guid><description>&lt;br/&gt;
I've a window service which has been running pretty well for a long time. Recently I have installed a .NET framework extended update and it probably caused this error:
&lt;br/&gt;&lt;br/&gt;
&lt;em&gt;Description: The process was terminated due to an internal error in the .NET Runtime at IP 6B484BC2 (6B300000) with exit code &lt;strong class="highlight"&gt;80131506&lt;/strong&gt;&lt;/em&gt;
&lt;br/&gt;&lt;br/&gt;
This error message leads me to this support page: &lt;a href="http://support.microsoft.com/kb/2640103" target="_blank"&gt;http://support.microsoft.com/kb/2640103&lt;/a&gt;. It seems to be so many people got the same problem and they've been trying to download this hot fix. I think Microsoft has not officially released it yet.
&lt;br/&gt;&lt;br/&gt;
So if you met the same problem and need the hot fix, &lt;a href="http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=2640103&amp;kbln=en-us" targe="_blank"&gt;download it here&lt;/a&gt;, more info:
&lt;br/&gt;&lt;br/&gt;
&lt;a href="http://connect.microsoft.com/VisualStudio/feedback/details/720374/faulting-module-name-clr-dll-error-message-when-you-run-a-microsoft-net-framework-4-based-application" target="_blank"&gt;http://connect.microsoft.com/VisualStudio/feedback/details/720374/faulting-module-name-clr-dll-error-message-when-you-run-a-microsoft-net-framework-4-based-application&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;

The problem seems to be fixed after I've installed it as my windows service has been running smoothly for 2 days without crashing. It used to randomly crash within a day.
&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;

Goood luck.
&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">6</thr:total></item><item><title>Programmatically  create RabbitMQ Exchange and Queue with Burrow.NET</title><link>http://thoai-nguyen.blogspot.com/2012/06/programmatically-rabbitmq-exchange.html</link><category>Burrow.NET</category><category>RabbitMQ</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Thu, 14 Jun 2012 15:28:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-8096968426594411536</guid><description>&lt;br /&gt;&lt;br /&gt;
- As mentioned in &lt;a href="/search/label/Burrow.NET" _target="_blank"&gt;previous posts&lt;/a&gt;, IRouteFinder&lt;T&gt; is an interface defined in Burrow.NET to help publishing the message to correct target. If you have many message types, potentially you will need many exchanges and queues. And if it's true, setup everything for different environments or different machines is not an interesting task. So with Burrow.NET we can programmatically create these exchanges, queues and bind them very easy.
&lt;br /&gt;&lt;br /&gt;
- What you need is an implementation of &lt;em&gt;IRouteFinder&lt;/em&gt; which should define your exchange names, queues name based on message type. 
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;class TestRouteFinder : IRouteFinder
{
    public string FindExchangeName&amp;lt;T&amp;gt;()
    {
        return "Burrow.Exchange";
    }

    public string FindRoutingKey&amp;lt;T&amp;gt;()
    {
        return typeof(T).Name;
    }

    public string FindQueueName&amp;lt;T&amp;gt;(string subscriptionName)
    {
        return string.IsNullOrEmpty(subscriptionName)
            ? string.Format("Burrow.Queue.{0}", typeof(T).Name)
            : string.Format("Burrow.Queue.{0}.{1}", subscriptionName, typeof(T).Name);
    }
}
&lt;/pre&gt;
&lt;br /&gt;
- Once having the route finder implemented, write a few lines of code like below:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;var exchangeSetupData = new ExchangeSetupData{ExchangeType = "direct"};   
var queueSetupData = new QueueSetupData {SubscriptionName = "BurrowTestApp", MessageTimeToLive = 100000};

Func&amp;lt;string, string, IRouteFinder&amp;gt; factory = (environment, exchangeType) =&amp;gt; new TestRouteFinder();
var setup = new RabbitSetup(factory, Global.DefaultWatcher, ConfigurationManager.ConnectionStrings["RabbitMQ"].ToString(), "TEST");

setup.SetupExchangeAndQueueFor&amp;lt;YourMessageA&amp;gt;(exchangeSetupData, queueSetupData);
setup.SetupExchangeAndQueueFor&amp;lt;YourMessageB&amp;gt;(exchangeSetupData, queueSetupData);
setup.SetupExchangeAndQueueFor&amp;lt;YourMessageC&amp;gt;(exchangeSetupData, queueSetupData);
&lt;/pre&gt;
&lt;br /&gt;
- &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/50.gif" /&gt; Ofcourse, if you have a predefined exchange and queue names but want to have the same settings for different box you can use built-in &lt;em&gt;ConstantRouteFinder&lt;/em&gt;:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;Func&amp;lt;string, string, IRouteFinder&amp;gt; factory = (environment, exchangeType) =&amp;gt; new ConstantRouteFinder("exchangeName", "queueName", "routingKey");
&lt;/pre&gt;
&lt;br /&gt;
- These code can be run multi times even though the exchanges and queues have've been created before. In practice, I use a application config key/value to determine to run these setup or not. If there have been existing exchanges, queues with the same names but the setting details like &lt;i&gt;ExchangeType, MessageTimeToLive, Durable&lt;/i&gt; are different, running the code against the same server will print out the warning messages that would tell you the settings are different. Please note that different exchange type will lead to unexpected results.&lt;img src="https://dl.dropbox.com/u/81698224/Smilies/stroll.jpg" /&gt;
&lt;br /&gt;&lt;br /&gt;
- For someone who like to write integration tests which need to create the exchanges, queues before a test and destroy everything after the test, you can use the Destroy method:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;Func&amp;lt;string, string, IRouteFinder&amp;gt; factory = (x, y) =&amp;gt; new TestRouteFinder();
var setup = new RabbitSetup(factory, Global.DefaultWatcher, ConfigurationManager.ConnectionStrings["RabbitMQ"].ToString(), "TEST");

setup.Destroy&amp;lt;YourMessageA&amp;gt;(exchangeSetupData, queueSetupData);
setup.Destroy&amp;lt;YourMessageB&amp;gt;(exchangeSetupData, queueSetupData);
setup.Destroy&amp;lt;YourMessageC&amp;gt;(exchangeSetupData, queueSetupData);
&lt;/pre&gt;

&lt;br /&gt;
- This sample code is also available in &lt;a href="https://github.com/vanthoainguyen/Burrow.NET/blob/master/src/Burrow.Publisher/RabbitSetupTest.cs" target="_blank"&gt;Githup project&lt;/a&gt;
&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
Cheers

&lt;script language="javascript" type="text/javascript"&gt;SyntaxHighlighter.config.TypeNames = "TestRouteFinder IRouteFinder ExchangeSetupData QueueSetupData ConfigurationManager Global RabbitSetup ConstantRouteFinder YourMessageA YourMessageB YourMessageC";&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>How I Mock Mongo Collection?</title><link>http://thoai-nguyen.blogspot.com/2012/06/how-i-mock-mongo-collection.html</link><category>Mock</category><category>Mongo</category><category>NSubstitute</category><category>UnitTest</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Wed, 13 Jun 2012 21:51:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-8742596378599158776</guid><description>&lt;br /&gt;
- I have been working with Mongo quite alot recently and writing my service classes using mongo without testing is such a pain in the neck. So today, I'll post about how I mock mongo collection for my unit testings.
&lt;br /&gt;
- Given that I have a &lt;em&gt;ReminderService&lt;/em&gt; like below:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public class ReminderService
{
    private readonly MongoCollection&amp;lt;User&amp;gt; _mongoCollection;
    private readonly INotificationService _notificationService;

    public ReminderService(MongoCollection&amp;lt;User&amp;gt; mongoCollection, INotificationService notificationService)
    {
        _mongoCollection = mongoCollection;
        _notificationService = notificationService;
    }

    public void Send()
    {
        var notActivatedUsers = _mongoCollection.FindAs&amp;lt;User&amp;gt;(Query.EQ("activated", false)).ToList();
        notActivatedUsers.ForEach(user =&amp;gt; _notificationService.Send(new ActivationReminder(user)));
    }
}
&lt;/pre&gt;
&lt;br /&gt;
- It has 1 method Send which needs to be unit tested. This method will find all users who have not their activated account and then send reminder emails to them. This service class is oviously designed for unit testing as it has 2 dependencies: a mongo collection and an interface of INotificationService. To mock the interface, it's straightforward , isn't it? So our job today is mocking this mongo collection.
&lt;br /&gt;&lt;br /&gt;
- Before mocking a class like mongo collection, I often check whether it has &lt;em&gt;virtual&lt;/em&gt; methods because the thing we need to mock here is the method &lt;em&gt;FindAs&lt;/em&gt;. By pressing F12 on the &lt;em&gt;MongoCollection&lt;/em&gt; class to go to assembly metadata, we can easily see that this method is virtual and return a &lt;em&gt;MongoCursor&lt;/em&gt;.
&lt;br /&gt;

&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;// Summary:
//     Returns a cursor that can be used to find all documents in this collection
//     that match the query as TDocuments.
//
// Parameters:
//   query:
//     The query (usually a QueryDocument or constructed using the Query builder).
//
// Type parameters:
//   TDocument:
//     The type to deserialize the documents as.
//
// Returns:
//     A MongoDB.Driver.MongoCursor&amp;lt;TDocument&amp;gt;.
public virtual MongoCursor&amp;lt;TDocument&amp;gt; FindAs&amp;lt;TDocument&amp;gt;(IMongoQuery query);
&lt;/pre&gt;
&lt;br /&gt;
- Hmm, it's getting more complicated here because this method does not return an enumerable or collection but a &lt;em&gt;MongoCursor&amp;lt;TDocument&amp;gt;&lt;/em&gt; and that type inherits from &lt;em&gt;IEnumerable&amp;lt;TDocument&amp;gt;&lt;/em&gt;. So it's telling me that when we call mongoCursor.ToList(), behind the scene, it will call GetEnumerator(). And certainly, checking class &lt;em&gt;MongoCursor&lt;/em&gt;, I see that it's methods are all virtual so it's really open for unit testing.
&lt;br /&gt;&lt;br /&gt;
- To wrap up, the idea will be creating a mock cursor to return expected items and let it be the result of method FindAs on our mock collection. There are other things to note here: mocking a class is not similar to mocking an interface since it has constructor. That means we have to provide the constructor parameters to create a mock object of MongoCollection class. The parameters here are &lt;em&gt;MongoDatabase&lt;/em&gt; and &lt;em&gt;MongoCollectionSettings&amp;lt;TDefaultDocument&amp;gt;&lt;/em&gt;:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;// Summary:
//     Creates a new instance of MongoCollection. Normally you would call one of
//     the indexers or GetCollection methods of MongoDatabase instead.
//
// Parameters:
//   database:
//     The database that contains this collection.
//
//   settings:
//     The settings to use to access this collection.
public MongoCollection(MongoDatabase database, MongoCollectionSettings&amp;lt;TDefaultDocument&amp;gt; settings);
&lt;/pre&gt;
&lt;br /&gt;
- To have a MongoDatabase we need &lt;em&gt;MongoServer&lt;/em&gt; and &lt;em&gt;MongoDatabaseSettings&lt;/em&gt; and so on. So honestly it's not really simple. &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/17.gif" /&gt; I don't want my unit test to talk to real mongo server while running so I must ensure everything runs in memory. I had to create a TestHelper class for these thing, ofcourse for reuse reason:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public static class MongoTestHelpers
{
    private static readonly MongoServerSettings ServerSettings;
    private static readonly MongoServer Server;
    private static readonly MongoDatabaseSettings DatabaseSettings;
    private static readonly MongoDatabase Database;

    static MongoTestHelpers()
    {
        ServerSettings = new MongoServerSettings
        {
            Servers = new List&amp;lt;MongoServerAddress&amp;gt;
            {
                new MongoServerAddress("unittest")
            }
        };
        Server = new MongoServer(ServerSettings);
        DatabaseSettings = new MongoDatabaseSettings("databaseName", new MongoCredentials("", ""), GuidRepresentation.Standard, SafeMode.True, true);
        Database = new MongoDatabase(Server, DatabaseSettings);
    }

    /// &amp;lt;summary&amp;gt;
    /// Creates a mock of mongo collection
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;typeparam name="T"&amp;gt;&amp;lt;/typeparam&amp;gt;
    /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
    /// &amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    public static MongoCollection&amp;lt;T&amp;gt; CreateMockCollection&amp;lt;T&amp;gt;()
    {
        var collectionSetting = new MongoCollectionSettings&amp;lt;T&amp;gt;(Database, typeof(T).Name);
        var m = Substitute.For&amp;lt;MongoCollection&amp;lt;T&amp;gt;&amp;gt;(Database, collectionSetting);
        m.Database.Returns(Database);
        m.Settings.Returns(collectionSetting);
        return m;
    }

    public static MongoCollection&amp;lt;T&amp;gt; ReturnsCollection&amp;lt;T&amp;gt;(this MongoCollection&amp;lt;T&amp;gt; collection, IEnumerable&amp;lt;T&amp;gt; enumerable)
    {
        var cursor = Substitute.For&amp;lt;MongoCursor&amp;lt;T&amp;gt;&amp;gt;(collection, Substitute.For&amp;lt;IMongoQuery&amp;gt;());
        cursor.GetEnumerator().Returns(enumerable.GetEnumerator());
        cursor.When(x =&amp;gt; x.GetEnumerator())
              .Do(callInfo =&amp;gt; enumerable.GetEnumerator().Reset());// Reset Enumerator, incase the method is called multiple times

        cursor.SetSortOrder(Arg.Any&amp;lt;IMongoSortBy&amp;gt;()).Returns(cursor);
        cursor.SetLimit(Arg.Any&amp;lt;int&amp;gt;()).Returns(cursor);
        cursor.SetFields(Arg.Any&amp;lt;IMongoFields&amp;gt;()).Returns(cursor);
        cursor.SetFields(Arg.Any&amp;lt;string[]&amp;gt;()).Returns(cursor);
        cursor.SetFields(Arg.Any&amp;lt;string&amp;gt;()).Returns(cursor);
        cursor.SetSkip(Arg.Any&amp;lt;int&amp;gt;()).Returns(cursor);

        collection.Find(Arg.Any&amp;lt;IMongoQuery&amp;gt;()).Returns(cursor);
        collection.FindAs&amp;lt;T&amp;gt;(Arg.Any&amp;lt;IMongoQuery&amp;gt;()).Returns(cursor);
        collection.FindAll().Returns(cursor);
        // You properly need to setup more methods of cursor here
        
        return collection;
    }
}
&lt;/pre&gt;
&lt;br /&gt;
- There are some interesting points here:
&lt;br /&gt;
&lt;ol class="decimal"&gt;
&lt;li&gt;I'm using &lt;a href="http://nsubstitute.github.com/" target="_blank"&gt;NSubstitute&lt;/a&gt;, hope you understand the syntax. I think the syntax is similar to other frameworks like Moq so it's not a problem if you use different library.&lt;/li&gt;
&lt;li&gt;The code will never talk to real database as I used "unittest" as server address.&lt;/li&gt;
&lt;li&gt;Method ReturnsCollection is an extension method of MongoCollection&amp;lt;T&amp;gt;. We'll use it to specify the items we simulate the result from mongo query. In practice, we might use fluent syntax on mongo cursor object such as SetSortOrder, SetLimit, etc so we definitely don't want these things alter our result. That's why you see there're alot of lines to mock the result for those methods to return the same cursor.&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
- So with this helper, the unit test will look like this:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;[TestFixture]
public class ReminderServiceTests
{
    [Test]
    public void Send_should_send_notification_to_unactivated_users()
    {
        // Arrange
        var mockCollection = MongoTestHelpers.CreateMockCollection&amp;lt;User&amp;gt;();
        mockCollection.ReturnsCollection(new List&amp;lt;User&amp;gt;
        {
            new User {IsActivated = false}, 
            new User {IsActivated = false}
        });
        var notificationService = Substitute.For&amp;lt;INotificationService&amp;gt;();
        var service = new ReminderService(mockCollection, notificationService);

        // Action
        service.Send();

        // Assert
        notificationService.Received(2).Send(Arg.Any&amp;lt;ActivationReminder&amp;gt;());
    }
}
&lt;/pre&gt;
&lt;br /&gt;
- Well, The purpose of this test is guaranteeing that the notification service will send reminders to all unactivated users from database. Because I'm using mongo so the final thing we want to mock is the result set returned by Mongo, we're not testing mongo query here. Hope this help.
&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
Cheers.
&lt;br /&gt;
&lt;script language="javascript" type="text/javascript"&gt;SyntaxHighlighter.config.TypeNames = "List ReminderService MongoCollection INotificationService User Query MongoCursor IMongoQuery MongoDatabase MongoCollectionSettings MongoTestHelpers MongoServer MongoServerSettings MongoDatabaseSettings MongoServerAddress MongoCredentials GuidRepresentation SafeMode IEnumerable ReminderServiceTests Arg IMongoSortBy IMongoFields ActivationReminder";&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total></item><item><title>Save a little time when writing unit test using VS.NET Macro</title><link>http://thoai-nguyen.blogspot.com/2012/06/unit-test-macro-visual-studio-net.html</link><category>UnitTest</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Wed, 6 Jun 2012 21:44:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-2263078707337060164</guid><description>&lt;div style="display:none"&gt;&lt;img src="https://dl.dropbox.com/u/81698224/2012-06-06/BindKey.png" /&gt;&lt;/div&gt;
&lt;br /&gt;
- As a unit testing passioner, I write a lot of unit tests for my code. But repeating adding test attributes to classes and methods, adding resharper ignore InconsistentNaming statement or adding AAA pattern are killing me. &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/21.gif" /&gt;So I thought of making some awesome macros to save my time.
&lt;br /&gt;
- Basically, when I add a test class, the file will originaly be like this:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyProject
{
    class NewTestClass
    {
    }
}
&lt;/pre&gt;
&lt;br /&gt;
- And I want it to be like this after a few key presses: &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/19.gif" /&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

// ReSharper disable InconsistentNaming
namespace MyProject
{
    [TestClass]
    public class NewTestClass
    {
        [TestMethod]
        public void Should_be_implemented_NOW()
        {
            // Arrange


            // Action


            // Assert

        }
    }
}
// ReSharper restore InconsistentNaming
&lt;/pre&gt;
&lt;br /&gt;
- This is archivable with following macros:
&lt;br /&gt;
&lt;pre class="brush: vb; smart-tabs: true; toolbar: false"&gt;Sub CreateTestClassAttribute()
 DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
    DTE.ActiveDocument.Selection.Text = "public "
    DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
    DTE.ActiveDocument.Selection.NewLine()
    DTE.ActiveDocument.Selection.LineUp()
    DTE.ActiveDocument.Selection.Text = "[TestClass]"
    DTE.ActiveDocument.Selection.EndOfLine()
    DTE.ActiveDocument.Selection.LineUp(False, 3)
    DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText, True)
    DTE.ActiveDocument.Selection.Text = "using Microsoft.VisualStudio.TestTools.UnitTesting;"
    DTE.ActiveDocument.Selection.EndOfLine()
    DTE.ActiveDocument.Selection.NewLine()

    DTE.ActiveDocument.Selection.NewLine()
    DTE.ActiveDocument.Selection.Text = "// ReSharper disable InconsistentNaming"
    DTE.ActiveDocument.Selection.EndOfLine()
    DTE.ActiveDocument.Selection.LineDown(False, 8)
    DTE.ActiveDocument.Selection.EndOfLine()
    DTE.ActiveDocument.Selection.Text = "// ReSharper restore InconsistentNaming"
    DTE.ActiveDocument.Selection.LineUp(False, 3)

    CreateTestMethod()
End Sub
Public Sub CreateTestMethod()
    DTE.ActiveDocument.Selection.NewLine()
    DTE.ActiveDocument.Selection.Text = "[TestMethod]"
    DTE.ActiveDocument.Selection.NewLine()
    DTE.ActiveDocument.Selection.Text = "public void Should_be_implemented_now()"
    DTE.ActiveDocument.Selection.NewLine()
    DTE.ActiveDocument.Selection.Text = "{"
    DTE.ActiveDocument.Selection.NewLine()

    DTE.ActiveDocument.Selection.Text = "// Arrange"
    DTE.ActiveDocument.Selection.NewLine(3)

    DTE.ActiveDocument.Selection.Text = "// Action"
    DTE.ActiveDocument.Selection.NewLine(3)

    DTE.ActiveDocument.Selection.Text = "// Assert"
    DTE.ActiveDocument.Selection.NewLine()
    DTE.ActiveDocument.Selection.LineUp(False, 6)
End Sub
&lt;/pre&gt;
&lt;br /&gt;
- Well, the steps are simple:
&lt;br /&gt;
&lt;ol style="list-style-type: decimal; margin-left:25px"&gt;
&lt;li&gt;In your VS.NET click Tool -&gt; Macros -&gt; Macro Explorer and paste these macros to the RecordingModule.&lt;/li&gt;
&lt;li&gt;Choose Tool again -&gt; Options -&gt; Keyboard. Type in Macros, choose these 2 macros and bind your favorite hot key for it like picture below:&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;a href="https://dl.dropbox.com/u/81698224/2012-06-06/BindKey.png" class="fancybox"&gt;&lt;img src="https://dl.dropbox.com/u/81698224/2012-06-06/BindKey.png" /&gt;&lt;/a&gt;
&lt;br /&gt;
- I choose &lt;em&gt;Ctrl F - Ctrl C&lt;/em&gt; to make a test class with first test method and &lt;em&gt; Ctrl F - Ctrl M&lt;/em&gt; to add another Test method.
&lt;br /&gt;
- Hehe, It's DRY principle in unit testing. &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/17.gif" /&gt; I has been using different Unit testing frameworks like NUnit, MBUnit, etc but in this post, I used VS.NET test framework. You properly need to alter the macros a little bit to fit your needs. Now enjoy your tests. Cheers

&lt;br /&gt;

&lt;object style="height: 600px; width: 800px"&gt;&lt;param name="movie" value="http://www.youtube.com/v/JypN6hpgyiI?version=3&amp;feature=player_detailpage"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/JypN6hpgyiI?version=3&amp;feature=player_detailpage" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="800" height="600"&gt;&lt;/object&gt;

&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script language="javascript" type="text/javascript"&gt;SyntaxHighlighter.config.TypeNames = "NewTestClass";&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total></item><item><title>Things you can easily change in Burrow.NET</title><link>http://thoai-nguyen.blogspot.com/2012/06/things-you-can-change-in-burrownet.html</link><category>Burrow.NET</category><category>RabbitMQ</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Sun, 3 Jun 2012 21:29:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-3333327281142819129</guid><description>&lt;br/&gt;&lt;br/&gt;
&lt;p&gt;
- As I said in &lt;a href="/search/label/Burrow.NET"  target="_blank"&gt;other posts&lt;/a&gt;, Burrow.NET aims to generic needs of any .NET projects that use RabbitMQ. I believe the built-in code has covered most of your requirements for common usages. &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/29.gif" /&gt; However there are some things you can easily change without writing any new code or at least just a few lines of code. So in this post, I'll introduce about things you can make to suit your needs when working with RabbitMQ using &lt;a href="/search/label/Burrow.NET"  target="_blank"&gt;Burrow.NET&lt;/a&gt;. 
&lt;/p&gt;
&lt;br/&gt;
&lt;h4&gt;1/ Global.DefaultConsumerBatchSize&lt;/h4&gt;
&lt;p&gt;- The default value of this static property is &lt;em&gt;256&lt;/em&gt;. When you use ITunnel object to asynchronously subscribe to a queue, Burrow.NET use a internal Semaphore object when creating asynchronous Task to handle the messages from the queue. The amount of Tasks it create will depend on this value since it's used as the initialize value for the internal Semaphore. In the mean time, this value is also used to call &lt;em&gt;IModel.BasicQos&lt;/em&gt;, which eventually sets the maximum amount of messages stay on the Unacknowledged list when they are consumed. That's the fetchsize value mentioned in RabbitMQ document and they advise to keep this number as high as double to the acknowledge speed. Therefore, you potentially should adjust this number to fit your need. Moreover, the amount of Tasks and eventualy Threads Burrow.NET create when consumming messages is in proportion to this value and I personally think creating more threads does not make the application run faster. I'll keep monitoring the way it works in my projects so I could split the value for the queue fetch size and the number of concurrent Tasks if it's neccessary but I think so far so good.
&lt;/p&gt;
&lt;br/&gt;
&lt;h4&gt;2/ Global.DefaultPersistentMode&lt;/h4&gt;
&lt;p&gt;- This value is equal to &lt;em&gt;true&lt;/em&gt; by default and is used when creating the ITunnel object. It's eventually used when you publish messages. If the persistent mode is true, the message will be written to disk instead of being kept in memory. So if there is any problem with the server and you have the machine reboot, your messages will be safe. Otherwise, they will be removed when server reboots. However, keeping messages in memory could improve the performance. The DefaultPersistentMode is used to create ITunnel object in TunnelFactory, but you can change it anytime as the ITunnel has a method to do that.&lt;/p&gt;
&lt;br/&gt;
&lt;h4&gt;3/ Global.DefaultErrorExchangeName and Global.DefaultErrorQueueName&lt;/h4&gt;
&lt;p&gt;- The built-in error handler will publish any unhandled exception wrapped in an object and publish to these exchange/queue so you can modify this value to route the error messages to their new home. The default value for the exchange is &lt;em&gt;"Burrow.Exchange.Error"&lt;/em&gt; and &lt;em&gt;"Burrow.Queue.Error"&lt;/em&gt; for the queue.&lt;/p&gt;
&lt;br/&gt;
&lt;h4&gt;4/ Global.DefaultSerializer&lt;/h4&gt;
&lt;p&gt;- This property hold the default value of an &lt;em&gt;JavaScriptSerializer&lt;/em&gt; which is quite slow in performance and cannot handle serialization very well. The reason to have this is to reduce the dependencies to 3rd libraries so you can just use &lt;em&gt;Burrow.dll&lt;/em&gt; without &lt;em&gt;Burrow.Extras.dll&lt;/em&gt;. However, I know everyone likes &lt;em&gt;Json.NET&lt;/em&gt; include me so there is another implementation of ISerializer locates in Burrow.Extras package using Json.NET. It's not the fastest .NET serializer but fast enough for common usages. So I strongly recommend using this one in your project. Again, this value is used to create ITunnel and the ITunnel object will have a method to change that anytime.&lt;/p&gt;

&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;Global.DefaultSerializer = new JsonSerializer();

var tunnel = RabbitTunnel.Factory.Create();
tunnel.SetSerializer(new JsonSerializer());
&lt;/pre&gt;
&lt;br/&gt;
&lt;h4&gt;5/ Global.DefaultWatcher&lt;/h4&gt;
&lt;p&gt;- This one is used to write debug messages from Burrow.NET. The default value is &lt;em&gt;ConsoleWatcher&lt;/em&gt; which writes messages to console so if you're writing a console app, you will easily see those messages. You properly want to change it to anything else such as Log4Net. To do that, simply implement &lt;em&gt;IRabbitWatcher&lt;/em&gt; using Log4net and change the DefaultWatcher when app start.&lt;/p&gt;

&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;Global.DefaultWatcher = new Log4NetRabbitWatcher();
&lt;/pre&gt;

&lt;br/&gt;
&lt;h4&gt;6/ Global.DefaultCorrelationIdGenerator&lt;/h4&gt;
&lt;p&gt;- This one is used to generate the CorrelationId when you publish a message. The default implementation will generate a &lt;em&gt;Guid&lt;/em&gt; and I think it's pretty enough for an Id. You don't have to change that but just do it if you have time and good reason &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/stroll.jpg" /&gt;&lt;/p&gt;
&lt;br/&gt;
&lt;h4&gt;7/ Global.DefaultTypeNameSerializer&lt;/h4&gt;
&lt;p&gt;- Like the CorrelationId, this one is used to generate a string to determine the message when you publish messsags to RabbitMQ. I can think of a case we might need this value is when you just publish any type of message to the queue. When consuming the messages, base on this value you can know the type and deserialie the object. But honestly I've never tried this, neither used this value so if you don't need it in your project, leave it.&lt;/p&gt;


&lt;br/&gt;&lt;br/&gt;
&lt;p&gt;- In conclusion, I put these things in the &lt;em&gt;Global&lt;/em&gt; class just to make it's easier to change the behavior of the ITunnel without touching to the &lt;a href="custom-burrownet-tunnelfactory-rabbitmq.html" target="_blank"&gt;&lt;em&gt;TunnelFactory&lt;/em&gt;&lt;/a&gt; or calling methods on ITunnel object. Things like DefaultWatcher, DefaultTypeNameSerializer and DefaultCorrelationIdGenerator are the bare minimum needs for Burrow.NET and you can simply use the library without worrying about those values. Again, the only thing I suggest to take care of is the &lt;em&gt;DefaultSerializer&lt;/em&gt;, just change it to &lt;em&gt;JsonSerializer&lt;/em&gt; for better performance.&lt;/p&gt;

&lt;br/&gt;&lt;br/&gt;
Cheers.
&lt;script language="javascript" type="text/javascript"&gt;SyntaxHighlighter.config.TypeNames = "Global JsonSerializer RabbitTunnel Log4NetRabbitWatcher";&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total></item><item><title>Custom Burrow.NET TunnelFactory &amp; RabbitMQ</title><link>http://thoai-nguyen.blogspot.com/2012/06/custom-burrownet-tunnelfactory-rabbitmq.html</link><category>Burrow.NET</category><category>DependencyInjection</category><category>RabbitMQ</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Sun, 3 Jun 2012 00:04:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-4756633993398143511</guid><description>&lt;br /&gt;&lt;br /&gt;
&lt;h4&gt;I/ Default TunnelFactory&lt;/h4&gt;

&lt;p&gt;
- When using Burrow.NET, one of the important thing to create is a &lt;em&gt;Tunnel&lt;/em&gt; by using &lt;em&gt;TunnelFactory&lt;/em&gt;:
&lt;/p&gt;

&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;var tunnel = RabbitTunnel.Factory.Create();
&lt;/pre&gt;

&lt;p&gt;
- The Factory static property of RabbitTunnel keeps a default instance of TunnelFactory class. The TunnelFactory has 4 overloads  to create the ITunnel object:
&lt;/p&gt;

&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public virtual ITunnel Create();
public virtual ITunnel Create(string connectionString);
public virtual ITunnel Create(string connectionString, IRabbitWatcher watcher):
public virtual ITunnel Create(string hostName, string virtualHost, string username, string password, IRabbitWatcher watcher):
&lt;/pre&gt;
&lt;br /&gt;
&lt;p&gt;
- They're all virtual so if you want to implement a custom ITunnel, you have things to override. Personally, I don't think of any cases to make a custom ITunnel but just in case you want to change some thing &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/50.gif" /&gt;. These 4 methods are quite straight forward and I think the first one is the simplest one to use since it'll take the RabbitMQ connection string from app.config and create an built-in ITunnel object with built-in dependencies.
&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;
- I intentionally don't create an &lt;em&gt;ITunnelFactory&lt;/em&gt; but only this base class. The reason is I tend to keep only 1 type of TunnelFactory in use in the whole AppDomain. I mean if you create a &lt;em&gt;CustomTunnelFactory&lt;/em&gt; which inherits from class TunnelFactory, you just need to initialize an instance of your class somewhere and this action will automatcally set &lt;em&gt;RabbitTunnel.Factory&lt;/em&gt; to this new factory. That's the only way to change the type of RabbitTunnel.Factory since it does not have public setter. Well you still can create any static classes that have similar methods to create the ITunnel if you want but in my opinion, creating tunnel objects from RabbitTunnel.Factory looks better. &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/14.gif" /&gt;
&lt;/p&gt; 
&lt;br /&gt;
&lt;h4&gt;II/ Implement a custom TunnelFactory and make it as default&lt;/h4&gt;

&lt;p&gt;
- Let's say you want to replace default &lt;em&gt;DefaultRouteFinder&lt;/em&gt; of Burrow.NET and set it your one as the route finder whenever you create an ITunnel. There are at least 2 ways to do that. The first way is creating a custom Factory and override the last method of 4 methods above since that built-in method always use DefaultRouteFinder as RouteFinder. The second way is using &lt;em&gt;DependencyInjectionTunnelFactory&lt;/em&gt;. I'll talk about the 2nd way later in this post. There is another simple method to change the RouteFinder of an ITunnel, that is using the method &lt;span style="font-style:italic"&gt;SetRouteFinder&lt;/span&gt; of ITunnel but in this topic, we're talking about make it as default RouteFinder.
&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;
- This is how to implement the first method:
&lt;/p&gt;

&lt;pre class="brush: csharp; smart-tabs: true; highlight: [21]; toolbar: false"&gt;public class CustomTunnelFactory : TunnelFactory
{
    public override ITunnel Create(string hostName, string virtualHost, string username, string password, IRabbitWatcher watcher)
    {
        var rabbitWatcher = watcher ?? Global.DefaultWatcher;
            var connectionFactory = new RabbitMQ.Client.ConnectionFactory
                                        {
                                            HostName = hostName,
                                            VirtualHost = virtualHost,
                                            UserName = username,
                                            Password = password
                                        };

            var durableConnection = new DurableConnection(new DefaultRetryPolicy(), rabbitWatcher, connectionFactory);
            var errorHandler = new ConsumerErrorHandler(connectionFactory, Global.DefaultSerializer, rabbitWatcher);
            var msgHandlerFactory = new DefaultMessageHandlerFactory(errorHandler, rabbitWatcher);
            var consumerManager = new ConsumerManager(rabbitWatcher, msgHandlerFactory, Global.DefaultSerializer, Global.DefaultConsumerBatchSize);

            return new RabbitTunnel(consumerManager,
                                    rabbitWatcher, 
                                    new CustomRouteFinder(), 
                                    durableConnection,
                                    Global.DefaultSerializer,
                                    Global.DefaultCorrelationIdGenerator,
                                    Global.DefaultPersistentMode);
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;p&gt;
- And here is how to register this as default and use it:
&lt;/p&gt;

&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;// Put this line somewhere when app start:
new CustomTunnelFactory();

// Create your tunnel:
RabbitTunnel.Factory.Create();

// Hmmm, I can't stop you doing this:
(new CustomTunnelFactory()).Create(); // But please, it's such an ugly code
&lt;/pre&gt;
&lt;br /&gt;
&lt;p&gt;
- This first way could possibly require you to read the the original &lt;em&gt;TunnelFactory&lt;/em&gt; source code to know how to replace the route finder. In fact the override method is exactly the same as the base one except the CustomRouteFinder thing. I personally don't like this way since duplication is  always bad. &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/stroll.jpg" /&gt; That's why we have DependencyInjectionTunnelFactory.
&lt;/p&gt;
&lt;br /&gt;
&lt;h4&gt;III/ Dependency Injection Tunnel Factory&lt;/h4&gt;

&lt;p&gt;
- Dependecy Injection is my favorite topic. I like to use libraries that allow me to change behavior easily and I tend to do the same thing in my code. The default &lt;em&gt;RabbitTunnel&lt;/em&gt; class has some dependencies. As it's constructor requires following things:
&lt;/p&gt;
&lt;br /&gt;
&lt;ul style="list-style: square; margin-left:20px"&gt;
&lt;li&gt;IConsumerManager&lt;/li&gt;
&lt;li&gt;IRabbitWatcher&lt;/li&gt;
&lt;li&gt;IRouteFinder&lt;/li&gt;
&lt;li&gt;IDurableConnection&lt;/li&gt;
&lt;li&gt;ISerializer&lt;/li&gt;
&lt;li&gt;ICorrelationIdGenerator&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;p&gt;
- Again, these interfaces have default implementations and I cannot think of any cases that have to change the behavior, but I would not close the door to change it. &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/31.gif" /&gt; The potential behavior you possibly want to change could be the way this library handle error which is implemented in &lt;em&gt;ConsumerErrorHandler&lt;/em&gt; class. There is a long chunk of dependencies to get there so properly using DependencyInjectionTunnelFactory is the easiest way to change the behavior without spending time reading the whole source code. The way DependencyInjectionTunnelFactory works is that it will try to resolve the object it requires. If it cannot find any registed dependencies, it'll use the default one. 
&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;
- To use this factory, you have to implement &lt;em&gt;IBurrowResolver&lt;/em&gt; interface. Basically, it exposes methods like some popular IOC library like Autofac or StructureMap. So if you use Autofac in your project, simply imlement IBurrowResolver and wrap the Autofac's IContainer inside, delegate all methods of IBurrowResolver to IContainer.
&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;
- After have the IBurrowResolver implemented, here is how to use it:
&lt;/p&gt;

&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;RabbitTunnel.Factory.RegisterResolver(new AutofacBurrowResolver());
var tunnel = RabbitTunnel.Factory.Create();
&lt;/pre&gt;
&lt;br /&gt;
&lt;p&gt;
- That's it. Behind the scene, this extension method does exactly what I say above:
&lt;/p&gt;

&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;namespace Burrow.Extras
{
    public static class TunnelFactoryExtensions
    {
        /// &amp;lt;summary&amp;gt;
        /// Call this method to register a dependency resolver and set default TunnelFactory to DependencyInjectionTunnelFactory
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="factory"&amp;gt;&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="burrowResolver"&amp;gt;&amp;lt;/param&amp;gt;
        public static void RegisterResolver(this TunnelFactory factory, IBurrowResolver burrowResolver)
        {
            new DependencyInjectionTunnelFactory(burrowResolver);           
        }
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;p&gt;
- These things are located in &lt;em&gt;Burrow.Extras&lt;/em&gt; so you propably have to grab that &lt;a href="http://nuget.org/packages/Burrow.Extras" target="_blank"&gt;nuget package&lt;/a&gt; to use it. Obviously, you have to register any dependencies before creating any ITunnel. For instance, if you're using Autofac and you want to change the type of RabbitWatcher when creating ITunnel you have to do this first:
&lt;/p&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;var builder = new ContainerBuilder();
builder.RegisterType&amp;lt;CustomRabbitWatcher&amp;gt;()
       .As&amp;lt;IRabbitWatcher&amp;gt;()
       .SingleInstance();
&lt;/pre&gt;
&lt;br /&gt;
&lt;p&gt;       
- And it's pretty similar for other IOC libraries. I use the above &lt;em&gt;RabbitWatcher&lt;/em&gt; replacement thing as an example because there is definitely a simpler way to replace the default watcher type which is setting it to &lt;em&gt;Global&lt;/em&gt; static class. Okey, It's enough for this topic. I would love to hear any suggestions &amp; comments from you to make this better.
&lt;img src="https://dl.dropbox.com/u/81698224/Smilies/09.gif" /&gt;&lt;/p&gt;

&lt;br /&gt;&lt;br /&gt;
Cheers.

&lt;script language="javascript" type="text/javascript"&gt;SyntaxHighlighter.config.TypeNames = "RabbitTunnel ITunnel IRabbitWatcher TunnelFactory CustomTunnelFactory Global  ConnectionFactory DurableConnection DefaultRetryPolicy ConsumerErrorHandler DefaultMessageHandlerFactory ConsumerManager RabbitTunnel CustomRouteFinder CustomTunnelFactory AutofacBurrowResolver TunnelFactoryExtensions DependencyInjectionTunnelFactory CustomRabbitWatcher ContainerBuilder IBurrowResolver";&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>RabbitMQ Exchanges &amp; Queues naming convention with Burrow.NET</title><link>http://thoai-nguyen.blogspot.com/2012/05/rabbitmq-exchange-queue-name-convention.html</link><category>Burrow.NET</category><category>RabbitMQ</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Thu, 31 May 2012 00:24:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-1958350900423222674</guid><description>&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;
- If you just need only 1 exchange and 1 queue, naming convention should not be a big concern. Even that, you may need exchanges and queues for different environments.
As in my projects, I often have 3 environments: DEV, UAT and PROD and I've been using following conventions for exchanges and queues:
&lt;/p&gt;

&lt;br /&gt;

&lt;u&gt;Exchanges&lt;/u&gt;&amp;nbsp;: &lt;em&gt;ProjectName.E.&amp;lt;ExchangeType&amp;gt;.&amp;lt;Environment&amp;gt;.MessageTypeName&lt;/em&gt;&lt;br /&gt;
&lt;u&gt;Queue&lt;/u&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;: &lt;em&gt;ProjectName.Q.&amp;lt;Environment&amp;gt;.&amp;lt;ConsumerName&amp;gt;.MessageTypeName&lt;/em&gt;

&lt;br /&gt;&lt;br /&gt;
&lt;p&gt;
- The consumer name in the Queue convention is optional. It makes sence to have different consumer names for different queues of the same message when Fanout exchange is used. Because at that case, we'll have many clients interested in the same message. We cannot let these clients subcribe to the same queue because only 1 of them will get the message while they all want the same thing. Fanout exchange in that sittuation is a best choice since it will deliver the same copy of the message you publish to all queues bind to it.
&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;
- In below example, we'll use exchange type &lt;strong&gt;Direct&lt;/strong&gt; and we won't need &lt;u&gt;ConsumerName&lt;/u&gt; in the queue name. Then a single message type will have 1 exchange and 1 queue bind to it for every environment. As a result, with message type "RequestMessage" we'll have&lt;/p&gt;
&lt;br /&gt;
&lt;u&gt;Exchanges:&lt;/u&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;ProjectName.E.Direct.DEV.RequestMessage&lt;/li&gt;
&lt;li&gt;ProjectName.E.Direct.UAT.RequestMessage&lt;/li&gt;
&lt;li&gt;ProjectName.E.Direct.PROD.RequestMessage&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;u&gt;Queues:&lt;/u&gt;
&lt;ul&gt;
&lt;li&gt;ProjectName.Q.DEV.RequestMessage&lt;/li&gt;
&lt;li&gt;ProjectName.Q.UAT.RequestMessage&lt;/li&gt;
&lt;li&gt;ProjectName.Q.PROD.RequestMessage&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;a class="fancybox" href="https://dl.dropbox.com/u/81698224/2012-05-30/Binding.png"&gt;
&lt;img src="https://dl.dropbox.com/u/81698224/2012-05-30/Binding.png" style="padding:0px"&gt;&lt;/a&gt;
&lt;br /&gt;
&lt;p&gt;
- Creating queues and exchanges for every single message classes is not a good way as we will polute the server with a long list of queues and exchanges. Indeed, we realized that way as a problem and we've got a few better options. We can use 1 exchange for all those message types and bind different queues to the same exchange by different routing keys. So if we publish a message type &lt;em&gt;RequestA&lt;/em&gt; to the exchange with routing key &lt;em&gt;"RequestA"&lt;/em&gt;, the message will go the queue &lt;em&gt;"ProjectName.PROD.Q.RequestA"&lt;/em&gt; for instance. In our project, we had a need to use Fanout exchange as I mentioned above so we created a wrapper class like below:
&lt;/p&gt;

&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public class MessageWrapper
{
    public object MessageObject {get; set;}
}
&lt;/pre&gt;

&lt;p&gt;
- So we'll have only 1 queue for each client. The message will be deserialized perfectly with the real object as the one we publish so the client can base on the type of MessageObject and determine what to do.
&lt;/p&gt;
&lt;p&gt;
- Back to our story, with this convention in mind, what we have to do is implementing the &lt;em&gt;IRouteFinder&lt;/em&gt;:
&lt;/p&gt;
&lt;a class="fancycode"&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public class MyCustomRouteFinder : IRouteFinder
{
    private readonly string _environment;
    public MyCustomRouteFinder(string environment)
    {
        if (string.IsNullOrEmpty(environment))
        {
            throw new ArgumentNullException(environment);
        }
        _environment = environment;
    }

    public string FindExchangeName&amp;lt;T&amp;gt;()
    {
        return string.Format("ProjectName.E.{0}.{1}.{2}", GetExchangeTypeFor&amp;lt;T&amp;gt;().ToUpper(), _environment, typeof(T).Name);
    }

    public string FindRoutingKey&amp;lt;T&amp;gt;()
    {        
        return typeof(T).Name;
    }

    public string FindQueueName&amp;lt;T&amp;gt;(string subscriptionName)
    {
        if (GetExchangeTypeFor&amp;lt;T&amp;gt;() == ExchangeType.Fanout &amp;&amp; string.IsNullOrEmpty(subscriptionName))
        {
            throw new ArgumentException("subscriptionName");
        }

        var subscription = GetSubscriptionTextFor&amp;lt;T&amp;gt;(subscriptionName);
        
        return !string.IsNullOrEmpty(subscription)
               ? string.Format("ProjectName.Q.{0}.{1}.{2}", _environment, subscription, typeof(T).Name)
               : string.Format("ProjectName.Q.{0}.{1}", _environment, typeof(T).Name);
    }

    protected virtual string GetExchangeTypeFor&amp;lt;T&amp;gt;()
    {
        var messageType = typeof(T);
        var messageTypesNeedDirectExchange = new List&amp;lt;Type&amp;gt; { typeof(MessageA), 
                                                              typeof(MessageB) };

        return messageTypesNeedDirectExchange.Contains(messageType)
             ? ExchangeType.Direct
             : ExchangeType.Fanout;
    }

    protected virtual string GetSubscriptionTextFor&amp;lt;T&amp;gt;(string subscriptionName)
    {
        var typesDontNeedSubscriptionName = new List&amp;lt;Type&amp;gt; { typeof(MessageA), 
                                                             typeof(MessageB) };

        return typesDontNeedSubscriptionName.Contains(typeof(T)) 
             ? null 
             : subscriptionName;
    }
}
&lt;/pre&gt;&lt;/a&gt;
&lt;p&gt;
- Here is how to use it:
&lt;/p&gt;

&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;// Init
var environment = "DEV";
var routeFinder = new MyCustomRouteFinder(environment);
Global.DefaultSerializer = new JsonSerializer();

// Setup exchange and queues programatically
Func&amp;lt;string, string, IRouteFinder&amp;gt; routeFinderFactory = (environment, exchangeType) =&amp;gt; routeFinder;
var setup = new RabbitSetup(routeFinderFactory, 
                            Global.DefaultWatcher, 
                            ConfigurationManager.ConnectionStrings["RabbitMQ"].ToString(), 
                            environment);
setup.SetupExchangeAndQueueFor&amp;lt;MessageA&amp;gt;(new ExchangeSetupData(), new QueueSetupData());
setup.SetupExchangeAndQueueFor&amp;lt;MessageB&amp;gt;(new ExchangeSetupData(), new QueueSetupData());

// Publish message 
using(var tunnel = RabbitTunnel.Factory.Create())
{
    tunnel.SetRouteFinder(routeFinder);
    tunnel.Publish&amp;lt;MessageA&amp;gt;(new MessageA());
    tunnel.Publish&amp;lt;MessageB&amp;gt;(new MessageB());
}
&lt;/pre&gt;

&lt;p&gt;
- And I swear by the moon and the stars in the sky that the messages will go to correct queues. &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/50.gif" style="padding:0px"&gt; In my &lt;a href="http://thoai-nguyen.blogspot.com.au/2012/05/messaging-rabbitmq-and-burrownet.html" target="_blank"&gt;last post&lt;/a&gt;, I'd mentioned the &lt;em&gt;ConstantRouteFinder&lt;/em&gt; which can be used for a predefined exchange name, queue. However, in any cases, I think having a convention is better eventhough we have only 1 queue and exchange. &lt;/p&gt;

&lt;p&gt;
- As a best practice, we should not share the development environment with PROD or UAT environment so the "DEV" exchanges and queues should not be created on the same server as exchanges and queues for "UAT" and "PROD". We should install rabbitmq server on personal machine for development, it won't take so long.&lt;img src="https://dl.dropbox.com/u/81698224/Smilies/17.gif" style="padding:0px"&gt;
&lt;/p&gt;

&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;

Happy messaging. &lt;img src="https://dl.dropbox.com/u/81698224/Smilies/03.gif" style="padding:0px"&gt;

&lt;script language="javascript" type="text/javascript"&gt;SyntaxHighlighter.config.TypeNames = "MessageWrapper MyCustomRouteFinder IRouteFinder ArgumentNullException ArgumentException MessageA MessageB Global Func RabbitSetup ConfigurationManager RabbitTunnel ExchangeType JsonSerializer ExchangeSetupData QueueSetupData List Type";&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total></item><item><title>Messaging with RabbitMQ and Burrow.NET</title><link>http://thoai-nguyen.blogspot.com/2012/05/messaging-rabbitmq-and-burrownet.html</link><category>Burrow.NET</category><category>RabbitMQ</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Wed, 30 May 2012 00:15:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-932846113335904848</guid><description>&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;
- As a .NET developer, what I have known about queueing world is only MSMQ because I've rarely had chances to using queues in any projects. I've known RabbitMQ since my last 2 projects and I'm pretty impressed by it's reliability and stability. RabittMQ is very easy to install on Windows or Linux. I wrote a blog post &lt;a href="http://thoai-nguyen.blogspot.com.au/2012/05/install-rabbitmq-erlang-slitaz-linux.html" target="_blank"&gt;"Install RabbitMQ on SliTaz Linux"&lt;/a&gt; which I described step by step to make a RabbitMQ server on such a very tiny SliTaz Linux distro. It's obviously not the first blog post about RabbitMQ in .NET but I would take this as a opportunity to introduce a part of my project: &lt;a href="https://github.com/vanthoainguyen/Burrow.NET" target="_blank"&gt;Burrow.NET&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
- Burrow.NET is a wrapper library of &lt;a href="http://www.rabbitmq.com/dotnet.html" target="_blank"&gt;RabbitMQ.Client for .NET&lt;/a&gt;. I started this library from EasyNETQ source code and improve the project to fit our usages. However, I have made this library as generic for any project as possible. Basically, Burrow.NET will abstract away the complexity about connection handling, error handling, logging, and recently from &lt;a href="http://nuget.org/packages/Burrow.NET"&gt;version 1.0.8&lt;/a&gt;, I've finished the work around solution for priority queues because RabbitMQ is not natively supporting it. In this post, I'll shortly introduce the very basic features of Burrow.NET and I'll keep other interesting topics for later posts.
&lt;/p&gt;
&lt;h2&gt;I/ Use cases&lt;/h2&gt;
&lt;p&gt;
    1/ Let's say you have to build an async web service to serve a huge amount of clients. A normal basic WCF service host on IIS or Window service does not have capability to handle the big amount of requests. So RabbitMQ acts as a middle layer to queue the requests, you can launch as many instance of &lt;em&gt;"processor application"&lt;/em&gt; to handle the requests as you need. So this way can easily scale in long term.
&lt;/p&gt;
&lt;p&gt;
    2/ You're building a workflow base system that the output of a sub-system will be the input for other system. On other words, your sub-systems need a proper way to asynchronous communicate with each other. Since these sub-systems are different AppDomain so WCF supposes to be a good choice as first sign. However, one like me will not like WCF as an option due to it's configuration complexity. And in this use case, WCF seems not to be a proper solution as we may need scaling for a part or some parts of the system.
&lt;/p&gt;
&lt;p&gt;
- In my personal opinion, whenever you need asynchronous communication between applications, queueing is the best and think about RabbitMQ :D. Well I don't say RabbitMQ is the best. There are alot of mature solutions before RabbitMQ but they came with cost. That's one of the reason why we have the awesome RabbitMQ software and I personaly think RabbitMQ is the best choice, it's fast, it's fashionable, it's free and it works :D.
&lt;/p&gt;
&lt;h2&gt;II/ Burrow.NET&lt;/h2&gt;
&lt;p&gt;
- As the above introduction, this code is a wrapper of .NET RabbitMQ.Client. If you don't want to use wrapper, simply grab RabbitMQ.Client.dll and use it if your need is as simple as publishing a message to a known exchange, queues. However, if you want something consistance like the naming conventions for the whole soultion since you may need alot of queues for the system; or if you expect your application auto reconnect after a connection problem, etc then Burrow.NET is a good candidate. 
&lt;/p&gt;&lt;p&gt;
- I've been using it in my real project which is a big system with different applications comunicate via RabbitMQ channels, I had to make the code as efficient as possible such as establishing only 1 connection for each AppDomain to save the &lt;em&gt;"socket descriptors"&lt;/em&gt;, open only neccesary RabbitMQ channels to save the resources and consume the messages in the queue as fast as possible to keep the server's memory stay low.
&lt;/p&gt;&lt;br /&gt;
Alright, enough promoting. Here is the main topic: &lt;img src="https://a248.e.akamai.net/camo.github.com/fea27716f3efb860240ae6a0fab9619cbbc6f602/687474703a2f2f6934302e74696e797069632e636f6d2f326d34766c32782e6a7067" style="padding: 0px; width:40px"/&gt;
&lt;br /&gt;
&lt;h2&gt;III/ Example&lt;/h2&gt;
&lt;p&gt;
- Asume that you have to build a web service in user case 1. Your web service will not handle the messages immediately but will put the requests to a queue. There will be 1 or many instances of window services which subscribe to that queue and process them. It's not so complicated, isn't it. Firstly grab the RabbitMQ lib either from &lt;a href="http://nuget.org/packages/Burrow.NET" target="_blank"&gt;NUGET&lt;/a&gt; or from &lt;a href="https://github.com/vanthoainguyen/Burrow.NET" target="_blank"&gt;GITHUB&lt;/a&gt;.
&lt;/p&gt;&lt;p&gt;
- In other to push messages to RabbitMQ queue, we're gonna need exchange, queue and binding. I really hope you already known about these things. When you publish a message, you actually send it to the RabbitMQ exchange. And depend on the exchange type, also depend on the queue and binding between that queue and the exchange, your messages will be delivered to the proper queue. RabbitMQ has magic stuff to route your messages to the expected target and believe me, you will love that feature. So let's say we will use following exchange and queue:
&lt;/p&gt;
&lt;u&gt;exchange&lt;/u&gt;: &lt;em&gt;RequestExchange&lt;/em&gt;
&lt;br /&gt;
&lt;u&gt;queue&lt;/u&gt; : &lt;em&gt;RequestQueue&lt;/em&gt;
&lt;p&gt;
- The above exchange type will be &lt;em&gt;"direct"&lt;/em&gt; and the &lt;em&gt;"RequestQueue"&lt;/em&gt; will bind to it with a routing key such as &lt;em&gt;"RequestMessage"&lt;/em&gt;. That means if you publish a request object to that exchange with a routing key &lt;em&gt;"RequestMessage"&lt;/em&gt;, it will eventually go to queue &lt;em&gt;"RequestQueue"&lt;/em&gt;. There are several exchange types, each one will suit different needs and I really recommend you to read about it here: &lt;a href="http://www.rabbitmq.com/tutorials/tutorial-four-python.html" target="_blank"&gt;rabbitmq.com/tutorials/tutorial&lt;/a&gt;.
&lt;/p&gt;&lt;p&gt;
- Since we use the above names which are not any convention at all, we'll use &lt;em&gt;ConstantRouteFinder&lt;/em&gt; in Burrow.NET.
&lt;/p&gt;
&lt;br /&gt;
Here is the code to publish a message:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;var routeFinder = new ConstantRouteFinder("RequestExchange", "RequestQueue", "RequestMessage");
var tunnel = RabbitTunnel.Factory.Create();
tunnel.SetSerializer(new JsonSerializer());
tunnel.SetRouteFinder(routeFinder);
tunnel.Publish&amp;lt;RequestMessage&amp;gt;(new RequestMessage());
&lt;/pre&gt;
To subscribe from the above queue, it's very similar
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;var routeFinder = new ConstantRouteFinder("RequestExchange", "RequestQueue", "RequestMessage");
var tunnel = RabbitTunnel.Factory.Create();
tunnel.SetSerializer(new JsonSerializer());
tunnel.SetRouteFinder(routeFinder);
tunnel.Subscribe&amp;lt;RequestMessage&amp;gt;("RabbitMQDemo", requestMsg =&amp;gt; { 
    // Handle the requestMsg here
});
&lt;/pre&gt;
- Or if you want to asynchronous handle the messages in the queue using multi thread:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;Global.DefaultConsumerBatchSize = 10; // Set the maximum 10 threads
tunnel.SubscribeAsync&amp;lt;RequestMessage&amp;gt;("RabbitMQDemo", requestMsg =&amp;gt; { 
    // Handle the requestMsg here
});
&lt;/pre&gt;
&lt;p&gt;
- There something to note here, the code above create RabbitMQ connection using the connection string in your application config. You'll need something like following lines in your app.config:
&lt;/p&gt;
&lt;pre class="brush: xml; smart-tabs: true; toolbar: false"&gt;&amp;lt;connectionStrings&amp;gt;
    &amp;lt;add name="RabbitMQ" connectionString="host=localhost;username=guest;password=guest"/&amp;gt;
&amp;lt;/connectionStrings&amp;gt;
&lt;/pre&gt;
&lt;p&gt;
- If not, you can use other overloads of &lt;em&gt;RabbitTunnel.Factory&lt;/em&gt; to provide the connection string. The &lt;em&gt;"JsonSerializer"&lt;/em&gt; is the implementation of &lt;em&gt;ISerializer&lt;/em&gt; using Json.NET which is one of the best json serializer for .NET for now. It's currently supporting serializing/deserializing complex object with inheritance hierachy so don't worry about it. 
&lt;/p&gt;&lt;p&gt;
- Burrow.NET has a &lt;em&gt;DefaultRouteFinder&lt;/em&gt; which will generate the queue name, exchange name following a default convention which I don't recommend to use. In fact, if you like this library, implement your own &lt;em&gt;IRouteFinder&lt;/em&gt; and set that instance to the tunnel like the code above. So I'm saying that If you don't use ConstantRouteFinder as above, the code still work but it will create different exchange and queue following built-in convention. You can checkout the latest source code from &lt;a href="https://github.com/vanthoainguyen/Burrow.NET" target="_blank"&gt;GITHUB&lt;/a&gt;, there are 2 demo projects which demonstrate everything about the library, and 1 unit test project which reaches 99% test coverage ^^
&lt;/p&gt;
&lt;p&gt;
&lt;a class="fancybox" href="https://dl.dropbox.com/u/81698224/2012-05-30/Coverage.png"&gt;&lt;img src="https://dl.dropbox.com/u/81698224/2012-05-30/Coverage.png" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
- That's all you need for publishing and subscribing. Other stuff are already handled by the library and you can change those by implement serveral interfaces then inject to the tunnel using your own TunnelFactory. But that would be other topics, now it's time for me to go to bed :D
&lt;/p&gt;
&lt;br /&gt;
Cheers
&lt;br /&gt;&lt;br /&gt;

&lt;img src="https://dl.dropbox.com/u/81698224/2012-05-30/sleep.jpg" style="padding:0px" /&gt;

&lt;script language="javascript" type="text/javascript"&gt;SyntaxHighlighter.config.TypeNames = "ConstantRouteFinder RabbitTunnel JsonSerializer RequestMessage Global";&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">7</thr:total></item><item><title>Install RabbitMQ on SliTaz Linux</title><link>http://thoai-nguyen.blogspot.com/2012/05/install-rabbitmq-erlang-slitaz-linux.html</link><category>Erlang</category><category>Linux</category><category>RabbitMQ</category><category>SliTaz</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Sun, 20 May 2012 01:26:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-7455110752905275833</guid><description>&lt;br /&gt;&lt;br /&gt;
&lt;img src="http://www.rabbitmq.com/img/rabbitmq_logo_strap.png" height="82" /&gt;
&lt;img src="http://t1.gstatic.com/images?q=tbn:ANd9GcRqq2ZsEdFIItGG0OZKBB2pSMqK8fKj9XrV4lLCzwKKqopvAPVS76LFOnE" height="82" /&gt;
&lt;br /&gt;&lt;br /&gt;
- I have played with RabbitMQ for a few months so I tried to install RabbitMQ on a Linux distro running on VMWare. I do this as setting up a development environment at home since I don't want to install so much stuff on my Win7 machine.
And another reason, for fun with Linux things since It's been along time I didn't mess with Linux. Well I did some googling to find some tiny distros. I like simple things that just work and Ubuntu is so fancy for my purpose. 
&lt;br /&gt;&lt;br /&gt;
- &lt;a href="http://www.slitaz.org/" target="_blank"&gt;SliTaz&lt;/a&gt; came out to be the highest rated tiny Linux so I gave it a try. It took me a whole day for trouble shooting problems when install RabbitMQ on this distro. There are quite a few problems such as Erlang version, OpenSSL for mochiweb, and daemon on SliTaz so I think it's worth to write down my experience incase someone likes to do something like this.
&lt;br /&gt;

&lt;h3&gt;1/ The problems&lt;/h3&gt;
&lt;ul&gt; 
&lt;li&gt;RabbitMQ (current &lt;strong&gt;2.8.2&lt;/strong&gt;) requires Erlang &lt;strong&gt;R12B-3&lt;/strong&gt; (&lt;a href="http://www.rabbitmq.com/which-erlang.html" target="_blank"&gt;www.rabbitmq.com/which-erlang.html&lt;/a&gt;). However, &lt;em&gt;mochiweb&lt;/em&gt; requires &lt;strong&gt;R13B01&lt;/strong&gt; which is not available for SliTaz. I could't find any exising packages for Erlang with that version so I had to build OTP version from source which I have never done before :D&lt;/li&gt; 
&lt;li&gt;There is not RabbitMQ package available for SliTaz, so I found out that we can convert from debian package and use within SliTaz.&lt;/li&gt; 
&lt;li&gt;Mochiweb requires OpenSSL so we not only need Erlang source but we also need OpenSSL source. If you check Erlang website, you will see they've mentioned that.&lt;/li&gt; 
&lt;li&gt;I want the RabbitMQ server autostart when system starts but the daemon script for Debian which is installed when you install rabbitmq package does not work. So I have to use "screen" to work around.&lt;/li&gt;
&lt;li&gt;And many many more :D but I promish it will be less pain if you follow these below steps&lt;/li&gt;
&lt;/ul&gt; 

&lt;h3&gt;2/ Installation steps:&lt;/h3&gt;

- Assume that you have install SliTaz successfully (If using VMWare, try use IDE instead of SCSI, I got the problem finding HDD with that) and login as root, the first thing to do is enable SSH on the SliTaz server because it's alot easier using "putty" than "sakura". You'll need to copy and paste something and doing this with putty is damn simple. The SSH server in SliTaz is &lt;em&gt;"dropbear"&lt;/em&gt; and it will not start automatically when system boot so you have to put that to SliTaz "daemon" script. In SliTaz, daemon scripts locate at &lt;em&gt;/etc/init.d/&lt;/em&gt; folder and the primary script is &lt;em&gt;/etc/rcS.conf&lt;/em&gt;. Simply put "dropbear" to the end of &lt;em&gt;RUN_DAEMONS&lt;/em&gt; to make it autostart.
Save the file and reboot.
&lt;br /&gt;&lt;br /&gt;
- When system reboot, SSH to SliTaz server and executing following commands to install &lt;em&gt;make, perl, gcc&lt;/em&gt; and other tools required to compile erlang.
&lt;br /&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;tazpkg get-install make
tazpkg get-install perl
tazpkg get-install gcc
tazpkg get-install slitaz-toolchain --forced
&lt;/pre&gt;
&lt;br /&gt;
- Then we'll get erlang and openssl source, at this time they are latest version.
&lt;br /&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;root@slitaz:/# mkdir /home/temp
root@slitaz:/# mkdir /home/temp/erlang
root@slitaz:/# mkdir /home/temp/openssl

root@slitaz:/# cd /home/temp/openssl
root@slitaz:/home/temp/openssl/# wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
root@slitaz:/home/temp/openssl/# gunzip -c openssl-1.0.1c.tar.gz | tar xf -

root@slitaz:/# cd /home/temp/erlang
root@slitaz:/home/temp/erlang/# wget http://www.erlang.org/download/otp_src_R15B01.tar.gz
root@slitaz:/home/temp/erlang/# gunzip -c otp_src_R15B01.tar.gz | tar xf -
&lt;/pre&gt;

- Now we will config erlang with ssl tag (It's a requirement to use mochiweb)

&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;root@slitaz:/home/temp/erlang/# ./configure --with-ssl=/home/temp/openssl/openssl-1.0.1c
&lt;/pre&gt;
&lt;br /&gt;
- If everything is okey, you'll see this at the end:
&lt;br /&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;..............
config.status: creating Makefile
config.status: creating ../make/i686-pc-linux-gnu/otp.mk
config.status: creating ../make/i686-pc-linux-gnu/otp_ded.mk
config.status: creating ../lib/ic/c_src/i686-pc-linux-gnu/Makefile
config.status: creating ../lib/os_mon/c_src/i686-pc-linux-gnu/Makefile
config.status: creating ../lib/crypto/c_src/i686-pc-linux-gnu/Makefile
config.status: creating ../lib/orber/c_src/i686-pc-linux-gnu/Makefile
config.status: creating ../lib/runtime_tools/c_src/i686-pc-linux-gnu/Makefile
config.status: creating ../lib/tools/c_src/i686-pc-linux-gnu/Makefile
config.status: creating i686-pc-linux-gnu/config.h
config.status: creating include/internal/i686-pc-linux-gnu/ethread_header_config.h
config.status: creating include/i686-pc-linux-gnu/erl_int_sizes_config.h
*********************************************************************
**********************  APPLICATIONS DISABLED  **********************
*********************************************************************

jinterface     : No Java compiler found
odbc           : ODBC library - link check failed

*********************************************************************
*********************************************************************
**********************  APPLICATIONS INFORMATION  *******************
*********************************************************************

wx             : wxWidgets not found, wx will NOT be usable

*********************************************************************
*********************************************************************
**********************  DOCUMENTATION INFORMATION  ******************
*********************************************************************

documentation  :
                 fop is missing.
                 Using fakefop to generate placeholder PDF files.

*********************************************************************
&lt;/pre&gt;
&lt;br /&gt;
- We will &lt;em&gt;make&lt;/em&gt; and &lt;em&gt;install&lt;/em&gt; Erlang:
&lt;br /&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;root@slitaz:/home/temp/erlang/# make

root@slitaz:/home/temp/erlang/# make install
&lt;/pre&gt;
&lt;br /&gt;
- Now, it's time to grab and install rabbitmq package
&lt;br /&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;root@slitaz:/home/temp/erlang/# cd /home/temp
root@slitaz:/home/temp/# mkdir rabbitmq
root@slitaz:/home/temp/# cd rabbitmq

root@slitaz:/home/temp/rabbitmq/# wget http://www.rabbitmq.com/releases/rabbitmq-server/v2.8.2/rabbitmq-server_2.8.2-1_all.deb
root@slitaz:/home/temp/rabbitmq/# tazpkg convert rabbitmq-server_2.8.2-1_all.deb
root@slitaz:/home/temp/rabbitmq/# tazpkg install rabbitmq-server-2.8.2-1.tazpkg
&lt;/pre&gt;
&lt;br /&gt;
- We are almost done. Let's test things by checking &lt;em&gt;rabbitmqctl&lt;/em&gt;
&lt;br /&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;root@slitaz:/# rabbitmqctl
id: unknown user rabbitmq
sh: rabbitmqctl: unknown operand
su: unknown user rabbitmq
&lt;/pre&gt;
&lt;br /&gt;
- Seem like the converted package didn't create user rabbitmq and group rabbitmq for the server. So we have to do it manually:
&lt;br /&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;root@slitaz:/# addgroup rabbitmq
root@slitaz:/# adduser -S rabbitmq -G rabbitmq

root@slitaz:/# rabbitmqctl status
Status of node rabbit@slitaz ...
Error: unable to connect to node rabbit@slitaz: nodedown

DIAGNOSTICS
===========

nodes in question: [rabbit@slitaz]

hosts, their running nodes and ports:
- slitaz: [{rabbitmqctl22218,45733}]

current node details:
- node name: rabbitmqctl22218@slitaz
- home dir: /home/rabbitmq
- cookie hash: vPSQrFu2FNfj5/GsGmwn5A==

root@slitaz:/#
&lt;/pre&gt;
&lt;br /&gt;
- Awesome, it works. Now it's time to start the server:
&lt;br /&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;root@slitaz:/# rabbitmq-server start
/usr/lib/rabbitmq/bin/rabbitmq-server: line 70: can't create /var/lib/rabbitmq/mnesia/rabbit@slitaz.pid: Permission denied
Activating RabbitMQ plugins ...
ERROR: Could not create dir /var/lib/rabbitmq/mnesia/rabbit@slitaz-plugins-expand (eacces)
root@slitaz:/#
&lt;/pre&gt;
&lt;br /&gt;
- Hmm, the user we've created doesn't have permission on that folder. We have to chown:
&lt;br /&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;root@slitaz:/# chown -R rabbitmq:rabbitmq /var/lib/rabbitmq/mnesia

root@slitaz:/# rabbitmq-server start
Activating RabbitMQ plugins ...
0 plugins activated:

{"init terminating in do_boot",{{nocatch,{error,{cannot_log_to_file,"/var/log/rabbitmq/rabbit@slitaz.log",{error,eacces}}}},[{rabbit,ensure_working_log_handler,5,[]},{rabbit,ensure_working_log_handlers,0,[]},{rabbit,prepare,0,[]},{init,eval_script,8,[]},{init,do_boot,3,[]}]}}
init terminating in do_boot ()
&lt;/pre&gt;
&lt;br /&gt;
- Hmm, we'll have to do the same thing for /var/log/rabbitmq
&lt;br /&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;root@slitaz:/# chown -R rabbitmq:rabbitmq /var/log/rabbitmq

root@slitaz:/# rabbitmq-server start
Activating RabbitMQ plugins ...
0 plugins activated:

{"init terminating in do_boot",{{nocatch,{error,{cannot_log_to_file,"/var/log/rabbitmq/rabbit@slitaz.log",{error,eacces}}}},[{rabbit,ensure_working_log_handler,5,[]},{rabbit,ensure_working_log_handlers,0,[]},{rabbit,prepare,0,[]},{init,eval_script,8,[]},{init,do_boot,3,[]}]}}
init terminating in do_boot ()
root@slitaz:/# chown -R rabbitmq:rabbitmq /var/log/rabbitmq
root@slitaz:/# rabbitmq-server start
Activating RabbitMQ plugins ...
0 plugins activated:


+---+   +---+
|   |   |   |
|   |   |   |
|   |   |   |
|   +---+   +-------+
|                   |
| RabbitMQ  +---+   |
|           |   |   |
|   v2.8.2  +---+   |
|                   |
+-------------------+
AMQP 0-9-1 / 0-9 / 0-8
Copyright (C) 2007-2012 VMware, Inc.
Licensed under the MPL.  See http://www.rabbitmq.com/

node           : rabbit@slitaz
app descriptor : /usr/lib/rabbitmq/lib/rabbitmq_server-2.8.2/sbin/../ebin/rabbit.app
home dir       : /home/rabbitmq
config file(s) : (none)
cookie hash    : vPSQrFu2FNfj5/GsGmwn5A==
log            : /var/log/rabbitmq/rabbit@slitaz.log
sasl log       : /var/log/rabbitmq/rabbit@slitaz-sasl.log
database dir   : /var/lib/rabbitmq/mnesia/rabbit@slitaz
erlang version : 5.9.1

-- rabbit boot start
starting file handle cache server                                     ...done
starting worker pool                                                  ...done
starting database                                                     ...done
starting database sync                                                ...done
starting codec correctness check                                      ...done
-- external infrastructure ready
starting plugin registry                                              ...done
starting auth mechanism cr-demo                                       ...done
starting auth mechanism amqplain                                      ...done
starting auth mechanism plain                                         ...done
starting statistics event manager                                     ...done
starting logging server                                               ...done
starting exchange type direct                                         ...done
starting exchange type fanout                                         ...done
starting exchange type headers                                        ...done
starting exchange type topic                                          ...done
-- kernel ready
starting alarm handler                                                ...done
starting node monitor                                                 ...done
starting cluster delegate                                             ...done
starting guid generator                                               ...done
starting memory monitor                                               ...done
-- core initialized
starting empty DB check                                               ...done
starting exchange, queue and binding recovery                         ...done
starting mirror queue slave sup                                       ...done
starting adding mirrors to queues                                     ...done
-- message delivery logic ready
starting error log relay                                              ...done
starting networking                                                   ...done
starting direct client                                                ...done
starting notify cluster nodes                                         ...done

broker running
&lt;/pre&gt;
&lt;br /&gt;
- Muahahaha, it's running without a problem except there are not any plugins available. Press CTRL-C and choose a to stop the server. Then enable the management plugin.
Before that (this is optional), we can manually create a config file for rabbitmq: &lt;em&gt;/etc/rabbitmq/rabbitmq.config&lt;/em&gt;. Hope you know how to use &lt;em&gt;vi&lt;/em&gt; :D. Here i make it use 80% available guest memory and 5GB hard disk for data. You can find out these things on &lt;a href="http://www.rabbitmq.com/memory.html" target="_blank"&gt;rabbitmq memory management website&lt;/a&gt;
&lt;br /&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;[
    {mnesia, [{dump_log_write_threshold, 1000}]},
    {rabbit, [{tcp_listeners, [5672]}, {vm_memory_high_watermark, 0.8}, {disk_free_limit, 5368709120}]}
].
&lt;/pre&gt;
&lt;br /&gt;
&lt;em&gt;The dot at the end of the script is required :D&lt;/em&gt;
&lt;br /&gt;
- To enable management plugin, simply execute 
&lt;br /&gt;
&lt;em&gt;rabbitmq-plugins enable rabbitmq_management&lt;/em&gt;
&lt;br /&gt;
- Finally, we have to let RabbitMQ server auto start when system boot. We'll use screen. First, download and install screen:
&lt;br /&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;root@slitaz:/# tazpkg get-install screen
&lt;/pre&gt;
&lt;br /&gt;
- And create the bash script to start rabbitmq in a screen session, i name it start-rabbitmq.sh and put in /etc/init.d
&lt;br /&gt;
&lt;strong&gt;/etc/init.d/start-rabbitmq.sh&lt;/strong&gt;
&lt;br /&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;PATH=$PATH:/usr/local/bin
export PATH
screen -dmS rabbitmq /usr/sbin/rabbitmq-server start
&lt;/pre&gt;
&lt;br /&gt;
- Obviously, we have to chmod this file
&lt;br /&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;root@slitaz:/# chmod +x /etc/init.d/start-rabbitmq.sh
&lt;/pre&gt;
&lt;br /&gt;
- And the last step, put it to &lt;em&gt;/etc/init.d/local.sh&lt;/em&gt;:
&lt;br /&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;echo "Run rabbitmq startup script"
/etc/init.d/start-rabbitmq.sh
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
- Save and reboot, you have the awesome &lt;em&gt;RabbitMQ&lt;/em&gt; server running on &lt;em&gt;SliTaz&lt;/em&gt;. If you want to use it on internet, find dyndns service and do some port fowarding.
The ports you need to foward are 5672 and 55672, default port for the server and mochiweb.
&lt;br /&gt;&lt;br /&gt;
&lt;img src="http://i48.tinypic.com/xdruo9.png" /&gt;
&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
Cheers</description><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="http://i48.tinypic.com/xdruo9_th.png" width="72"/><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></item><item><title>Transform Web.config for debugging using MsBuild 4.0 and VS.NET 2010</title><link>http://thoai-nguyen.blogspot.com/2012/04/transform-web-configuration-msbuild.html</link><category>Configuration</category><category>MSbuild</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Tue, 24 Apr 2012 17:33:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-555903396928225268</guid><description>&lt;br /&gt;
&lt;br /&gt;
This is the old topic and there are quite a few post about this.
I found following articles are quite helpfull and actually, I based on their help to make a solution that fit my need:
&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/EltonStoneman/archive/2010/08/20/using-msbuild-4.0-web.config-transformation-to-generate-any-config-file.aspx" target="_blank"&gt;http://geekswithblogs.net/EltonStoneman/....aspx&lt;/a&gt;
&lt;br /&gt;
&lt;a href="http://stackoverflow.com/questions/2905151/msbuild-script-and-vs2010-publish-apply-web-config-transform" target="_blank"&gt;http://stackoverflow.com/questions/2905151&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;
Well, in my project, I have a 3 different configuration files which are &lt;em&gt;web.config, appSettings.config&lt;/em&gt; and &lt;em&gt;Autofac.config&lt;/em&gt; that need to be transformed when I debug. There are many settings need to be changed between those configurations so doing it manually is not an interesting job.
&lt;br /&gt;
&lt;br /&gt;
&lt;img src="http://i39.tinypic.com/244xzif.png" /&gt;
&lt;br /&gt;
&lt;br /&gt;
I want a simple solution that can be reused for other project, and on top of it, I don't want to unload my project, put some chunk of Msbuild tasks to it to do the job. Therefore, an external msbuild script seems to be a nice option. Then what I actually need to do is modify the build event of the project to call MsBuild command to transform these things. However, I don't want my hack to affect the build process on server so I use a environment variable which is only available on my machine to enable the transformation.
&lt;br /&gt;
&lt;br /&gt;
So using this way, I have to aware 3 following pointss:
&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Work only for MSbulid 4.0 since I'm using a feature of this version&lt;/li&gt;
&lt;li&gt;The Web.config for instance will be overwrite everytime I build the project, and I should not checkin these changes.&lt;/li&gt;
&lt;li&gt;I should have a Web.Debug.config to switch everthing back to normal in Debug configuration.&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
Here is the Msbuild Script:
&lt;br /&gt;
&lt;pre class="brush: xml; smart-tabs: true; toolbar: false"&gt;&amp;lt;!--  To use:
- Put this file at project folder
- Set DeveloperMachine to enable transforming on current machine, otherwise it will be ignored
- Set following command as the Post build event:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild $(ProjectDir)TransformXml.msbuild /p:ProjectPath=$(ProjectDir);Configuration=$(ConfigurationName);ConfigFile=Web.config
--&amp;gt;
&amp;lt;Project ToolsVersion="4.0"
         DefaultTargets="Execute"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&amp;gt;

    &amp;lt;UsingTask TaskName="TransformXml"
               AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/&amp;gt;

    &amp;lt;PropertyGroup&amp;gt;
        &amp;lt;ProjectPath Condition=" '$(ProjectPath)' == '' "&amp;gt;.\&amp;lt;/ProjectPath&amp;gt;
        &amp;lt;Configuration Condition=" '$(Configuration)' == '' "&amp;gt;Debug&amp;lt;/Configuration&amp;gt;
        &amp;lt;ConfigFile Condition=" '$(ConfigFile)' == '' "&amp;gt;Web.config&amp;lt;/ConfigFile&amp;gt;
        &amp;lt;ConfigFileName&amp;gt;$(ConfigFile.Substring(0, $(ConfigFile.IndexOf('.'))))&amp;lt;/ConfigFileName&amp;gt;
        &amp;lt;ConfigFileExtension&amp;gt;$(ConfigFile.Substring($(ConfigFile.LastIndexOf('.'))))&amp;lt;/ConfigFileExtension&amp;gt;
        &amp;lt;StackTraceEnabled&amp;gt;False&amp;lt;/StackTraceEnabled&amp;gt;
        
        &amp;lt;TransformInputConfigFile&amp;gt;$(TEMP)\$(ConfigFileName)_Temp$(ConfigFileExtension)&amp;lt;/TransformInputConfigFile&amp;gt;
        &amp;lt;TransformConfigFile&amp;gt;$(ProjectPath)$(ConfigFileName).$(Configuration)$(ConfigFileExtension)&amp;lt;/TransformConfigFile&amp;gt;
        &amp;lt;TransformOutputConfigFile&amp;gt;$(ProjectPath)$(ConfigFileName)$(ConfigFileExtension)&amp;lt;/TransformOutputConfigFile&amp;gt;            
    &amp;lt;/PropertyGroup&amp;gt;


    &amp;lt;Target Name="Transform" Condition="'$(DeveloperMachine)' == 'True'" &amp;gt;
        &amp;lt;Copy
            SourceFiles="$(TransformOutputConfigFile)"
            DestinationFiles="$(TransformInputConfigFile)"
            OverwriteReadOnlyFiles="True"
        /&amp;gt;
        
        &amp;lt;TransformXml Source="$(TransformInputConfigFile)"
                      Transform="$(TransformConfigFile)"
                      Destination="$(TransformOutputConfigFile)"
                      StackTrace="$(StackTraceEnabled)" /&amp;gt;                    
        
    &amp;lt;/Target&amp;gt;      
    
    &amp;lt;Target Name="Init" Condition="'$(DeveloperMachine)' != 'True'"&amp;gt;
        &amp;lt;Message Text="Set system environment [DeveloperMachine] to True to transform $(TransformOutputConfigFile) while debugging !!!" /&amp;gt;                
    &amp;lt;/Target&amp;gt;
    
    &amp;lt;Target Name="Execute" DependsOnTargets="Init;Transform" /&amp;gt;        
            
&amp;lt;/Project&amp;gt;
&lt;/pre&gt;
&lt;br /&gt;

As you see in the comment, to use this script:
&lt;ol&gt;
&lt;li&gt;Put this file at project folder&lt;/li&gt;
&lt;li&gt;Set DeveloperMachine to enable transforming on current machine, otherwise it will be ignored&lt;/li&gt;
&lt;li&gt;Set following command as the Post build event:&lt;/li&gt;
&lt;br /&gt;
&lt;em&gt;C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild $(ProjectDir)TransformXml.msbuild /p:ProjectPath=$(ProjectDir);Configuration=$(ConfigurationName);ConfigFile=Web.config&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;br /&gt;
&lt;br /&gt;
Because I have 3 files to transform, I'll have to add 3 lines for these 3 files in my build event.
&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
Cheers.</description><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="http://i39.tinypic.com/244xzif_th.png" width="72"/><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>MVC Enum and Nullable object JSON ModelBinder</title><link>http://thoai-nguyen.blogspot.com/2012/04/mvc-enum-nullable-json-modelbinder.html</link><category>Json</category><category>ModelBinder</category><category>MVC</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Thu, 19 Apr 2012 12:53:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-7284163272193616163</guid><description>&lt;br /&gt;&lt;br /&gt;
&lt;img src="http://i39.tinypic.com/1zlc49g.gif" style="width:10%;border:0px" /&gt; 
&lt;br /&gt;
Warning: This post is quite long with so many unusable code except the last one which is my solution. Stop reading or get your own a cup of tea first :) &lt;img src="http://i40.tinypic.com/2m4vl2x.jpg" border="0" /&gt;
&lt;br /&gt;
&lt;br /&gt;
- When posting Json data to an MVC action method, you could face a problem if you're using numeric values for enum field instead of string representations of the enum names. There are some posts on &lt;a href="http://stackoverflow.com/questions/6051756/model-binding-to-enums-in-asp-net-mvc-3" target="_blank"&gt;stackoverflow.com&lt;/a&gt; to solve this problem but I don't really like it. The problem with that approach is that it can not bind nullable enum, array of enum, etc. Indeed, when trying to solve a problem with Model Binders we could have following options:
&lt;br /&gt;
&lt;ul class="square"&gt;
&lt;li&gt;Override the DefaultModelBinder, if the ModelType to bind is the type we want, do it, otherwise delegate the job the the base class.&lt;/li&gt;
&lt;li&gt;Make a specific ModelBinder for your type.&lt;/li&gt;
&lt;li&gt;Change the way JsonValueProviderFactory works.&lt;/li&gt;
&lt;li&gt;Hack TypeDescripter.&lt;/li&gt;
&lt;li&gt;... potential other options&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
- The first approach is the one used in the stackoverflow post. That seems to be the good one because we could have many enums. The "One size fits all" approach supposes to be the good choice. However, let check out other options first.
&lt;br /&gt;&lt;br /&gt;
- The second option is really good if you have a specific type that MVC does not know how to bind such as &lt;a href="http://www.joe-stevens.com/2011/06/12/model-binding-mongodb-objectid-with-asp-net-mvc/" target="_blank"&gt;Mongo ObjectID&lt;/a&gt;. However, for enum types, this approach is not very convenient because you have to add following line for every single enum type you have in the project:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;ModelBinders.Binders.Add(typeof(YourEnumType), new EnumModelBinder());
&lt;/pre&gt;
&lt;br /&gt;
- I found the third option when I tried to find different ways to solve my problem without using the code in stackoverflow post. Well, by reading the MVC source code and it's quite interesting to see how MVC team make something &lt;em&gt;virtual&lt;/em&gt; but it's not that easy to extend the behavior you need. In short, when you post something to server, the MVC engine will use all registered &lt;em&gt;ValueProviderFactory&lt;/em&gt; to get an &lt;em&gt;IValueProvider&lt;/em&gt;. 
&lt;br /&gt;&lt;br /&gt;
- Obviously, when you post Json, the content type is &lt;em&gt;"application/json"&lt;/em&gt; and nothing but the built-in &lt;em&gt;JsonValueProviderFactory&lt;/em&gt; will return a &lt;em&gt;IValueProvider&lt;/em&gt; which is an object of type &lt;em&gt;DictionaryValueProvider&lt;/em&gt;. There is an interesting point here, if you post an array in JSON, something like &lt;em&gt;{selectedFields:[1,2,3]}&lt;/em&gt;, JsonValueProviderFactory will put following keys/values to the dictionary:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;selectedFields[0] = 1
selectedFields[2] = 2
selectedFields[3] = 3
&lt;/pre&gt;
&lt;br /&gt;
- That potentialy is an issue if lately you want to retrieve the value of that field because the model name here is &lt;strong&gt;selectedFields&lt;/strong&gt;, not &lt;strong&gt;selectedFields[0]&lt;/strong&gt; nor &lt;strong&gt;selectedFields[1]&lt;/strong&gt;. Anyways, that's the way MVC works and I believe if MVC serialize array that way, it can get the values back properly.
&lt;br /&gt;&lt;br /&gt;
- Continue digging into class &lt;em&gt;DictionaryValueProvider&lt;/em&gt;, you will see that it has an &lt;strong&gt;"private readonly" Dictionay&lt;string, ValueProviderResult&gt;&lt;/strong&gt;. &lt;em&gt;ValueProviderResult&lt;/em&gt; is the one I said that has method virtual but there is no really simple way to extend behavior just by overriding methods. I realized that if I override method &lt;em&gt;ConverTo&lt;/em&gt;, I can fix the Enum binding problem here. Here is the code:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;/// &amp;lt;summary&amp;gt;
/// This class is created to fix the Enum parser 
/// &amp;lt;/summary&amp;gt;
public class JsonEnumValueProviderResult : ValueProviderResult
{
    public JsonEnumValueProviderResult(object rawValue, string attemptedValue, CultureInfo culture)
        : base(rawValue, attemptedValue, culture)
    {
    }
    public override object ConvertTo(Type type, CultureInfo culture)
    {
        int rawValue;
        var underlyingType = Nullable.GetUnderlyingType(type);

        if ((type.IsEnum || (underlyingType != null &amp;&amp; underlyingType.IsEnum)) &amp;&amp; int.TryParse(RawValue == null ? "0" : RawValue.ToString(), out rawValue))
        {
            return Enum.ToObject(underlyingType ?? type, rawValue);
        }
        return base.ConvertTo(type, culture);
    }
}
&lt;/pre&gt;
&lt;br /&gt;
As I said, thing is not that simple. I have to somehow make &lt;em&gt;DictionaryValueProvider&lt;/em&gt; use my &lt;em&gt;JsonEnumValueProviderResult&lt;/em&gt; as well. And I would have to create this class:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;/// &amp;lt;summary&amp;gt;
/// Inherit DictionaryValueProvider, just to return JsonEnumValueProviderResult for method GetValue
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;typeparam name="TValue"&amp;gt;&amp;lt;/typeparam&amp;gt;
public class CustomDictionaryValueProvider&amp;lt;TValue&amp;gt; : DictionaryValueProvider&amp;lt;TValue&amp;gt;
{
    private readonly Dictionary&amp;lt;string, JsonEnumValueProviderResult&amp;gt; _values = new Dictionary&amp;lt;string, JsonEnumValueProviderResult&amp;gt;(StringComparer.OrdinalIgnoreCase);

    public CustomDictionaryValueProvider(IDictionary&amp;lt;string, TValue&amp;gt; dictionary, CultureInfo culture)
        : base(dictionary, culture)
    {
        foreach (var entry in dictionary)
        {
            object rawValue = entry.Value;
            string attemptedValue = Convert.ToString(rawValue, culture);
            _values[entry.Key] = new JsonEnumValueProviderResult(rawValue, attemptedValue, culture);
        }
    }

    public override ValueProviderResult GetValue(string key)
    {
        if (key == null)
        {
            throw new ArgumentNullException("key");
        }

        JsonEnumValueProviderResult vpResult;
        _values.TryGetValue(key, out vpResult);
        return vpResult;
    }

}
&lt;/pre&gt;
&lt;br /&gt;
Well, that's still not enough. I have to make &lt;em&gt;JsonValueProviderFactory&lt;/em&gt; to return my &lt;em&gt;CustomDictionaryValueProvider&lt;/em&gt;, either overriding it which is impossible because MVC team sealed this class :( or completly replace it. So if I keen on this approach I have to copy its source code and change only 1 line:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; highlight: [68]; toolbar: false"&gt;/// &amp;lt;summary&amp;gt;
/// JsonValueProviderFactory is sealed. This class is copied from JsonValueProviderFactory and will try to use CustomDictionaryValueProvider
/// &amp;lt;/summary&amp;gt;
public class CustomJsonValueProviderFactory : ValueProviderFactory
{
    private static void AddToBackingStore(Dictionary&amp;lt;string, object&amp;gt; backingStore, string prefix, object value)
    {
        IDictionary&amp;lt;string, object&amp;gt; d = value as IDictionary&amp;lt;string, object&amp;gt;;
        if (d != null)
        {
            foreach (KeyValuePair&amp;lt;string, object&amp;gt; entry in d)
            {
                AddToBackingStore(backingStore, MakePropertyKey(prefix, entry.Key), entry.Value);
            }
            return;
        }

        IList l = value as IList;
        if (l != null)
        {
            for (int i = 0; i &amp;lt; l.Count; i++)
            {
                AddToBackingStore(backingStore, MakeArrayKey(prefix, i), l[i]);
            }
            return;
        }

        // primitive
        backingStore[prefix] = value;
    }

    private static object GetDeserializedObject(ControllerContext controllerContext)
    {
        if (!controllerContext.HttpContext.Request.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
        {
            // not JSON request
            return null;
        }

        StreamReader reader = new StreamReader(controllerContext.HttpContext.Request.InputStream);
        string bodyText = reader.ReadToEnd();
        if (String.IsNullOrEmpty(bodyText))
        {
            // no JSON data
            return null;
        }

        JavaScriptSerializer serializer = new JavaScriptSerializer();
        object jsonData = serializer.DeserializeObject(bodyText);
        return jsonData;
    }

    public override IValueProvider GetValueProvider(ControllerContext controllerContext)
    {
        if (controllerContext == null)
        {
            throw new ArgumentNullException("controllerContext");
        }

        object jsonData = GetDeserializedObject(controllerContext);
        if (jsonData == null)
        {
            return null;
        }

        Dictionary&amp;lt;string, object&amp;gt; backingStore = new Dictionary&amp;lt;string, object&amp;gt;(StringComparer.OrdinalIgnoreCase);
        AddToBackingStore(backingStore, String.Empty, jsonData);
        return new CustomDictionaryValueProvider&amp;lt;object&amp;gt;(backingStore, CultureInfo.CurrentCulture);
    }

    private static string MakeArrayKey(string prefix, int index)
    {
        return prefix + "[" + index.ToString(CultureInfo.InvariantCulture) + "]";
    }

    private static string MakePropertyKey(string prefix, string propertyName)
    {
        return (String.IsNullOrEmpty(prefix)) ? propertyName : prefix + "." + propertyName;
    }
}
&lt;/pre&gt;
&lt;br /&gt;
- So the final step is replace the default &lt;em&gt;JsonValueProviderFactory&lt;/em&gt;:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;var oldFactory = ValueProviderFactories.Factories.FirstOrDefault(x =&amp;gt; x is JsonValueProviderFactory);
if (oldFactory != null)
{
    ValueProviderFactories.Factories.Remove(oldFactory);
}
ValueProviderFactories.Factories.Add(new CustomJsonValueProviderFactory());
&lt;/pre&gt;
&lt;br /&gt;
- It's not fun anymore, I hate to copy source code and change 1 line because I cannot extend it. So let's talk about last option. Again if you look in MVC source code class &lt;em&gt;ValueProviderResult&lt;/em&gt;, you'll see that in method &lt;em&gt;ConvertSimpleType&lt;/em&gt; where it convert simple types like int, enum, etc, It use &lt;em&gt;TypeDescriptor&lt;/em&gt; to get the converter. So I thought If I change that static class, I'll have what I want. And here's the code:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;internal class JsonEnumTypeConverter&amp;lt;T&amp;gt; : TypeConverter
{
    public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
    {
        return (sourceType == typeof(int) || sourceType.IsEnum || sourceType == typeof(string)) &amp;&amp; CanConvertTo(context, typeof(T));
    }

    public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
    {
        if (destinationType.IsEnum)
        {
            return true;
        }

        var underlyingType = Nullable.GetUnderlyingType(destinationType);
        return underlyingType != null &amp;&amp; underlyingType.IsEnum;
    }

    public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
    {
        if (value == null)
        {
            return null;
        }
        try
        {
            int numericValue;
            return int.TryParse(value.ToString(), out numericValue)
                ? Enum.ToObject(typeof(T), numericValue)
                : Enum.Parse(typeof(T), value.ToString());
        }
        catch (Exception)
        {
            return base.ConvertFrom(context, culture, value);
        }
    }
}
&lt;/pre&gt;
&lt;br /&gt;
- But again, I would have to register every single enums in the project which I don't like. So I'll have to get back the the first option which suppose to be the best choice now. Indeed, it works just fine for most scenarios but list of enum, nullable of enum. Futhur more, MVC is not good in handling nullable type like float?, int?. You post &lt;em&gt;{value: 1}&lt;/em&gt; or even &lt;em&gt;{value:1.0}&lt;/em&gt;, you will get null in the float? field. Unless you post &lt;em&gt;{value: '1.0'}&lt;/em&gt; :D. So I'm thinking of getting the underlying type of nullable type then get the binder for that type and bind the value to the underlying type is likely the solution. Here is the code:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public class FixedDefaultModelBinder : DefaultModelBinder
{
    public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        if (bindingContext.ModelType.IsEnum)
        {
            var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
            if (valueProviderResult == null)
            {
                return base.BindModel(controllerContext, bindingContext);
            }

            int numericValue;
            return int.TryParse(valueProviderResult.AttemptedValue, out numericValue)
                ? Enum.ToObject(bindingContext.ModelType, numericValue)
                : Enum.Parse(bindingContext.ModelType, valueProviderResult.AttemptedValue);
        }

        var underlineType = Nullable.GetUnderlyingType(bindingContext.ModelType);
        if (underlineType != null)
        {
            var newBindingContext = new ModelBindingContext(bindingContext)
            {
                ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() =&amp;gt; bindingContext.Model, underlineType),
                ModelName = bindingContext.ModelName
            };
            return ModelBinders.Binders.GetBinder(underlineType).BindModel(controllerContext, newBindingContext);
        }

        return base.BindModel(controllerContext, bindingContext);
    }
}
&lt;/pre&gt;
&lt;div align="center"&gt;&lt;em&gt;&lt;h4&gt;This is the work solution.&lt;/h4&gt;&lt;/em&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
It works :). What you have to do last is setting it as the default model binder:
&lt;br /&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;ModelBinders.Binders.DefaultBinder = new FixedDefaultModelBinder();
&lt;/pre&gt;
&lt;br /&gt;
It's clean and simple, isn't it? Appologise for letting you read through such a long post with so many unusable code except the last one because I was so excited to find out as many ways to solve my project's problem as possible.

&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;

Cheers.

&lt;script language="javascript" type="text/javascript"&gt;SyntaxHighlighter.config.TypeNames = "ModelBinders YourEnumType EnumModelBinder JsonEnumValueProviderResult CultureInfo Nullable Enum CustomDictionaryValueProvider DictionaryValueProvider JsonEnumValueProviderResult StringComparer Dictionary ValueProviderResult IProviderResult CustomJsonValueProviderFactory JsonValueProviderFactory ControllerContext StreamReader JavaScriptSerializer ArgumentNullException ValueProviderFactories JsonEnumTypeConverter TypeConverter ITypeDescriptorContext FixedDefaultModelBinder DefaultModelBinder ModelBindingContext ValueProviderFactory Convert KeyValuePair IValueProvider IDictionary ModelMetadataProviders IList String HttpContext Exception StringComparison Type";&lt;/script&gt;</description><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="http://i39.tinypic.com/1zlc49g_th.gif" width="72"/><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total></item><item><title>Deploy window service artifact to a remote server after a successful build on TeamCity</title><link>http://thoai-nguyen.blogspot.com/2012/04/deploy-windows-service-teamcity-remote.html</link><category>Deployment</category><category>TeamCity</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Wed, 4 Apr 2012 14:46:00 +1000</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-5444525131362664532</guid><description>&lt;br /&gt;
There is a new version of this approach:
&lt;a href="/2012/10/deploy-dot-NET-window-service-TeamCity-Updated.html"&gt;http://thoai-nguyen.blogspot.com.au/2012/10/deploy-dot-NET-window-service-TeamCity-Updated.html&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Deploy window services from TeamCity is such a pain since you don't have something like WebDeploy as deploying a web application. Optopus is a product on the market to do it but I don't want to pay for this simple task. So here is the way I did.
&lt;br/&gt;
&lt;br/&gt;
&lt;strong&gt;Tool&lt;/strong&gt;: powershell, window commands, wget, 7zip
&lt;br/&gt;
&lt;strong&gt;Prerequisite&lt;/strong&gt;: TeamCity server and the remote server have to be &lt;a href="http://technet.microsoft.com/en-us/magazine/ff700227.aspx" target="_blank"&gt;configured to use Remote Commands in Windows PowerShell&lt;/a&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
1/ Config both servers follow the above link. TeamCity server has to be a trusted client to the remote server and vice versa
&lt;br/&gt;&lt;br/&gt;
2/ Download &lt;a href="http://www.gnu.org/software/wget/" target="_blank"&gt;wget&lt;/a&gt; and put somewhere on the remote server such as &lt;em&gt;C:\DeploymentScripts\wget.exe&lt;/em&gt;
&lt;br/&gt;&lt;br/&gt;
3/ Download and install &lt;a href="http://www.7-zip.org/download.html" target="_blank"&gt;7zip&lt;/a&gt; on remote server where you installed your windows service.
&lt;br/&gt;&lt;br/&gt;
4/ Write deployment script and put somewhere on the remote server such as &lt;em&gt;C:\DeploymentScripts\MyApp\deploy.bat&lt;/em&gt;
&lt;br/&gt;&lt;br/&gt;
It can be a powershell script but I decided to use a batch file for simplicity.
&lt;br/&gt;
Basically, the script when triggered, will
&lt;ul&gt;
&lt;li&gt;Use wget to download the latest artifact from TeamCity.&lt;/li&gt;
&lt;li&gt;Use 7zip to extract the artifact, copy it to a temporary folder.&lt;/li&gt;
&lt;li&gt;Save the artifact to Artifacts folder&lt;/li&gt;
&lt;li&gt;Backup the whole current service folder&lt;/li&gt;
&lt;li&gt;Stop target window service&lt;/li&gt;
&lt;li&gt;Copy over new files and old configuration files&lt;/li&gt;
&lt;li&gt;Start target window service&lt;/li&gt;
&lt;li&gt;Clean up&lt;/li&gt;
&lt;/ul&gt;
&lt;br/&gt;
Here is the script, replace some value in the script to match your requirement.
&lt;br/&gt;
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;@echo off:: Deployment scripts for my window service

SETLOCAL
:: 0/ --------- Set some local variables
SET Environment.ExecutingFolder="C:\DeploymentScripts\MyApp"
SET Environment.7zip="C:\Program Files (x86)\7-Zip\7z.exe"
SET Environment.Wget="C:\DeploymentScripts\wget.exe"
SET TeamCity.User=van
SET TeamCity.Password=vanpassword
SET TeamCity.BuildTypeId=bt19
SET TeamCity.Artifact=MyAppService.{build.number}.zip
SET TeamCity.Branch=Default Branch
SET MyApp.TargetFolderName=MyApp.Service
SET MyApp.TargetFolderPath=C:\WhereMyAppInstalled\%MyApp.TargetFolderName%
SET MyApp.ServiceName=MyAppServiceName
SET MyApp.ImageName=MyApp.Service.exe
CD /D %Environment.ExecutingFolder%

 
ECHO 1/ --------- Get latest artifact from TeamCity, MyApp %TeamCity.Branch% ----------------- bt19: build type ID for MyApp on %TeamCity.Branch%
%Environment.Wget% -q --http-user=%TeamCity.User% --http-password=%TeamCity.Password% --auth-no-challenge http://my.teamcity.url.com/repository/download/%TeamCity.BuildTypeId%/.lastSuccessful/%TeamCity.Artifact%
REN *.zip* *.zip
ECHO Found following artifact
DIR /B *zip


ECHO 2/ --------- Extract the artifact to folder __Temp ---------------
%Environment.7zip% e -y -o__Temp *.zip


ECHO 3/ --------- Store the artifact ------------------ 
MOVE /Y *.zip Artifacts\


ECHO 4/ --------- Backup current service folder --------------- 
for %%a in (%MyApp.TargetFolderPath%) do set Temp.LastDate=%%~ta
SET Temp.LastDate=%Temp.LastDate:~6,4%-%Temp.LastDate:~0,2%-%Temp.LastDate:~3,2% %Temp.LastDate:~11,2%%Temp.LastDate:~14,2%%Temp.LastDate:~17,2%
ECHO Last deployment: %Temp.LastDate%
ECHO Now backup files to folder %MyApp.TargetFolderName%.%Temp.LastDate%
XCOPY /E /I /H /R /Y %MyApp.TargetFolderPath% "%MyApp.TargetFolderName%.%Temp.LastDate%"


ECHO 5/ --------- Stop %MyApp.ServiceName% service ---------------
net stop %MyApp.ServiceName%
ECHO Wait 15 seconds
ping 1.1.1.1 -n 1 -w 15000 &gt; nul
ECHO Try to kill the process %MyApp.ImageName% if it's still running
TASKKILL /F /FI "IMAGENAME eq %MyApp.ImageName%" /T &gt; nul

ECHO 6/ --------- Deploy new files &amp; copy over old configs ----------------------
XCOPY /E /H /R /Y __Temp %MyApp.TargetFolderPath%
COPY /Y "%MyApp.TargetFolderName%.%Temp.LastDate%\*.config" %MyApp.TargetFolderPath%


ECHO 7/ --------- Start %MyApp.ServiceName% service ---------------
net start %MyApp.ServiceName%


ECHO 8/ --------- Cleanup --------------------------------- 
RD /S /Q __Temp
ENDLOCAL
&lt;/pre&gt;
&lt;br/&gt;

5/ Open powershell as &lt;strong&gt;Administrator&lt;/strong&gt; on TeamCity server and execute following command:
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;read-host -assecurestring | convertfrom-securestring | out-file C:\Users\Administrator\MyAppSecurePassword.txt
&lt;/pre&gt;
&lt;br/&gt;
Then enter the password for the remote server. The secure password will be stored in the above file. It will then be used by TeamCity for future powershell commands against the remote server.
&lt;br/&gt;&lt;br/&gt;
6/ Go to TeamCity management website, add a new project with 1 step that will execute the following powershell command:
&lt;pre class="brush: bash; smart-tabs: true; toolbar: false"&gt;$username = "Administrator"
$password = cat C:\Users\Administrator\MyAppSecurePassword.txt | convertto-securestring
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
$serverNameOrIp = "xxx.xxx.xxx.xxx"
Invoke-command -computername $serverNameOrIp -ScriptBlock {C:\DeploymentScripts\MyApp\deploy.bat} -Credential $cred
&lt;/pre&gt;
&lt;br/&gt;
Notes:
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Administrator&lt;/em&gt; is the Admin username on the remote server&lt;/li&gt;
&lt;li&gt;&lt;em&gt;C:\Users\Administrator\MyAppSecurePassword.txt&lt;/em&gt; is the secure file that store the secure password we created at step 5.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;serverNameOrIp&lt;/em&gt; value has to be changed to the remote server's ip address where you installed the windows service&lt;/li&gt;
&lt;/ul&gt;
&lt;br/&gt;
So after the code is checked in and successfully built, we can trigger the deployment by clicking "Run" from the above created project.
The &lt;em&gt;deploy.bat&lt;/em&gt; script above can be triggered anytime from the remote server for testing purpose. It's simple enough to read and modify when more steps need to be involved.
&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;
Cheers</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>Setup Tortoise Git and Winmerge</title><link>http://thoai-nguyen.blogspot.com/2012/03/setup-tortoise-git-and-winmerge.html</link><category>Git</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Wed, 14 Mar 2012 16:10:00 +1100</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-1793323135549222716</guid><description>&lt;br /&gt;
Winmerge has been my favorite diff and merge tool for a long time. I always use Winmerge for those purposes so when I use Tortoise softwares like TortoiseSVN, TortoiseHG, Winmerge always is my first option. Now I prefer same thing with GIT. Unlike TortoiseHG which helps you integrate with Winmerge by 1 single click. TortoiseGIT requires some more steps:
&lt;br /&gt;&lt;br /&gt;

&lt;h2&gt;1. For diff tool: &lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Go to Settings&lt;/li&gt;
&lt;li&gt;Click on Diff Viewer node on the left&lt;/li&gt;
&lt;li&gt;Enter following line to the textboxes like the picture below. Remember to choose External for the diff tool:&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;em&gt;C:\Program Files (x86)\WinMerge\WinMergeU.exe /s /e /x /u /wl /maximize /dl %bname /dr %yname %base %mine&lt;/em&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="https://i.imgur.com/w1TUIAR.png" class="fancybox"&gt;&lt;img src="https://i.imgur.com/w1TUIAR.png" alt="Diff Settings" style="width:560px"&gt;&lt;/a&gt;
&lt;br /&gt;
&lt;h2&gt;2. For merge tool:&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Click on Merge Tool node on the left&lt;/li&gt;
&lt;li&gt;Enter following line to the textbox like the picture below. Remember to choose External for the merge tool:&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;em&gt;C:\Program Files (x86)\WinMerge\WinMergeU.exe /maximize /wl /u /s /dl [%tname]-%theirs /dr [%yname]-%mine %theirs %mine %merged&lt;/em&gt;
&lt;br /&gt;&lt;br /&gt;
The parameters can be used are from here: https://tortoisegit.org/docs/tortoisegit/tgit-dug-settings.html
&lt;br /&gt;&lt;br /&gt;
&lt;a href="https://i.imgur.com/bu4CkJj.png" class="fancybox"&gt;&lt;img src="https://i.imgur.com/bu4CkJj.png" alt="Merge Settings" style="width:560px"&gt;&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;
Left panel is readonly. For the merge, any write to the right panel will be applied the merged file.
&lt;br /&gt;
If you're using GitExtensions, you can config WinMerge as the diff tool as well:
&lt;br /&gt;
&lt;em&gt;"C:/Program Files (x86)/WinMerge/WinMergeU.exe" -s -e -x -u -wl -wr -maximize -dl remote:"$REMOTE" -dr local:"$LOCAL" "$REMOTE" "$LOCAL"&lt;/em&gt;
&lt;br /&gt;
Now, enjoy GIT
&lt;br /&gt;
&lt;br /&gt;
Cheers</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></item><item><title>Consume Twitter Stream with OAuth in .NET</title><link>http://thoai-nguyen.blogspot.com/2012/03/consume-twitter-stream-oauth-net.html</link><category>Dotnet</category><category>OAuth</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Tue, 6 Mar 2012 09:32:00 +1100</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-5511514683984149909</guid><description>- Twitter &lt;a href="https://dev.twitter.com/blog/streaming-api-turning-ssl-only-september-29th"&gt;has announced&lt;/a&gt; that they're going to abandon the basic username/password authentication. OAuth seems to be the widely supported authentication standard among many big websites. I have dealed with Yahoo OAuth in the past and to be honest, their documentation is not as good as Twitters. Anyway, in my use case, I won't need to build any fancy UI to ask the users whether they allow my application works on their behalf to access their twitter stream. In other words, I won't need to obtain access tokens because I just want to authorize all my stream requests using OAuth and the access tokens are easily obtained from Twitter dev site. Really good job, Twitter.
&lt;br/&gt;
Now, given that I have got the following tokens from twitter dev site:
&lt;br/&gt;
&lt;ul&gt;
&lt;li&gt;twitterConsumerKey&lt;/li&gt;
&lt;li&gt;twitterConsumerSecret&lt;/li&gt;
&lt;li&gt;twitterAccessToken&lt;/li&gt;
&lt;li&gt;twitterAccessTokenSecret&lt;/li&gt;
&lt;/ul&gt;
What I need to do next is following their &lt;a href="https://dev.twitter.com/docs/auth/authorizing-request" target="_blank"&gt;awesome document&lt;/a&gt; to create the "Authentication" header. And the most important step to have that is &lt;a href="https://dev.twitter.com/docs/auth/creating-signature"&gt;generating the oauth_signature&lt;/a&gt;.
&lt;br/&gt;
They have said very clear about the parameters included in the request. I want to say another point about these parameters: If you're sending a post request, all the parameter value also have to be url encoded.
My case is quite simple, I'm going to use HttpWebRequest object to send OAuth request to Twitter. POST data will be url encoded and sent once the HttpWebRequest object is created. So I need something to authorise the request, something look like:
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public interface IRequestAuthorizer
{
    void Authorize(HttpWebRequest request, string postData);
}&lt;/pre&gt;
&lt;br/&gt;
And here is the implementation:
&lt;br/&gt;
&lt;pre class="brush: csharp; highlight: [59]; smart-tabs: true; toolbar: false"&gt;public class OAuthRequestAuthorizer : OAuthBase, IRequestAuthorizer
{
    private readonly string _twitterConsumerKey;
    private readonly string _twitterConsumerSecret;
    private readonly string _twitterAccessToken;
    private readonly string _twitterAccessTokenSecret;

    public OAuthRequestAuthorizer(string twitterConsumerKey, string twitterConsumerSecret, string twitterAccessToken, string twitterAccessTokenSecret)
    {
        _twitterConsumerKey = twitterConsumerKey;
        _twitterConsumerSecret = twitterConsumerSecret;
        _twitterAccessToken = twitterAccessToken;
        _twitterAccessTokenSecret = twitterAccessTokenSecret;
    }

    public override string GenerateNonce()
    {
        return new Nonce().Value;
    }

    private string BuildHeader(HttpWebRequest request, Uri uri)
    {
        var nonce = GenerateNonce();
        var timeStamp = GenerateTimeStamp();
        
        string normalizedUrl;
        string normalizedRequestParameters;
        
        var httpMethod = request.Method;
        var signature = GenerateSignature(uri, _twitterConsumerKey, _twitterConsumerSecret, _twitterAccessToken, _twitterAccessTokenSecret,
                                          httpMethod, timeStamp, nonce, out normalizedUrl,
                                          out normalizedRequestParameters);

        // https://dev.twitter.com/docs/auth/authorizing-request
        return
            string.Format(
                "OAuth oauth_consumer_key=\"{0}\", " +
                "oauth_nonce=\"{1}\", " +
                "oauth_signature=\"{2}\", " +
                "oauth_signature_method=\"HMAC-SHA1\", " +
                "oauth_timestamp=\"{3}\", " +
                "oauth_token=\"{4}\", " +
                "oauth_version=\"1.0\"", 
                
                UrlEncoder.Encode(_twitterConsumerKey), 
                UrlEncoder.Encode(nonce), 
                UrlEncoder.Encode(signature), 
                UrlEncoder.Encode(timeStamp), 
                UrlEncoder.Encode(_twitterAccessToken));
    }

    public void Authorize(HttpWebRequest request, string postData)
    {
        //NOTE: It's a must to collect all param either in the header/querystring or post body
        var baseUri = string.IsNullOrEmpty(postData) || request.Method.ToUpper() == "GET"
                    ? request.RequestUri
                    : new Uri(string.Format("{0}?{1}", request.RequestUri.AbsoluteUri, postData));

        request.Headers["Authorization"] = BuildHeader(request, baseUri);
    }
}&lt;/pre&gt;
&lt;br/&gt;
Nonce is a custom class I created to generate the unique nonce. You can make your self this unique value like a GUID or a DateTime tick. OAuthBase is the base class I got from &lt;a href="http://oauth.googlecode.com/svn/code/csharp/OAuthBase.cs" target="_blank"&gt;oauth.googlecode.com&lt;/a&gt;. This class did a good job to generate the signature based on what you provide. So utilizing this object will give you the "Authorization" value to put to the request header. UrlEncoder static class is extracted from the UrlEncode method in OAuthBase class. If you encode the Post data as mentioned above, Twitter stream and API is your oyster like they said :D.
&lt;br/&gt;&lt;br/&gt;
Here is the demo code to consume the twitter stream:
&lt;br/&gt;
&lt;pre class="brush: csharp; highlight: [1,13]; smart-tabs: true; toolbar: false"&gt;var postData = "track=" + UrlEncoder.Encode("IPhone,IPad");
var requestContentBuffer = Encoding.UTF8.GetBytes(postData);

var request = (HttpWebRequest)WebRequest.Create(new Uri("https://stream.twitter.com/1/statuses/filter.json"));
request.Method = "POST";
request.ContentLength = requestContentBuffer.Length;
request.ContentType = "application/x-www-form-urlencoded";

request.UserAgent = "OAuthTwitterStream";
request.Headers["Accept-Encoding"] = "deflate, gzip";
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

_requestAuthorizer.Authorize(request, postData);

using (var dataStream = request.GetRequestStream())
{
    dataStream.Write(requestContentBuffer, 0, requestContentBuffer.Length);
}

var apiResponse = (HttpWebResponse) apiRequest.GetResponse();
apiResponseStream = apiResponse.GetResponseStream();

while(true)
{
    var bytesReadCount = apiResponseStream.Read(readBuffer, 0, readBufferSize);
    // Parse Json content
}&lt;/pre&gt;
&lt;br/&gt;
I didn't expect the job would be as simple as this because lastime when I tried to consume Yahoo OAuth service, It took me a while to debug since a small mistake while encoding for example would give you the no clue Unauthorized error :D.
&lt;br/&gt;&lt;br/&gt;
Cheers

&lt;script language="javascript" type="text/javascript"&gt;SyntaxHighlighter.config.TypeNames = "IRequestAuthorizer HttpWebRequest OAuthRequestAuthorizer OAuthBase Nonce UrlEncoder Uri Encoding WebRequest DecompressionMethods HttpWebResponse";&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>Validation in WCF application with NValidator</title><link>http://thoai-nguyen.blogspot.com/2012/01/validation-wcf-with-nvalidator.html</link><category>NValidator</category><category>Validation</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Fri, 27 Jan 2012 14:37:00 +1100</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-1099066615687569222</guid><description>I have been working on a heavy validation messaging project for 3 months. Basically, my company had built a workflow based system to process incoming WCF messages from other business partners. These WCF messages are supposed to be validated before being queued in a RabbitMQ queue store. And I was responsible for implementing the validation stuff for the application. As mentioned in &lt;a href="http://thoai-nguyen.blogspot.com/2011/11/wcf-validation-with-data-annotation.html" target="_blank"&gt;previous post&lt;/a&gt;, I wanted to have something similar to ASP.NET MVC such as Validattion Provider, Validation Factory and using DataAnnotation for message contracts. But after a first draft implementation I has seen some potential issues:
&lt;br/&gt;
&lt;br/&gt;
1/ It's hard to have a clean contract DLL if using DataAnnotation.
The validation logic for the messaging application is quite complicated. We just perform field validation without touching database at this point. However, the rules are so many and quite complicated. So some basic DataAnnotation attributes cannot fit all requirements. Many custom DataAnnotation attributes have been implemented and I don't want to embedded them in the same assembly with the Contracts. As a result, the contract dll had to reference to 1 or 2 other assemblies which contains the custom DataAnnotation classes. I hate this drawback since the contract we built will be provided to other internal teams, even our business partners.
&lt;br/&gt;
&lt;br/&gt;
2/ It's possible but quite ugly to perform cross field validations
Using DataAnnotation, we can only perform validation rules on the "reader property" of a contract. Believe me, it's not gonna work for public field since the TypeDescriptor .NET class couldn't reflect the fields. To perform validation on crossfields, either we implement an attribute and decorate on the class it self, or implement interface IValidatableObject. I don't like both approaches since the first choice seems to be so complicated and not a straightforward way. The second choice pollutes my POCO classes. So, it's the second drawback to give up DataAnnotation
&lt;br/&gt;
&lt;br/&gt;
3/ Validation rules could be different between different trading partners
Using DataAnnotation, the validation logics are tight to the contract classes so it's almost impossible to changes the rules since the data annotation attributes are decorated on the contract's properties or the class itself.
&lt;br/&gt;
&lt;br/&gt;
4/ And similar to the above reason, validation rules should support versioning. DataAnnotation makes it impossible to deploy new validaton logic without compilation the application eventhough we're hardly need this level of support. 
&lt;br/&gt;
&lt;br/&gt;
Based on above reasons, separating the validation logics to different assembly seems to be a proper decision. I implemented &lt;a href="http://nvalidator.codeplex.com/" target="_blank"&gt;NValidator&lt;/a&gt; and changed my code to using NValidator and it works perfectly. The validation errors are so meanningfull and easy to debug. After applying the library a few days, I got 90 bugs regarding these validations but believe me or not, I fixed all of them just in 1 day.
&lt;br/&gt;
&lt;br/&gt;
&lt;pre class="brush: xml; smart-tabs: true; toolbar: false"&gt;&amp;lt;a:Result&amp;gt;
    &amp;lt;a:MessageCreatedDT&amp;gt;20120105 12170001&amp;lt;/a:MessageCreatedDT&amp;gt;
    &amp;lt;a:MessageReceivedDT&amp;gt;20120127 13250974&amp;lt;/a:MessageReceivedDT&amp;gt;
    &amp;lt;a:MessageSuccess&amp;gt;Fail&amp;lt;/a:MessageSuccess&amp;gt;
    &amp;lt;a:ProcessingErrors&amp;gt;
        &amp;lt;a:ProcessingError&amp;gt;   
            &amp;lt;a:ErrorDataField&amp;gt;CreateProfile.ApplicationNumber&amp;lt;/a:ErrorDataField&amp;gt;
            &amp;lt;a:ErrorDescription&amp;gt;ApplicationNumber is not a valid application number. Received value: "abcdef"&amp;lt;/a:ErrorDescription&amp;gt;
            &amp;lt;a:ErrorUniqueID&amp;gt;2d31f33f-44df-48aa-a682-61e3ca7d5566&amp;lt;/a:ErrorUniqueID&amp;gt;
        &amp;lt;/a:ProcessingError&amp;gt;
        &amp;lt;a:ProcessingError&amp;gt;   
            &amp;lt;a:ErrorDataField&amp;gt;CreateProfile.Entities[0].CompanyName&amp;lt;/a:ErrorDataField&amp;gt;
            &amp;lt;a:ErrorDescription&amp;gt;CompanyName must be null because ‘Entity Type’ = “Person”. Received value: ""&amp;lt;/a:ErrorDescription&amp;gt;
            &amp;lt;a:ErrorUniqueID&amp;gt;854e68c1-7604-412f-991c-20a6fc31b611&amp;lt;/a:ErrorUniqueID&amp;gt;
        &amp;lt;/a:ProcessingError&amp;gt;
        &amp;lt;a:ProcessingError&amp;gt;   
            &amp;lt;a:ErrorDataField&amp;gt;CreateProfile.Entities[1].CompanyName&amp;lt;/a:ErrorDataField&amp;gt;
            &amp;lt;a:ErrorDescription&amp;gt;Mandatory because ‘Entity Type’ = “Company”. Received value: ""&amp;lt;/a:ErrorDescription&amp;gt;
            &amp;lt;a:ErrorUniqueID&amp;gt;cca94d9d-6ea5-4846-8109-091285ae03e4&amp;lt;/a:ErrorUniqueID&amp;gt;
        &amp;lt;/a:ProcessingError&amp;gt;
    &amp;lt;/a:ProcessingErrors&amp;gt;
&amp;lt;/a:Result&amp;gt;
&lt;/pre&gt;

&lt;br/&gt;
Above is a sample message response when validation fails. The 2 last erros are examples of cross field validation. If EntityType = "Person" the CompanyName must be null. CompanyName is mandatory if EntityType = "Company".
&lt;br/&gt;
Reading enough? Here are the steps for using NValidator for validation on WCF service:
&lt;br/&gt;
&lt;ol&gt;
&lt;li&gt;Assume that you have your contract defined in an assembly, add another class library project just for validation rules. Using &lt;a href="http://nuget.org/packages/NValidator" target="_blank"&gt;Nuget to get latest NValidator&lt;/a&gt; and add your validator classes.&lt;/li&gt;
&lt;li&gt;Register your validator classes in the application bootstrapper or anywhere of your app where the code is executed before other stuff.&lt;/li&gt;
&lt;li&gt;Create a validation attribute to decorate on your WCF service. The method is pretty similar to &lt;a href="http://thoai-nguyen.blogspot.com/2011/11/wcf-validation-with-data-annotation.html" target="_blank"&gt;this post&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;br/&gt;

And here is the code. In this demo, I want to print out the value of the validated object so I create a custom Validation result as below. You don't have to do this if you don't want this function. The default ValidationResult and ValidationBuilder work just fine

&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public class CustomValidationResult : FormattableMessageResult
{
    public CustomValidationResult() : base(new Dictionary&amp;lt;string, object&amp;gt;())
    {
    }

    public CustomValidationResult(ValidationResult originalResult)
        : base(originalResult is FormattableMessageResult
                ? (originalResult as FormattableMessageResult).Params
                : new Dictionary&amp;lt;string, object&amp;gt;())
    {
        CopyValues(originalResult);
    }

    private void CopyValues(ValidationResult originalResult)
    {
        var customValidationResult = originalResult as CustomValidationResult;
        MemberName = originalResult.MemberName;
        Message = originalResult.Message;
        PropertyName = originalResult.PropertyName;

        if (customValidationResult != null &amp;&amp; customValidationResult.ValidatedValueWasSet)
        {
            ValidatedValue = customValidationResult.ValidatedValue;
        }
    }

    public bool ValidatedValueWasSet { get; private set; }

    private object _validatedValue;
    public object ValidatedValue
    {
        get
        {
            return _validatedValue;
        }
        set
        {
            if (!ValidatedValueWasSet)
            {
                _validatedValue = value;
                ValidatedValueWasSet = true;
            }
        }
    }
}
&lt;/pre&gt;
&lt;br/&gt;
I also have to make a customization of ValidationBuilder to make it return my custom ValidationResult:
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;/// &amp;lt;summary&amp;gt;
/// This class customizes the behavior of ValidationBuilder and return CustomValidationResult
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;typeparam name="T"&amp;gt;&amp;lt;/typeparam&amp;gt;
/// &amp;lt;typeparam name="TProperty"&amp;gt;The type of the property.&amp;lt;/typeparam&amp;gt;
public class CustomValidationBuilder&amp;lt;T, TProperty&amp;gt; : ValidationBuilder&amp;lt;T, TProperty&amp;gt;
{
    private object _validatedObject;
    public CustomValidationBuilder(Expression&amp;lt;Func&amp;lt;T, TProperty&amp;gt;&amp;gt; expression)
        : base(expression)
    {
    }

    protected override NValidator.ValidationResult FormatValidationResult(NValidator.ValidationResult result, string propertyChain)
    {
        var baseResult = base.FormatValidationResult(result, propertyChain);
        var customResult = new CustomValidationResult(baseResult);
        if (!customResult.ValidatedValueWasSet)
        {
            customResult.ValidatedValue = _validatedObject;
        }
        return customResult;
    }

    protected override object GetObjectToValidate(T value)
    {
        _validatedObject = base.GetObjectToValidate(value);
        return _validatedObject;
    }
}
&lt;/pre&gt;
&lt;br/&gt;
And here is the ParameterValidatorBehavior which invokes validation on every WCF message call:
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;public class ParameterValidatorBehavior : IParameterInspector
{
    public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
    {
    }

    public object BeforeCall(string operationName, object[] inputs)
    {
        // validate parameters before call
        var validationResults = new List&amp;lt;ValidationResult&amp;gt;();
        var serviceIntance = OperationContext.Current.InstanceContext.GetServiceInstance();
        if (serviceIntance != null)
        {
            foreach (var input in inputs)
            {
                if (input != null)
                {
                    var validator = ValidatorFactory.Current.GetValidatorFor(input.GetType());
                    if (validator == null)
                    {
                        ColorConsole.WriteLine(ConsoleColor.Yellow, "Validator for {0} not found.", input.GetType().Name);
                        continue;
                    }
                    validationResults.AddRange(validator.GetValidationResult(input));
                }
            }
            if (validationResults.Count &amp;gt; 0)
            {
                throw new FaultException&amp;lt;ValidationFault&amp;gt;(new ValidationFault(validationResults), "Validation error");
            }
        }
        return null;
    }
}
&lt;/pre&gt;
&lt;br/&gt;
As mentioned in the &lt;a href="http://nvalidator.codeplex.com/wikipage?title=ValidatorBuilder&amp;referringTitle=Table%20of%20contents" target="_blank"&gt;NValidator topic&lt;/a&gt;, the above CustomValidationBuilder has to be registered in BootStrapper:
&lt;br/&gt;
&lt;pre class="brush: csharp; smart-tabs: true; toolbar: false"&gt;internal class BootStrapper
{
    public static void Start()
    {
        ValidatorFactory.Config.DefaultValidationBuilderType = typeof (CustomValidationBuilder&amp;lt;,&amp;gt;);

        ValidatorFactory.Current.Register&amp;lt;OrderValidator&amp;gt;(true);
        ValidatorFactory.Current.Register&amp;lt;OrderDetailValidator&amp;gt;(true);
    }
}
&lt;/pre&gt;
&lt;br/&gt;
That cannot be easier. Again, the full source code can be check out here at &lt;a href="https://github.com/vanthoainguyen/Blog/tree/master/NValidatorDemo" target="_blank"&gt;GitHub&lt;/a&gt;.
Cheers.

&lt;script language="javascript" type="text/javascript"&gt;SyntaxHighlighter.config.TypeNames = "CustomValidationResult FormattableMessageResult Dictionary ValidationResult CustomValidationBuilder ValidationBuilder Expression Func ParameterValidatorBehavior IParameterInspector OperationContext ValidatorFactory BootStrapper OrderValidator OrderDetailValidator FaultException ValidationFault";&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total></item><item><title>Is Repository old skool?</title><link>http://thoai-nguyen.blogspot.com/2012/01/is-repository-old-skool.html</link><category>Dotnet</category><category>Repository</category><author>noreply@blogger.com (Anonymous)</author><pubDate>Thu, 19 Jan 2012 16:44:00 +1100</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-6734369634474697600.post-363033812428187836</guid><description>I used to be a fan of Repository pattern, DAO, DAL whatever they're called. I have tried many different approaches for this pattern and normally end up at a DAO object rather than a pure generic Repository. However, I still fooled myself that it was my bad design of Repository pattern and there must be a better design somewhere. More than two years ago, I saw &lt;a href="http://huyrua.wordpress.com/2011/04/13/entity-framework-4-poco-repository-and-specification-pattern-upgraded-to-ef-4-1" target="_blank"&gt;code of my elder colleague&lt;/a&gt; about his design of database abstraction layer. He used Specificication pattern together with the Generic Repository on top of Entity Framework. I talked to myself, what the hell is specification and why on earth would we want to use it when we have LinQ built in in the language. Hmm, I might be wrong at time time and now I know I was properly wrong. Recently, I'm watching &lt;a href="http://ayende.com/blog/153153/northwind-starter-kit-review-refactoring-to-an-actual-read-model" target="_blank"&gt;a interesting argument&lt;/a&gt; among many blog readers on a topic of Oren's blog. Basically, they're arguing about whether we should use Repository Pattern. I'm confused about the trend of community on this topic so I decided to ask my 2 experienced colleagues. Here are their responses:
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;
I don’t tend to use them these days ...
&lt;br /&gt;&lt;br /&gt;
A Repository in concept is “an in-memory list” for all intents and purposes ... the problem is they are almost always written as “a generic data access layer”. The main problem is that Repositories should only *ever* be for an Aggregate Root, and therefore handle all data access for all child objects too. Ours are a nasty generic data access layer pretending to be a repository.
&lt;br /&gt;&lt;br /&gt;
Personally I usually favour QueryObjects for querying and CommandObjects for writing
&lt;br /&gt;&lt;br /&gt;
In this case a QueryObject knows how to do one query or projection (which may involve database calls), and returns either DTOs or domain entities
&lt;br /&gt;&lt;br /&gt;
A CommandObject knows how to do one single operation, which may involve multiple database calls), and returns Void
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
Or as I think Oren advocates later on, I would just let the NH objects into the domain these days – nobody ever replaced a data layer 
&lt;/em&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;a href="http://devlicio.us/blogs/casey/" target="_blank"&gt;Jak Charlton&lt;/a&gt;&lt;/strong&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;
I usually, but not always, tend to judge the repository pattern as an anti-pattern and an unnecessary additional layer of abstraction, complexity and maintenance.  It's quite useful if you're going to need to swap out your storage platform at some point, say SQL Server for Oracle or MongoDB, but even then there are often underlying specific implementation differences between platforms that break the abstraction compatibility, so you end up needing to redesign the repository's API contract and break compatibility.  A generic repository that works across several storage platforms must be very generalised, and isn't able to leverage specific features of a particular technology.
&lt;br /&gt;&lt;br /&gt;
This only applies to a generic repository, I see less harm in it when applied more specifically, like EF which provides a good storage abstraction and API over relational databases.
&lt;br /&gt;&lt;br /&gt;
As always, it depends.  I currently tend to design for a service layer that directly uses a mirco-ORM for SQL Server, and other data access libraries specific to their storage type, like the .NET MongoDB driver.
&lt;/em&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;a href="http://chrisfulstow.com" target="_blank"&gt;Chris Fulstow&lt;/a&gt;&lt;/strong&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;

Well, clear enough. These comments plus people's comments on Oren's post tell me that I'm at least 3 years out of date. Repositories are nolonger hot fashion even though I believe there are still more guys like the old me still see the value of Repositories. I had seen enough problems using Repositories as a generic Repository can easily become a DAO at some point otherwise it would lose many features of the ORM technology abstracted behind it. Properly QueryObjects are the one to go for me next time :D.</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></item></channel></rss>