You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.9 KiB

using EC.UsingEventAggregator;
using EC.Utils;
using EC.Utils.ZMQ;
3 years ago
using System;
using System.Collections.Generic;
namespace ECMonitor.Code
{
public class ZMQManager
{
/// <summary>
/// 通用zmq
/// </summary>
private static ZMQHelper _zmqHelper;
public event EventHandler<PubSubModel> OnDataReceived; //定义一个委托类型的事件
3 years ago
public void Start()
{
try
{
string pubserver = ConfigHelper.PUBServer();
string subserver = ConfigHelper.SUBServer();
List<string> topics = SUBTopicList();
_zmqHelper = new ZMQHelper(pubserver, subserver, topics);
_zmqHelper.OnSubData += SubDataReceived;
_zmqHelper.Start();
}
catch (Exception ex)
3 years ago
{
FLogger.Error(ex);
}
}
internal static List<string> SUBTopicList()
{
List<string> topicList = new List<string>();
topicList.Add("Topic");
topicList.Add(ZMQTopic.Show_Single_Video + ConfigHelper.AppId);
topicList.Add(ZMQTopic.MainFrom_Show_Video + ConfigHelper.AppId);
topicList.Add(ZMQTopic.MainFrom_Show_Video);
topicList.Add(ZMQTopic.AI_Detect_Warning_Data);
return topicList;
}
public void Stop()
{
_zmqHelper?.Stop();
3 years ago
}
3 years ago
private void SubDataReceived(object sender, PubSubModel msgModel)
{
try
{
OnDataReceived?.Invoke(sender, msgModel);
}
catch (Exception ex)
{
LogFactory.GetLogger().Error(ex);
}
}
3 years ago
public void Send(string topic, string msg)
{
_zmqHelper.Send(topic, msg);
3 years ago
}
}
}