Skip to content

Latest commit

 

History

History
104 lines (76 loc) · 2.76 KB

guide-request-response-server.md

File metadata and controls

104 lines (76 loc) · 2.76 KB
title layout
Request / Response Guide
guide
<script src="{{ site.baseurl }}/assets/js/guide-request-response.js"></script> <script>shuttle.guideData.selectedItemName = 'guide-request-response-server'</script>

Server

Add a new Class Library to the solution called Shuttle.RequestResponse.Server.

![Request/Response Server]({{ site.baseurl }}/assets/images/guide-request-response-Server.png "Request/Response Server")

Install the shuttle-esb-msmq nuget package.

![Request/Response Server - Nuget Msmq]({{ site.baseurl }}/assets/images/guide-request-response-server-nuget-msmq.png "Request/Response Server - Nuget Msmq")

This will provide access to the Msmq IQueue implementation and also include the required dependencies.

Install the shuttle-core-host nuget package.

![Request/Response Server - Nuget Host]({{ site.baseurl }}/assets/images/guide-request-response-server-nuget-host.png "Request/Response Server - Nuget Host")

The default mechanism used to host an endpoint is by using a Windows service. However, by using the Shuttle.Core.Host executable we are able to run the endpoint as a console application or register it as a Windows service for deployment.

Add a reference to the Shuttle.RequestResponse.Messages project.

Host

Rename the default Class1 file to Host and implement the IHost and IDisposabe interfaces as follows:

using System;
using Shuttle.Core.Host;
using Shuttle.ESB.Core;

namespace Shuttle.RequestResponse.Server
{
	public class Host : IHost, IDisposable
	{
		private IServiceBus _bus;

		public void Start()
		{
			_bus = ServiceBus.Create().Start();
		}

		public void Dispose()
		{
			_bus.Dispose();
		}
	}
}

App.config

Add an Application Configuration File item to create the App.config and populate as follows:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<configSections>
		<section name='serviceBus' type="Shuttle.ESB.Core.ServiceBusSection, Shuttle.ESB.Core"/>
	</configSections>

	<serviceBus>
		 <inbox
			workQueueUri="msmq://./shuttle-server-work"
			errorQueueUri="msmq://./shuttle-error" />
	</serviceBus>
</configuration>

RegisterMemberHandler

Add a new class called RegisterMemberHandler that implements the IMessageHandler<RegisterMemberCommand> interface as follows:

using System;
using Shuttle.ESB.Core;
using Shuttle.RequestResponse.Messages;

namespace Shuttle.RequestResponse.Server
{
	public class RegisterMemberHandler : IMessageHandler<RegisterMemberCommand>
	{
		public void ProcessMessage(HandlerContext<RegisterMemberCommand> context)
		{
			Console.WriteLine();
			Console.WriteLine("[MEMBER REGISTERED] : user name = '{0}'", context.Message.UserName);
			Console.WriteLine();
		}

		public bool IsReusable
		{
			get { return true; }
		}
	}
}