# gRPC

MassTransit.Grpc (opens new window)

A new gRPC transport, designed to be a peer-to-peer distributed non-durable message transport, is now included. It's entirely in-memory, has zero dependencies, and allows multiple service instances to exchange messages across a shared message fabric.

WARNING

New, shiny, and very much in the early availability stage. There may be edge cases, so proceed with caution. The gRPC transport will be supported, and issues resolved as they're reported.

Introduction Video (YouTube) (opens new window)

# Broker Topology

The gRPC is modeled after RabbitMQ, and supports many of the same features. It uses exchanges and queues, and follows the same topology structure as the RabbitMQ transport.

Fanout, Direct, and Topic exchanges are supported, along with routing key support.

And, it, is fast. Using the server GC, message throughput is pretty impressive.

On a single node (essentially in-memory, but serialized via protocol buffers):

Send: 253,774 msg/s
Consume: 172,996 msg/s

Across two nodes, load balanced via competing consumer:

Send: 232,597 msg/s
Consume: 36,331 msg/s

Consume rate is slower because the messages are evenly split across the local and remote node.

# Examples

# Minimal

namespace GrpcConsoleListener;

using System.Threading.Tasks;
using MassTransit;
using Microsoft.Extensions.Hosting;

public class Program
{
    public static async Task Main(string[] args)
    {
        await Host.CreateDefaultBuilder(args)
            .ConfigureServices(services =>
            {
                services.AddMassTransit(x =>
                {
                    x.UsingGrpc((context, cfg) =>
                    {
                        cfg.Host(h =>
                        {
                            h.Host = "127.0.0.1";
                            h.Port = 19796;
                        });

                        cfg.ConfigureEndpoints(context);
                    });
                });
            })
            .Build()
            .RunAsync();
    }
}

Full documentation is coming soon, but for now the host configuration is shown below.

To configure the host using a complete address, such as http://localhost:19796, a Uri can be specified. The following configures a standalone instance, no servers are specified. Incoming connections are of course accepted.

cfg.Host(new Uri("http://localhost:19796"));

# Multiple Nodes

To configure a host that connects to other bus instances, use the AddServer method in the host. In this example, the host and port are configured separately. The bus will not start until the server connections are established.

namespace GrpcMultiConsoleListener;

using System;
using System.Threading.Tasks;
using MassTransit;
using Microsoft.Extensions.Hosting;

public class Program
{
    public static async Task Main(string[] args)
    {
        await Host.CreateDefaultBuilder(args)
            .ConfigureServices(services =>
            {
                services.AddMassTransit(x =>
                {
                    x.UsingGrpc((context, cfg) =>
                    {
                        cfg.Host(h =>
                        {
                            h.Host = "127.0.0.1";
                            h.Port = 19796;

                            h.AddServer(new Uri("127.0.0.1:19797"));
                            h.AddServer(new Uri("127.0.0.1:19798"));
                        });

                        cfg.ConfigureEndpoints(context);
                    });
                });
            })
            .Build()
            .RunAsync();
    }
}

Check out the discussion thread (opens new window) for more information.