Example #1
0
        private void OnMessage(string clientId, MqttApplicationMessage message)
        {
            var    container = _serializer.Deserialize <PacketContainer>(message.Payload);
            object packet    = JsonConvert.DeserializeObject(container.Content, container.Type);

            switch (packet)
            {
            case BaseRequest request:
                OnRequest(request, container.Type);
                break;
            }
        }
Example #2
0
        private async Task Client_OnMessage(MqttApplicationMessageReceivedEventArgs message)
        {
            Console.WriteLine("Received message from topic : " + message.ApplicationMessage.Topic);
            MessageReceived.WithLabels(_options.ClientOptions.ClientId, message.ApplicationMessage.Topic).Inc();
            var    container = _serializer.Deserialize <PacketContainer>(message.ApplicationMessage.Payload);
            object packet    = JsonConvert.DeserializeObject(container.Content, container.Type);

            switch (packet)
            {
            case IAsyncRpcRequest request:
                await _packetHandlersContainer.HandleAsync(request, container.Type);

                break;
            }
        }
Example #3
0
        private void OnMessage(string clientId, MqttApplicationMessage message)
        {
            var    container = _serializer.Deserialize <PacketContainer>(message.Payload);
            object packet    = JsonConvert.DeserializeObject(container.Content, container.Type);

            if (!(packet is BaseResponse response))
            {
                return;
            }

            if (!_pendingRequests.TryGetValue(response.RequestId, out PendingRequest request))
            {
                return;
            }

            request.Response.SetResult(response);
        }