Thursday, November 29, 2012

Getting started with NServiceBus, Request-Response example


In this blog post we explain some request-response example that we mentioned in the previous blogpost.

Below you can see the first steps to do, before we really can start with sending some messages.

  - Go to http://www.nservicebus.com à Downloads
  - Download the msi file under the “Get version 3.3.1 now” button.

 
   - Install the msi file on your system.
   -  Now you can find under “All programs > NServicebus v3.3.1” a Welcome to NServiceBus link.






You can click on the samples link to go to the samples. Or you can choose a sample below. We will talk about the “FullDuplex – RequestResponse” sample. Copy past the location of the sample and open it with visual studio. You will get the following solution.




The client is going to send a message to the server, the server will process the message and return it back to the client.
Let’s run the server and client application. You should see some screens like below.



Now we can exchange some messages between server and client. Let’s hit the “Enter” button in the Client Console. The client sends a message to the server with a Guid, which is received by the server and the server sends a message back to the client.




As you can see, this is not a real life scenario. What if the client is down? What if the server is down.
Let’s now start only the client application.



As you can see we send a message from the client to the server, but we don’t get some reaction back from the server because we didn’t start the server application. You don’t lose the message because NServicebus uses MSMQ and the message stays in the queue.
When we look in the MSMQ queue, you can see that there is a message.



Now we open the message, there you can find the DataID in the message. This ID is the same as on the Client application.



Now we can start the server application.



You can now see that the server picks up the message to process it. And send it back to the client.
I hope you enjoyed reading this blogpost.

Author: Sven Van den brande

No comments:

Post a Comment