Please read the Introduction before reading this provider documentation.
This transport provider uses MQTTnet client to connect to the MQTT broker.
The configuration is arranged via the .WithProviderMqtt(cfg => {})
method on the message bus builder.
services.AddSlimMessageBus(mbb =>
{
mbb.WithProviderMqtt(cfg =>
{
cfg.ClientBuilder
.WithTcpServer(configuration["Mqtt:Server"], int.Parse(configuration["Mqtt:Port"]))
.WithTls()
.WithCredentials(configuration["Mqtt:Username"], configuration["Mqtt:Password"])
// Use MQTTv5 to use message headers (if the broker supports it)
.WithProtocolVersion(MQTTnet.Formatter.MqttProtocolVersion.V500);
});
mbb.AddServicesFromAssemblyContaining<PingConsumer>();
mbb.AddJsonSerializer();
});
The ClientBuilder
property (of type MqttClientOptionsBuilder
) is used to configure the underlying MQTTnet library client.
Please consult the MQTTnet library docs for more configuration options.
Headers are only supported with MQTTv5 protocol version. Having a MQTTv5 compliant broker, you still need to to enable the protocol v5 version on the client to enable header feature:
services.AddSlimMessageBus(mbb =>
{
mbb.WithProviderMqtt(cfg =>
{
cfg.ClientBuilder
// ...
// Use MQTTv5 to use message headers (if the broker supports it)
.WithProtocolVersion(MQTTnet.Formatter.MqttProtocolVersion.V500);
});
});
Request-response relies on the presence of headers. When headers are not availabe, then request-response communication will not work with SMB.
In the future SMB might introduce headers emulation (similar to the Redis transport) for earlier protcol versions. If you have need this feature plase raise an issue.