Skip to content

ASP.NET Core service (RabbitMQ callable)

Sunny Ahuwanya edited this page Jan 27, 2016 · 7 revisions

ASP.Net Core (formerly known as ASP.NET 5) has not yet been released. However, you can use RestBus with the pre-release rc2 bits today.
You can install ASP.NET Core from get.asp.net if you don't have it installed.

For a working example, see the ASP.Net Core example in the RestBus.Examples repo.

Create and Configure a new Application

  • Create a new ASP.Net Application. (Select the Web API ASP.NET 5 template)
  • In the global.json file: Set version to 1.0.0-rc2-16357
  • Depending on your setup, you might need to add a hosting.json file.
  • Modify the the project.json file:
    • In the dependencies section, add "RestBus.AspNet": "0.6.2-rc2" and "RestBus.RabbitMQ" : "0.6.9".
    • Set the value of all other dependencies to "1.0.0-rc2-*", except Microsoft.AspNet.Mvc which should be set to "6.0.0-rc2-*".
    • In the frameworks section, and add only dnx452. (dnxcore50 will be supported once the RabbitMQ library becomes portable).
    • In the commands section, set the value for web to the application's assembly name.
  • Save the project.

Upgrade dnvm and install a specific version of the runtime.

In a Developer Command Prompt, run the following commands:

dnvm update-self  (You may be able to proceed to the next command if this fails)

dnvm install -u 1.0.0-rc2-16357 -arch x86 -runtime clr

dnvm install -u 1.0.0-rc2-16357 -arch x64 -runtime clr

Restore Nuget Packages

In a Developer Command Prompt, change directory to the path containing the project.json file, and run

dnu restore -s https://www.nuget.org/api/v2/ -s https://www.myget.org/F/aspnetvnext/api/v2/

Modify Startup.cs to run the RestBus host

Add the following code to the Configure method in Startup.cs

// Create RestBus Subscriber
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);

bool standAlone = false;
/* 
    This service listens for requests through both HTTP and the message broker. 
    If you desire a standalone service that only listens to the message broker:
    1. Set standAlone to true
    2. Update the hosting.json file with the instructions in the file.
*/

if (standAlone)
{
    // Configures the rest bus server -- needed if running standalone server, ignored otherwise.
    app.ConfigureRestBusServer(subscriber);
}
else
{
    app.RunRestBusHost(subscriber);
}

Run the application

In a Developer Command Prompt, change directory to the path containing the project.json file, and run

dnx web

You can also run the application from Visual Studio.

Make a request to the service

See Calling a Service EndPoint