RabbitExpress 1.1.10

An easy to use RabbitMQ Client for .Net.

Install-Package RabbitExpress -Version 1.1.10
dotnet add package RabbitExpress --version 1.1.10
<PackageReference Include="RabbitExpress" Version="1.1.10" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RabbitExpress --version 1.1.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

RabbitExpress

This library provides an easy way to use RabbitMQ from C# or your other preferred .Net language.

Add the reference

In the csproj add a PackageReference to the RabbitExpress.Serializers.JsonSerializer

<ItemGroup>
    <PackageReference Include="RabbitExpress.Serializers.JsonSerializer" Version="1.*" />
</ItemGroup>

or the RabbitExpress.Serializers.MsgPackSerializer package.

<ItemGroup>
    <PackageReference Include="RabbitExpress.Serializers.MsgPackSerializer" Version="1.*" />
</ItemGroup>

Basic usage

Using the QueueClient requires two type parameters. One type parameter defines the queues that will be created by the queue client. The other parameter defines the used serializer. As argument for the constructor the connection string is required in Uri format.

var client = new QueueClient<JsonSerializer>(new Uri("amqps://xxx:yyy@host/instance"));

To publish a message just use the Publish method. A full Publisher example can be found in RabbitExpress.ExamplePublisher.

client.Publish(Queues.EXAMPLE_QUEUE, new ExampleMessage { Text = message });

To listen for new messages use the StartWatch method. A full Worker example can be found in RabbitExpress.ExamplePublisher.

qc.WatchQueue<Queues, ExampleMessage>(Queues.EXAMPLE_QUEUE, m => {...});

RPC usage

Using the QueueClient for RPC is straight forward. You need to define an interface for your RPC proxies.

public interface IExampleService
{
    string Calculate(int number1, int number2);
}

Using void as return type makes the proxy behave like the worker/publisher example. Other return types cause the proxy to block until the result is available. Make sure the return types and parameters are serializeable. Failing to do so will result in unexpected behavior.

Consuming a method from the proxy is easy, you simply get a proxy from the queue client and start to call methods on it.

IExampleService client = qc.RpcClient<IExampleService>();
Console.WriteLine(client.Calculate(2, 4));

Without a service to handle the Request the code above will block forever. Implementing the server just requires another method call on the QueueClient.

qc.RpcServer<IExampleService>(x => x.Calculate(1, 2), new Func<int, int, string>((i1, i2) =>
{
    Console.WriteLine($"Calculating {i1} + {i2}");
    return (i1 + i2).ToString();
}));

For a full example of the RPC pattern see RabbitExpress.Example.RpcClient and RabbitExpress.Example.RpcServer.

Implementing a serializer

Implementing a serializer is very straight forward. Just implement the IExpressSerializer interface and make sure that your class accepts a parameterless default constructor. The interface defines only 3 methods, Serialize and Deserialize. For a full example see the RabbitExpress.JsonSerializer project.

RabbitExpress

This library provides an easy way to use RabbitMQ from C# or your other preferred .Net language.

Add the reference

In the csproj add a PackageReference to the RabbitExpress.Serializers.JsonSerializer

<ItemGroup>
    <PackageReference Include="RabbitExpress.Serializers.JsonSerializer" Version="1.*" />
</ItemGroup>

or the RabbitExpress.Serializers.MsgPackSerializer package.

<ItemGroup>
    <PackageReference Include="RabbitExpress.Serializers.MsgPackSerializer" Version="1.*" />
</ItemGroup>

Basic usage

Using the QueueClient requires two type parameters. One type parameter defines the queues that will be created by the queue client. The other parameter defines the used serializer. As argument for the constructor the connection string is required in Uri format.

var client = new QueueClient<JsonSerializer>(new Uri("amqps://xxx:yyy@host/instance"));

To publish a message just use the Publish method. A full Publisher example can be found in RabbitExpress.ExamplePublisher.

client.Publish(Queues.EXAMPLE_QUEUE, new ExampleMessage { Text = message });

To listen for new messages use the StartWatch method. A full Worker example can be found in RabbitExpress.ExamplePublisher.

qc.WatchQueue<Queues, ExampleMessage>(Queues.EXAMPLE_QUEUE, m => {...});

RPC usage

Using the QueueClient for RPC is straight forward. You need to define an interface for your RPC proxies.

public interface IExampleService
{
    string Calculate(int number1, int number2);
}

Using void as return type makes the proxy behave like the worker/publisher example. Other return types cause the proxy to block until the result is available. Make sure the return types and parameters are serializeable. Failing to do so will result in unexpected behavior.

Consuming a method from the proxy is easy, you simply get a proxy from the queue client and start to call methods on it.

IExampleService client = qc.RpcClient<IExampleService>();
Console.WriteLine(client.Calculate(2, 4));

Without a service to handle the Request the code above will block forever. Implementing the server just requires another method call on the QueueClient.

qc.RpcServer<IExampleService>(x => x.Calculate(1, 2), new Func<int, int, string>((i1, i2) =>
{
    Console.WriteLine($"Calculating {i1} + {i2}");
    return (i1 + i2).ToString();
}));

For a full example of the RPC pattern see RabbitExpress.Example.RpcClient and RabbitExpress.Example.RpcServer.

Implementing a serializer

Implementing a serializer is very straight forward. Just implement the IExpressSerializer interface and make sure that your class accepts a parameterless default constructor. The interface defines only 3 methods, Serialize and Deserialize. For a full example see the RabbitExpress.JsonSerializer project.

Version History

Version Downloads Last updated
1.1.10 32 5/13/2019
1.1.9 30 5/11/2019
1.1.8 31 5/11/2019
1.1.7 47 5/2/2019
1.1.6 40 5/2/2019
1.1.5 42 5/1/2019
1.1.4 45 5/1/2019
1.1.3 43 5/1/2019
1.1.2 43 5/1/2019
1.1.1 45 5/1/2019
1.1.0 43 5/1/2019