Exemple #1
0
        private void OnMessage(Guid clientId, Message message)
        {
            var matchedAnyTopic = false;

            // dispatch the message to matched queues
            foreach (var topic in _topicStore.GetAll())
            {
                if (topic.MessageRouteMatch(message.Route))
                {
                    try
                    {
                        topic.OnMessage(message);
                        matchedAnyTopic = true;
                    }
                    // message was not written, probably the channel was completed due to being disposed
                    catch
                    {
                        _logger.LogError($"Failed to write message: {message.Id} to topic: {topic.Name}");
                    }
                }
            }

            if (matchedAnyTopic)
            {
                // send received ack to publisher
                SendReceivedPayloadOk(clientId, message.Id);
            }
            else
            {
                SendReceivePayloadError(clientId, message.Id, "No topic was found");
            }

            // must return the original message data to buffer pool
            message.Dispose();
        }
        private void ClientDisconnected(object clientSession, ClientSessionDisconnectedEventArgs eventArgs)
        {
            if (clientSession is IClient client)
            {
                _logger.LogInformation($"Client: {client.Id} removed");

                foreach (var queue in _topicStore.GetAll())
                {
                    queue.ClientUnsubscribed(client);
                }

                _clientStore.Remove(client);
            }
        }