Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document the MQTT integration #1

Open
kevinchalet opened this issue Dec 7, 2024 · 0 comments
Open

Document the MQTT integration #1

kevinchalet opened this issue Dec 7, 2024 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@kevinchalet
Copy link
Contributor

OpenNetty has a MQTT companion (named OpenNetty.Mqtt) that can be enabled using .AddMqttIntegration():

/// <summary>
/// Registers the OpenNetty MQTT services in the DI container.
/// </summary>
/// <param name="builder">The services builder used by OpenNetty to register new services.</param>
/// <remarks>This extension can be safely called multiple times.</remarks>
/// <returns>The <see cref="OpenNettyMqttBuilder"/> instance.</returns>
public static OpenNettyMqttBuilder AddMqttIntegration(this OpenNettyBuilder builder)
{
ArgumentNullException.ThrowIfNull(builder);
builder.Services.AddOptionsWithValidateOnStart<OpenNettyMqttOptions>();
builder.Services.TryAddSingleton(static provider => new MqttFactory());
builder.Services.TryAddSingleton(static provider =>
{
var factory = provider.GetRequiredService<MqttFactory>();
return factory.CreateManagedMqttClient();
});
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IOpenNettyHandler, OpenNettyMqttHostedService>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IPostConfigureOptions<OpenNettyMqttOptions>, OpenNettyMqttConfiguration>());
builder.Services.TryAddSingleton<IOpenNettyMqttWorker, OpenNettyMqttWorker>();
builder.Services.AddHostedService<OpenNettyMqttHostedService>();
return new OpenNettyMqttBuilder(builder.Services);
}

We'll need to document that in the README file.

@kevinchalet kevinchalet added the documentation Improvements or additions to documentation label Dec 7, 2024
@kevinchalet kevinchalet self-assigned this Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant