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 925 B

12345678910111213141516171819202122232425262728293031
  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) : base(adapters, logger.CreateChildLogger(nameof(MqttHostedServer)))
  15. {
  16. _options = options ?? throw new ArgumentNullException(nameof(options));
  17. }
  18. public Task StartAsync(CancellationToken cancellationToken)
  19. {
  20. return StartAsync(_options);
  21. }
  22. public Task StopAsync(CancellationToken cancellationToken)
  23. {
  24. return StopAsync();
  25. }
  26. }
  27. }