コード例 #1
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="MqttProducerEndpointBuilder" /> class.
 /// </summary>
 /// <param name="clientConfig">
 ///     The <see cref="MqttClientConfig" />.
 /// </param>
 /// <param name="endpointsConfigurationBuilder">
 ///     The optional reference to the <see cref="IEndpointsConfigurationBuilder" /> that instantiated the
 ///     builder.
 /// </param>
 public MqttProducerEndpointBuilder(
     MqttClientConfig clientConfig,
     IEndpointsConfigurationBuilder?endpointsConfigurationBuilder = null)
     : base(endpointsConfigurationBuilder)
 {
     _clientConfig = clientConfig;
 }
コード例 #2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="MqttConsumerEndpointBuilder" /> class.
 /// </summary>
 /// <param name="clientConfig">
 ///     The <see cref="MqttClientConfig" />.
 /// </param>
 /// <param name="messageType">
 ///     Gets the type of the message being consumed.
 /// </param>
 /// <param name="endpointsConfigurationBuilder">
 ///     The optional reference to the <see cref="IEndpointsConfigurationBuilder" /> that instantiated the
 ///     builder.
 /// </param>
 public MqttConsumerEndpointBuilder(
     MqttClientConfig clientConfig,
     Type?messageType = null,
     IEndpointsConfigurationBuilder?endpointsConfigurationBuilder = null)
     : base(messageType, endpointsConfigurationBuilder)
 {
     _clientConfig = clientConfig;
 }
コード例 #3
0
        /// <inheritdoc cref="IMqttProducerEndpointBuilder.Configure(Action{IMqttClientConfigBuilder})" />
        public IMqttProducerEndpointBuilder Configure(Action <IMqttClientConfigBuilder> configBuilderAction)
        {
            Check.NotNull(configBuilderAction, nameof(configBuilderAction));

            var configBuilder = new MqttClientConfigBuilder(
                _clientConfig,
                EndpointsConfigurationBuilder?.ServiceProvider);

            configBuilderAction.Invoke(configBuilder);

            _clientConfig = configBuilder.Build();

            return(this);
        }
コード例 #4
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="MqttClientConfigBuilder" /> class.
        /// </summary>
        /// <param name="baseConfig">
        ///     The <see cref="MqttClientConfig" /> to be used to initialize the builder.
        /// </param>
        /// <param name="serviceProvider">
        ///     The <see cref="IServiceProvider" /> to be used to resolve the required types (e.g. the
        ///     <see cref="IMqttExtendedAuthenticationExchangeHandler" />).
        /// </param>
        public MqttClientConfigBuilder(MqttClientConfig baseConfig, IServiceProvider?serviceProvider = null)
            : this(serviceProvider)
        {
            Check.NotNull(baseConfig, nameof(baseConfig));

            UseProtocolVersion(baseConfig.ProtocolVersion);
            WithCommunicationTimeout(baseConfig.CommunicationTimeout);

            if (baseConfig.CleanSession)
            {
                RequestCleanSession();
            }
            else
            {
                RequestPersistentSession();
            }

            if (baseConfig.KeepAlivePeriod == TimeSpan.Zero)
            {
                DisableKeepAlive();
            }
            else
            {
                SendKeepAlive(baseConfig.KeepAlivePeriod);
            }

            WithClientId(baseConfig.ClientId);

            if (baseConfig.WillMessage != null)
            {
                SendLastWillMessage(baseConfig.WillMessage, baseConfig.WillDelayInterval);
            }

            WithAuthentication(baseConfig.AuthenticationMethod, baseConfig.AuthenticationData);

            if (baseConfig.TopicAliasMaximum != null)
            {
                LimitTopicAlias(baseConfig.TopicAliasMaximum.Value);
            }

            if (baseConfig.MaximumPacketSize != null)
            {
                LimitPacketSize(baseConfig.MaximumPacketSize.Value);
            }

            if (baseConfig.ReceiveMaximum != null)
            {
                LimitUnacknowledgedPublications(baseConfig.ReceiveMaximum.Value);
            }

            if (baseConfig.RequestProblemInformation != null)
            {
                if (baseConfig.RequestProblemInformation.Value)
                {
                    RequestProblemInformation();
                }
                else
                {
                    DisableProblemInformation();
                }
            }

            if (baseConfig.RequestResponseInformation != null)
            {
                if (baseConfig.RequestResponseInformation.Value)
                {
                    RequestResponseInformation();
                }
                else
                {
                    DisableResponseInformation();
                }
            }

            if (baseConfig.SessionExpiryInterval != null)
            {
                WithSessionExpiration(baseConfig.SessionExpiryInterval.Value);
            }

            baseConfig.UserProperties.ForEach(property => AddUserProperty(property.Name, property.Value));

            if (baseConfig.Credentials != null)
            {
                WithCredentials(baseConfig.Credentials);
            }

            if (baseConfig.ExtendedAuthenticationExchangeHandler != null)
            {
                UseExtendedAuthenticationExchangeHandler(baseConfig.ExtendedAuthenticationExchangeHandler);
            }

            if (baseConfig.ChannelOptions is MqttClientTcpOptions tcpOptions)
            {
                ConnectViaTcp(
                    options =>
                {
                    options.Port          = tcpOptions.Port;
                    options.Server        = tcpOptions.Server;
                    options.AddressFamily = tcpOptions.AddressFamily;
                    options.BufferSize    = tcpOptions.BufferSize;
                    options.DualMode      = tcpOptions.DualMode;
                    options.NoDelay       = tcpOptions.NoDelay;
                    options.TlsOptions    = tcpOptions.TlsOptions;
                });
            }
            else if (baseConfig.ChannelOptions is MqttClientWebSocketOptions webSocketOptions)
            {
                ConnectViaWebSocket(
                    options =>
                {
                    options.Uri             = webSocketOptions.Uri;
                    options.CookieContainer = webSocketOptions.CookieContainer;
                    options.ProxyOptions    = webSocketOptions.ProxyOptions;
                    options.RequestHeaders  = webSocketOptions.RequestHeaders;
                    options.SubProtocols    = webSocketOptions.SubProtocols;
                    options.TlsOptions      = webSocketOptions.TlsOptions;
                });
            }
        }