-
Notifications
You must be signed in to change notification settings - Fork 56
Web API service (RabbitMQ callable)
Sunny Ahuwanya edited this page Jan 24, 2016
·
6 revisions
To create a RabbitMQ callable Web API service:
-
Create a new Web API project. Detailed instructions can be seen at the Getting Started with ASP.NET Web API 2 tutorial.
-
Install the RestBus.RabbitMQ and RestBus.WebAPI NuGet packages.
PM> Install-Package RestBus.RabbitMQ
PM> Install-Package RestBus.WebAPI
- Add code in the
Application_Start
method of the Global.asax file that starts the RestBus host.
RestBusHost restbusHost = null; //Make this a field in the class
var amqpUrl = "amqp://localhost:5672"; //AMQP URI for RabbitMQ server
var serviceName = "samba"; //Uniquely identifies this service
var msgMapper = new BasicMessageMapper(amqpUrl, serviceName);
var subscriber = new RestBusSubscriber(msgMapper);
restbusHost = new RestBusHost(subscriber, GlobalConfiguration.Configuration);
restbusHost.Start();
- Add code in the
Application_End
method of the Global.asax file that stops the RestBus host.
if (restbusHost != null)
restbusHost.Dispose();
A complete example is available in the RestBus.Examples repo.
To call this service from a client, see Calling a Service Endpoint