Calling a Service Endpoint (via RabbitMQ)

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

To call service endpoints, use the RestBusClient class which is used similarly to the HttpClient class.

Compose a HttpRequestMessage and use the RestBusClient.SendAsync method to send the message.
Alternatively, use one of the convenience extension methods defined on the RestBusClient class to send your message, as illustrated in the following walkthrough:

  • Create a new Console Application and install the RestBus.RabbitMQ NuGet package.
PM> Install-Package RestBus.RabbitMQ
  • Call the target service with the following code example.
	using RestBus.Client;
	using RestBus.RabbitMQ;
	using RestBus.RabbitMQ.Client;
	using System;
	class Program
	    static void Main(string[] args)
	        var amqpUrl = "amqp://localhost:5672"; //AMQP URL for RabbitMQ installation
	        var serviceName = "samba"; //The unique identifier for the target service
	        var msgMapper = new BasicMessageMapper(amqpUrl, serviceName);
	        RestBusClient client = new RestBusClient(msgMapper);
	        RequestOptions requestOptions = null;
	         * //Uncomment this section to get a response in JSON format
	        requestOptions = new RequestOptions();
	        requestOptions.Headers.Add("Accept", "application/json");
	        //Send Request
	        var uri = "api/values"; //Substitute "hello/random" for the ServiceStack example
	        var response = client.GetAsync(uri, requestOptions).Result;
	        //NOTE: You can use 'var response = await client.GetAsync(uri, requestOptions);' in your code
	        //Display response

	        //Dispose client

Complete examples of RabbitMQ RestBus clients in console and web applications are available at the RestBus.Examples repo.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.