private void ReceiveAttributes(MqttApplicationMessageReceivedEventArgs e) { var tps = e.ApplicationMessage.Topic.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); var rpcmethodname = tps[2]; var rpcdevicename = tps[1]; var rpcrequestid = tps[4]; LogInformation?.Invoke($"rpcmethodname={rpcmethodname} "); LogInformation?.Invoke($"rpcdevicename={rpcdevicename } "); LogInformation?.Invoke($"rpcrequestid={rpcrequestid} "); if (!string.IsNullOrEmpty(rpcmethodname) && !string.IsNullOrEmpty(rpcdevicename) && !string.IsNullOrEmpty(rpcrequestid)) { if (e.ApplicationMessage.Topic.Contains("/attributes/")) { OnReceiveAttributes?.Invoke(Client, new AttributeResponse() { KeyName = rpcmethodname, DeviceName = rpcdevicename, Id = rpcrequestid, Data = e.ApplicationMessage.ConvertPayloadToString() }); } } }
private void Client_ApplicationMessageReceived(object sender, MqttApplicationMessageReceivedEventArgs e) { _logger.LogDebug($"ApplicationMessageReceived Topic {e.ApplicationMessage.Topic} QualityOfServiceLevel:{e.ApplicationMessage.QualityOfServiceLevel} Retain:{e.ApplicationMessage.Retain} "); try { if (e.ApplicationMessage.Topic.StartsWith($"/devices/") && e.ApplicationMessage.Topic.Contains("/response/")) { var tps = e.ApplicationMessage.Topic.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); var rpcmethodname = tps[2]; var rpcdevicename = tps[1]; var rpcrequestid = tps[4]; _logger.LogInformation($"rpcmethodname={rpcmethodname} "); _logger.LogInformation($"rpcdevicename={rpcdevicename } "); _logger.LogInformation($"rpcrequestid={rpcrequestid} "); if (!string.IsNullOrEmpty(rpcmethodname) && !string.IsNullOrEmpty(rpcdevicename) && !string.IsNullOrEmpty(rpcrequestid)) { if (e.ApplicationMessage.Topic.Contains("/attributes/")) { OnReceiveAttributes?.Invoke(Client, new AttributeResponse() { KeyName = rpcmethodname, DeviceName = rpcdevicename, Id = rpcrequestid, Data = e.ApplicationMessage.ConvertPayloadToString() }); } else { OnExcCommand?.Invoke(Client, new RpcRequest() { Command = rpcmethodname, DeviceName = rpcdevicename, RequestId = rpcrequestid, Params = e.ApplicationMessage.ConvertPayloadToString() }); } } } } catch (Exception ex) { _logger.LogError($"ClientId:{e.ClientId} Topic:{e.ApplicationMessage.Topic},Payload:{e.ApplicationMessage.ConvertPayloadToString()}", ex); } }