/// <summary> /// Creates an MQTT Client /// </summary> /// <param name="configuration"> /// The configuration used for creating the Client /// See <see cref="MqttConfiguration" /> for more details about the supported values /// </param> /// <returns>A new MQTT Client</returns> /// <exception cref="MqttClientException">MqttClientException</exception> public async Task <IMqttClient> CreateClientAsync(MqttConfiguration configuration) { try { //Adding this to not break backwards compatibility related to the method signature //Yielding at this point will cause the method to return immediately after it's called, //running the rest of the logic acynchronously await Task.Yield(); MqttTopicEvaluator topicEvaluator = new MqttTopicEvaluator(configuration); IMqttChannelFactory innerChannelFactory = _binding.GetChannelFactory(_hostAddress, configuration); PacketChannelFactory channelFactory = new PacketChannelFactory(innerChannelFactory, topicEvaluator, configuration); PacketIdProvider packetIdProvider = new PacketIdProvider(); InMemoryRepositoryProvider repositoryProvider = new InMemoryRepositoryProvider(); ClientProtocolFlowProvider flowProvider = new ClientProtocolFlowProvider(topicEvaluator, repositoryProvider, configuration); return(new MqttClientImpl(channelFactory, flowProvider, repositoryProvider, packetIdProvider, configuration)); } catch (Exception ex) { _tracer.Error(ex, ClientProperties.Client_InitializeError); throw new MqttClientException(ClientProperties.Client_InitializeError, ex); } }
/// <summary> /// Creates an MQTT Server /// </summary> /// <param name="configuration"> /// The configuration used for creating the Server /// See <see cref="MqttConfiguration" /> for more details about the supported values /// </param> /// <returns>A new MQTT Server</returns> /// <exception cref="MqttServerException">MqttServerException</exception> public IMqttServer CreateServer(MqttConfiguration configuration) { try { MqttTopicEvaluator topicEvaluator = new MqttTopicEvaluator(configuration); IMqttChannelListener channelProvider = _binding.GetChannelListener(configuration); PacketChannelFactory channelFactory = new PacketChannelFactory(topicEvaluator, configuration); InMemoryRepositoryProvider repositoryProvider = new InMemoryRepositoryProvider(); ConnectionProvider connectionProvider = new ConnectionProvider(); PacketIdProvider packetIdProvider = new PacketIdProvider(); Subject <MqttUndeliveredMessage> undeliveredMessagesListener = new Subject <MqttUndeliveredMessage>(); ServerProtocolFlowProvider flowProvider = new ServerProtocolFlowProvider(_authenticationProvider, connectionProvider, topicEvaluator, repositoryProvider, packetIdProvider, undeliveredMessagesListener, configuration); return(new MqttServerImpl(channelProvider, channelFactory, flowProvider, connectionProvider, undeliveredMessagesListener, configuration)); } catch (Exception ex) { _tracer.Error(ex, ServerProperties.Server_InitializeError); throw new MqttServerException(ServerProperties.Server_InitializeError, ex); } }