Beispiel #1
0
 public static void AddIoTSharpMqttServer(this IServiceCollection services, MqttBrokerSetting setting)
 {
     services.AddMqttTcpServerAdapter();
     services.AddHostedMqttServerEx(options =>
     {
         var broker = setting;
         if (broker == null)
         {
             broker = new MqttBrokerSetting();
         }
         options.WithDefaultEndpointPort(broker.Port).WithDefaultEndpointBoundIPAddress(System.Net.IPAddress.Parse("127.0.0.1")).WithDefaultEndpoint();
         if (broker.EnableTls)
         {
             options.WithEncryptedEndpoint();
             options.WithEncryptedEndpointPort(broker.TlsPort);
             if (System.IO.File.Exists(broker.Certificate))
             {
                 options.WithEncryptionCertificate(System.IO.File.ReadAllBytes(broker.Certificate)).WithEncryptionSslProtocol(broker.SslProtocol);
             }
         }
         else
         {
             options.WithoutEncryptedEndpoint();
         }
         options.Build();
     });
     services.AddMqttConnectionHandler();
     services.AddMqttWebSocketServerAdapter();
     services.AddTransient <MqttEventsHandler>();
 }
Beispiel #2
0
 //static private IMqttServer _mqttServer;
 public static void AddIoTSharpMqttServer(this IServiceCollection services, MqttBrokerSetting broker)
 {
     services.AddMqttTcpServerAdapter();
     services.AddHostedMqttServerEx(options =>
     {
         options.WithDefaultEndpointPort(broker.Port).WithDefaultEndpoint();
         if (broker.EnableTls)
         {
             options.WithEncryptedEndpoint();
             options.WithEncryptedEndpointPort(broker.TlsPort);
             if (System.IO.File.Exists(broker.Certificate))
             {
                 options.WithEncryptionCertificate(System.IO.File.ReadAllBytes(broker.Certificate)).WithEncryptionSslProtocol(broker.SslProtocol);
             }
         }
         else
         {
             options.WithoutEncryptedEndpoint();
         }
         options.WithPersistentSessions();
         options.Build();
     });
     services.AddMqttConnectionHandler()
     .AddConnections();
     services.AddMqttWebSocketServerAdapter();
     services.AddSingleton <MQTTServerHandler>();
 }
Beispiel #3
0
 //static private IMqttServer _mqttServer;
 public static void AddIoTSharpMqttServer(this IServiceCollection services, MqttBrokerSetting broker)
 {
     services.AddMqttTcpServerAdapter();
     services.AddHostedMqttServer(options =>
     {
         options.WithDefaultEndpointPort(broker.Port).WithDefaultEndpoint();
         if (broker.EnableTls)
         {
             if (broker.CACertificate != null)
             {
                 broker.CACertificate.LoadCAToRoot();
             }
             options.WithEncryptedEndpoint();
             options.WithEncryptedEndpointPort(broker.TlsPort);
             if (broker.BrokerCertificate != null)
             {
                 options.WithEncryptionCertificate(broker.BrokerCertificate.Export(X509ContentType.Pfx)).WithEncryptionSslProtocol(broker.SslProtocol);
             }
         }
         else
         {
             options.WithoutEncryptedEndpoint();
         }
         options.WithDefaultCommunicationTimeout(TimeSpan.FromSeconds(5));
         options.WithPersistentSessions();
         options.Build();
     }).AddMqttConnectionHandler()
     .AddConnections();
     services.AddMqttWebSocketServerAdapter();
     services.AddSingleton <MQTTServerHandler>();
 }