|
|
|
using EC.UsingEventAggregator;
|
|
|
|
using EC.Utils;
|
|
|
|
using EC.Utils.ZMQ;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace ECMonitor.Code
|
|
|
|
{
|
|
|
|
public class ZMQManager
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// 通用zmq
|
|
|
|
/// </summary>
|
|
|
|
private static ZMQHelper _zmqHelper;
|
|
|
|
|
|
|
|
public event EventHandler<PubSubModel> OnDataReceived; //定义一个委托类型的事件
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SubDataReceived(object sender, PubSubModel msgModel)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
OnDataReceived?.Invoke(sender, msgModel);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
LogFactory.GetLogger().Error(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Send(string topic, string msg)
|
|
|
|
{
|
|
|
|
_zmqHelper.Send(topic, msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|