Back from Udi Dahan’s course

As JP commented, this is the best course he ever took. I have the exactly same feeling.

Some shocking takeaway from the course.

  1. If you are not doing CQRS, you are probably doing DDD in the wrong way.
  2. Your so-called Domain object, e.g., Customer or Product, is actually a persistent view model.
  3. View model can be deployed on a distributed database, preferable a document-based database, or MySql, can even be the cookie at client side. The important part is the view-updater which is listening the event message published by the command.
  4. The infrastructure of ACs pulling tasks from Distributor instead of classic cluster enable no-shut-down upgrading.
  5. Message pub/sub with pipeline pattern is very clean and easy for maintenance. NServiceBus can automatically find all those message handlers and wire them up.
  6. Watch out your design, especially the service boundary, thinking wide instead of deep. Don’t let your db-design block your view to user-intention.
  7. Editable grid has no business meaning, or hide the real business requirement behind it.
  8. Delete customer/product has no real world meaning, do you want to cancel it? do you want to change history?
  9. Some concurrency can not be fixed by technology, like cancel and ship the same order, has to be solved by the business model, more detail, different timeout in refund service.
  10. Saga is the real domain object, not depended on UI, DB, with business only logic saved it, not data. You don’t save customer name or relationship in saga, even a customer id. Saga pattern was actually invented by DBA group to solve concurrency problem about 15 years age.

The first thing I did after the course is download the NServiceBus, compile and look into the sub/pub sample. After install MSMQ on my Win7 box, Subscriber 2 still couldn’t start. error said: NServiceBus.Utils.WorkerThread, – Exception reached top level….System.Threading.LockRecursionException: Recursive write lock acquistions not a llow in this mode…

I had to close subscriber2 and focus on sbuscriber1 and Publisher only. Message can be sent and received successfully. OK, add my add-on message handler. Works like a charm!

using log4net;

using MyMessages;
using NServiceBus;

namespace Subscriber1
{
    public class EventMessageHandler : IHandleMessages<EventMessage>
    {
        public void Handle(EventMessage message)
        {
            Logger.Info(string.Format("Subscriber 1 received EventMessage with Id {0}.", message.EventId));
            Logger.Info(string.Format("Message time: {0}.", message.Time));
            Logger.Info(string.Format("Message duration: {0}.", message.Duration));
            Console.WriteLine("==========================================================================");
        }

        private static readonly ILog Logger = LogManager.GetLogger(typeof (EventMessageHandler));
    }

    public class AddonEventMessageHandler : IHandleMessages<EventMessage>
    {
        private static readonly ILog Logger = LogManager.GetLogger(typeof(AddonEventMessageHandler ));
        public void Handle(EventMessage message)
        {
            Logger.Info("X##########################################333");
            Logger.Info("did you see me?");
            Logger.Info("X##########################################333");
        }
    }
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s