private void InternalSendTotMQTT(USeMarketData marketData) { try { CreateMQChannel(); byte[] body = CreateMQTTBody(marketData); if (marketData.Instrument.Market == USeMarket.LME) { m_mqttClient.Publish(m_topicLME, body, MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); Interlocked.Increment(ref m_sotreCount); } else { m_mqttClient.Publish(m_topic, body, MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); Interlocked.Increment(ref m_sotreCount); } Debug.WriteLine(string.Format("时间:{0} 合约:{1} 最新价:{2} body:{3}", marketData.QuoteTime, marketData.Instrument.InstrumentCode, marketData.ClosePrice, body)); } catch (Exception ex) { Interlocked.Increment(ref m_errorStoreCount); string text = string.Format("{0}发送MQTT实时行情数据失败,{1}", this, ex.Message); m_eventLogger.WriteError(text); USeNotifyEventArgs notify = new USeNotifyEventArgs(USeNotifyLevel.Warning, text); SafeRaiseNotifyEvent(this, notify); } }
public override void HandleCommand(string attribute, string payload) { if (!IsEnabled) { return; } int step; switch (attribute) { case "up": step = $"{payload}" != "" ? payload.Convert <int>() : 1; Audio.Volume(Audio.GetVolume() + step); MqttConnection.Publish(AudioVolumeMqttMessage()); break; case "down": step = $"{payload}" != "" ? payload.Convert <int>() : 1; Audio.Volume(Audio.GetVolume() - step); MqttConnection.Publish(AudioVolumeMqttMessage()); break; case "level": Audio.Volume(payload.Convert <int>()); MqttConnection.Publish(AudioVolumeMqttMessage()); break; case "mute": switch (payload.ToLower()) { case "1": case "on": Audio.Mute(true); break; case "0": case "off": Audio.Mute(false); break; } MqttConnection.Publish(AudioMuteMqttMessage()); break; case "mute_toggle": Audio.Mute(!Audio.IsMuted()); MqttConnection.Publish(AudioMuteMqttMessage()); break; default: break; } }
void PublishNext(MqttConnection conn) { byte[] bytes = new byte[0]; if (Qos == MqttQos.AtMostOnce) { // if is qos 0, assume the packet will be delivered this.published += 1; } ushort packetId = conn.Publish(TopicToPublish, bytes, Qos); Console.WriteLine("{0} >> broker : Delivering {1} : PUBLISH packet_id:{2}", ClientId, this.published, packetId); }
void PublishNext(MqttConnection conn) { int i; this.previousPublishedNumber = i = this.previousPublishedNumber + 1; byte[] bytes = MakePayload(i); if (Qos == MqttQos.AtMostOnce) { // if is qos 0, assume the number was published numbersPersistence.RegisterPublishedNumber(i); } ushort packetId = conn.Publish(TopicToPublish, bytes, Qos); Console.WriteLine("{0} >> broker : Delivering {1} (PUBLISH packet_id:{2})", ClientId, i, packetId); }
public void SendUpdateStatusMessages() { if (!IsEnabled) { return; } var msgs = PrepareUpdateStatusMessages(); if (msgs == null) { return; } foreach (var msg in msgs) { MqttConnection.Publish(msg); } }
public void SendDiscoveryMessages() { if (!IsEnabled) { return; } var msgs = PrepareDiscoveryMessages(); if (msgs == null) { return; } foreach (var msg in msgs) { MqttConnection.Publish(msg); } }