Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Tuesday, August 19, 2008

Don't Give Up on Messaging

Today at work the dreaded words were uttered: "Well if it's not working by the end of the day lets just go for the pull every 1 second solution."

After implementing all of the long running processes to a pub/sub model, it was not pleasant to hear that. I wasn't going to just give up on that much energy poured into the current (and best) approach.

After adding tons of logging and hammering the server to see where the leaks sprung up, I cornered the culprit. If you are pulling from MSMQ ad nauseum, and you are in a multithreaded environment, you need to protect yourself from the thread unsafe methods "Send" and "Receive" on your MSMQ object - usually done by creating the MSMQ object for just long enough to do 1 operation.

The place where this was being done was not a multithreaded scenario, so I got rid of the creation and disposal of the MSMQ object between receives.

That did it.

The other lesson here is to be careful when you do have a multithreaded app pulling from MSMQ. You may see same messages go missing. I know there are other MSMQ features that guarantee delivery, etc, but I expect this integrity out-of-the-box.

Monday, August 11, 2008

DDD and the Too Many Aggregate Roots Design Smell

This usually comes about from forcing a DDD solution where one would really needs a simple forms over data type app with ORM thrown in for speed.

Don't even bother with TDD for the most part.

Thoughts?

Thursday, December 6, 2007

Active Record and Many to Many Update

Ok. I've cleaned it up now. In the continuing journey of learning Active Record and NHibernate, the static FindAll method can be overridden and the client code is as clean as you would expect it to be:

Distributor[] all = Distributor.FindAll();
foreach(Distributor distributor in all) {
Console.WriteLine(distributor.Name);
foreach(DeliveryMethod deliveryMethod in distributor.DeliveryMethods)
Console.WriteLine("--" + deliveryMethod.Description);
}


Here is what was added to the Distributor class:

public new static Distributor[] FindAll() { return FindAll(DetachedCriteria.For(typeof(Distributor)).SetResultTransformer(CriteriaUtil.DistinctRootEntity).SetFetchMode("DeliveryMethods", FetchMode.Eager)); }

I'm sure there's a way to include the same attribute on the DeliveryMethod and still get the results you want - I just haven't learned enough of the API yet to know how to do that. Tips are welcome..