Getting Started with ServiceMatrix step one: Send Recive

I gave a presentation at the DublinAlt.net July meeting, the presentation is up on Slide Share here and the code is on GitHub here.

I was under time pressure as Damian Hickey was doing his great presentation on NAncy after me, therefor i had to cut the demo short, so here is a quick getting started with ServiceMatrix and ServiceInsight. Now, I’m going to do it in iterations and this is the first one 🙂

Getting Started with ServiceMatrix

If you don’t have ServiceMatrix installed, you can download ServiceMatrix form here.

The simple scenario we are going to build is:

  • A customer goes to our web site and creates a new account
  • When the back end receives the ‘CreatAccount’ command it sets the account to pending state, sends an email to the user with a link to validate his email address.
  • Once the user click on the link in the email, a ValidateAccountEmailAddress’ command is sent from the web site and we can mark the account as verified.
  • at this stage an event is published to that the account is Verified

Ok, let’s do it.

Create a new project and select NServiceBus system as the project type.

solution builder

You should see folders in Solution Builder called Infrastructure, Libraries, Endpoints, and Services:

  • Infrastructure is where cross-cutting concerns like authentication and auditing are handled.
  • Libraries are units of code that can be reused, including logging and data access.
  • Endpoints are where components are ultimately deployed. They are the executable process. They can be web applications (both Web Forms and MVC) or NServiceBus Hosts (a special kind of Windows Service that allows you to debug it as a Console Application).
  • Services are a logical construct of code that supports a business capability, not a physical process or deployment concern. A service logically defines the boundary of a business concern and provides a logical construct to the business logic (processes and events) code and data belonging to it. This code and data cannot be shared with other services. They are made of many components that can send, process, publish, and subscribe to messages.

Components are a development view. A component can be part of only one service. Components can only interact (send commands/receive commands) with other components in the same service. Components can subscribe to events that are published by components in other services or in the same service. Components are deployed to an endpoint.

Add an MVC endpoint Web call it ‘WebSite’

Right click the web endpoint you just created and select ‘Send Command’; put ‘AccountManagement’ for Service Name and ‘CreateAccount’ as the Command Name

send command

Double click ‘CreateAccount’ command in ‘AccountManagment’ Service>’Contract’>’Commands’ and add properties like id and email.

We now need to deploy the CreatAccount’ command handler to an end point, so right click ‘CreateAccountProcessor’ Component and select ‘Deploy To…’, enter ‘AccountManager’, make sure NServiceBus host is selected and hit ok.

Matrix will create an endpoint and link the ‘CreateAccountProcessor’ (the handling code) to that endpoint, double click ‘CreateAccountProcessor’ and view the handler generated.

Now let’s add code to send a message from the ‘Register’ Action in the AccountController in our MVC web application

Go to ‘AccountController.cs’, find the ‘Register’ action handler and Comment the inner section of the try/catch block, add MvcApplication.Bus.Send(createAccountMessage);

So you will end up with something like this:

Now hit F5 and run, click the register link fill in your details and submit.

You can see the message in the ‘AccountManager’ handling the ‘CreateAccount’ message

Great! We now have send and receive working!

web page1

console page 1

In my next post (iteration) we will do our next task: send a command to our email component so it will send an email to the user.

Stay tuned

1 thought on “Getting Started with ServiceMatrix step one: Send Recive”

Comments are closed.