async Task <List <string> > PrepareTopicHashSubscriptions(TopicHashSelector selector) { Dictionary <string, List <string> > topicsByPublisher; Dictionary <string, List <string> > singleWildcardTopicsByPublisher; Dictionary <string, List <string> > multiWildcardTopicsByPublisher; const int NumPublishers = 1; const int NumTopicsPerPublisher = 10000; TopicGenerator.Generate(NumPublishers, NumTopicsPerPublisher, out topicsByPublisher, out singleWildcardTopicsByPublisher, out multiWildcardTopicsByPublisher); var topics = topicsByPublisher.FirstOrDefault().Value; var singleWildcardTopics = singleWildcardTopicsByPublisher.FirstOrDefault().Value; var multiWildcardTopics = multiWildcardTopicsByPublisher.FirstOrDefault().Value; const string ClientId = "Client1"; var logger = new Mockups.TestLogger(); var serverOptions = new MQTTnet.Server.MqttServerOptions(); var eventContainer = new MQTTnet.Server.MqttServerEventContainer(); var retainedMessagesManager = new MqttRetainedMessagesManager(eventContainer, logger); var sessionManager = new MqttClientSessionsManager(serverOptions, retainedMessagesManager, eventContainer, logger); _clientSession = new MQTTnet.Server.MqttSession( ClientId, false, new Dictionary <object, object>(), serverOptions, eventContainer, retainedMessagesManager, sessionManager ); List <string> topicsToSubscribe; switch (selector) { case TopicHashSelector.SingleWildcard: topicsToSubscribe = singleWildcardTopics; break; case TopicHashSelector.MultiWildcard: topicsToSubscribe = multiWildcardTopics; break; default: topicsToSubscribe = topics; break; } foreach (var t in topicsToSubscribe) { var subPacket = new Packets.MqttSubscribePacket(); var filter = new Packets.MqttTopicFilter(); filter.Topic = t; subPacket.TopicFilters.Add(filter); await _clientSession.SubscriptionsManager.Subscribe(subPacket, default(CancellationToken)); } return(topics); }
public MqttClientSessionsManager( MqttServerOptions options, MqttRetainedMessagesManager retainedMessagesManager, MqttServerEventContainer eventContainer, IMqttNetLogger logger) { if (logger == null) { throw new ArgumentNullException(nameof(logger)); } _logger = logger.WithSource(nameof(MqttClientSessionsManager)); _rootLogger = logger; _options = options ?? throw new ArgumentNullException(nameof(options)); _retainedMessagesManager = retainedMessagesManager ?? throw new ArgumentNullException(nameof(retainedMessagesManager)); _eventContainer = eventContainer ?? throw new ArgumentNullException(nameof(eventContainer)); }
public MqttServer(MqttServerOptions options, IEnumerable <IMqttServerAdapter> adapters, IMqttNetLogger logger) { _options = options ?? throw new ArgumentNullException(nameof(options)); if (adapters == null) { throw new ArgumentNullException(nameof(adapters)); } _adapters = adapters.ToList(); _rootLogger = logger ?? throw new ArgumentNullException(nameof(logger)); _logger = logger.WithSource(nameof(MqttServer)); _retainedMessagesManager = new MqttRetainedMessagesManager(_eventContainer, _rootLogger); _clientSessionsManager = new MqttClientSessionsManager(options, _retainedMessagesManager, _eventContainer, _rootLogger); _keepAliveMonitor = new MqttServerKeepAliveMonitor(options, _clientSessionsManager, _rootLogger); }
public MqttSession( string clientId, bool isPersistent, IDictionary items, MqttServerOptions serverOptions, MqttServerEventContainer eventContainer, MqttRetainedMessagesManager retainedMessagesManager, MqttClientSessionsManager clientSessionsManager) { Id = clientId ?? throw new ArgumentNullException(nameof(clientId)); IsPersistent = isPersistent; Items = items ?? throw new ArgumentNullException(nameof(items)); _serverOptions = serverOptions ?? throw new ArgumentNullException(nameof(serverOptions)); _clientSessionsManager = clientSessionsManager ?? throw new ArgumentNullException(nameof(clientSessionsManager)); SubscriptionsManager = new MqttClientSubscriptionsManager(this, eventContainer, retainedMessagesManager, clientSessionsManager); }