Thursday, April 24, 2014

Creating Projections in GetEventStore

Why do you need to create projections? Well currently Im trying to debug a problem and need to find out everything that happened to an order that was placed. I know the Id of the order and want to search the entire GetEventStore and find out everything about it.

GetEventStore: Projections Tab
Note: To be able to access this, you must turn on runProjections=true in the GES config file.

Step 1: Click on New Projection

Delete the code in the Source. Add your Javascript. For Example, I had to go through the entire GES to search for an event where Id == 69864709-5991-49CF-8283-65E99AB343A2 (Guid)


fromStream('Test-events') 
    .when({
        $init: function () {
            return { count: 0, }; // initial state
        },
      
        OrderModified: function(s, e) {
            if(e.body.OrderId.toString() == 'a88b484d-e208-44c4-afd0-2ea1d76838cd'){
                linkTo('OrderId-a88b484d', e);
            }
        },
    }); 

2 Click on Emit Enable
3 Post. Now your Projection shows up in the Streams for analysis.

Saturday, April 12, 2014

Design Patterns - Part 1

Lately I realized that the more new stuff I am learning the more I'm forgetting to apply the basic design principles in the code. The more there is to learn the more there is remember. This only makes things complex. This blog is just a quick brush up on the design patterns we see and use in our code on a day to day basis. 

Decorator Pattern: Sean Chambers has written a good article here on the decorator pattern. There is a free chapter in the OReilly book available here. In a nutshell, this pattern comes handy if you want to extend classes at runtime instead of compile time using a form of object composition. By dynamically composing objects, we are making sure the Open Close principle is not violated. Meaning, new functionality is added without modifying base class. The pattern does what Inheritance will help accomplish just its more powerful and is executed at runtime. C# example is IO operations using streams. File Streams, Memory Streams, Buffered steams and the like.

Courtesy: MSDN


Adapter Pattern: The Adapter pattern lets you adapter one interface to another. This is the best way to deal with that legacy monster that is hard to test. Create an interface and it will hide the ugliness and help test the code too! It is different than the decorator pattern in the sense that in Decorator Pattern the interface of the objects you are composing is the same while in Adapter you change the interfaces. Adapters also have a definite sequence to them; the Adaptee must be contained by the Adapter.

Composite Design Pattern: Ray Houston from LosTechies has a good article here. In a gist: Its best for handing tree like structures where the parent and leaf nodes does not have to be dealt differently.