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

98 lines
3.0 KiB
C#

using DSWeb.Common.Model;
using log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Quartz.Impl;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Topshelf;
namespace DSWeb.EventBus
{
public class EventProcessService : ServiceControl
{
private static ILog logger = LogManager.GetLogger("EventProcessService");
private ConnectionMultiplexer redis;
public bool Start(HostControl hostControl)
{
// 开始具体的业务逻辑
logger.Debug("开始运行");
try
{
redis = ConnectionMultiplexer.Connect(ConfigurationManager.AppSettings["RedisServerAddr"]);
redis.GetSubscriber().SubscribeAsync("EventMessage", (channel, value) =>
{
try
{
var str = value.ToString();
logger.Debug($"收到消息:{str}");
var jobj = JObject.Parse(str);
var strType = jobj.GetValue("type").ToString();
JObject jobjBody = jobj.GetValue("body") as JObject;
if (Enum.TryParse<EventMessageType>(strType, out EventMessageType type))
{
EventProcessChain.ProcessEvent(type, jobjBody);
}
else
{
logger.Error($"不支持的消息类型:{strType}");
}
}
catch (JsonException jex)
{
logger.Error($"json参数错误{jex.Message}");
logger.Error(jex.StackTrace);
}
catch (Exception ex)
{
logger.Error(ex.Message);
logger.Error(ex.StackTrace);
}
});
}
catch (Exception ex)
{
logger.Error("启动出错:");
logger.Error(ex.Message);
logger.Error(ex.StackTrace);
}
//账单中心东胜7回写接收状态
MqProcBillcenterDs7Feedback.DoProcess();
//大简云动作日志
MqProcActionLog.DoProcess();
//账单中心东胜6回写接收状态
MqProcBillcenterDs6Feedback.DoProcess();
return true;
}
public bool Stop(HostControl hostControl)
{
// 结束
logger.Debug("停止运行");
if (redis.IsConnected)
{
redis.GetSubscriber().UnsubscribeAll();
redis.Close();
}
MqProcBillcenterDs7Feedback.StopProcess();
MqProcActionLog.StopProcess();
return true;
}
}
}