Please read the Introduction before reading this provider documentation.
This transport provider uses NATS.Nets client to connect to the NATS broker.
The configuration is arranged via the .WithProviderNats(cfg => {})
method on the message bus builder.
builder.Services.AddSlimMessageBus(messageBusBuilder =>
{
messageBusBuilder.WithProviderNats(cfg =>
{
cfg.Endpoint = endpoint;
cfg.ClientName = $"MyService_{Environment.MachineName}";
cfg.AuthOpts = NatsAuthOpts.Default;
});
messageBusBuilder
.Produce<PingMessage>(x => x.DefaultTopic(topic))
.Consume<PingMessage>(x => x.Topic(topic).Instances(1));
messageBusBuilder.AddServicesFromAssemblyContaining<PingConsumer>();
messageBusBuilder.AddJsonSerializer();
});
The NatsMessageBusSettings
property is used to configure the underlying Nats.Net library client.
Please consult the NATS.Net library docs for more configuration options.
Nats offers native serialization functionality. This functionality conflicts with the serialization functionality provided by SlimMessageBus. We have chosen to leave the responsibility for serialization to SlimMessageBus and leave the default configuration of Nats serialization, which is raw serialization. This means that the message body is serialized as a byte array.