title | layout |
---|---|
Request / Response Guide |
guide |
Add a new
Class Library
to the solution calledShuttle.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.
Rename the default
Class1
file toHost
and implement theIHost
andIDisposabe
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();
}
}
}
Add an
Application Configuration File
item to create theApp.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>
Add a new class called
RegisterMemberHandler
that implements theIMessageHandler<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; }
}
}
}