You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MqttHostedServer.cs 974 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using Microsoft.Extensions.Hosting;
  6. using MQTTnet.Adapter;
  7. using MQTTnet.Diagnostics;
  8. using MQTTnet.Server;
  9. namespace MQTTnet.AspNetCore
  10. {
  11. public class MqttHostedServer : MqttServer, IHostedService
  12. {
  13. private readonly IMqttServerOptions _options;
  14. public MqttHostedServer(IMqttServerOptions options, IEnumerable<IMqttServerAdapter> adapters, IMqttNetLogger logger)
  15. : base(adapters, logger.CreateChildLogger(nameof(MqttHostedServer)))
  16. {
  17. _options = options ?? throw new ArgumentNullException(nameof(options));
  18. }
  19. public Task StartAsync(CancellationToken cancellationToken)
  20. {
  21. _ = StartAsync(_options);
  22. return Task.CompletedTask;
  23. }
  24. public Task StopAsync(CancellationToken cancellationToken)
  25. {
  26. return StopAsync();
  27. }
  28. }
  29. }