Skip to content

Web API service (RabbitMQ callable)

Sunny Ahuwanya edited this page Jan 24, 2016 · 6 revisions

To create a RabbitMQ callable Web API service:

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