优化Redis发布订阅
This commit is contained in:
parent
0d2371d881
commit
12e407f523
@ -1 +1 @@
|
||||
Subproject commit 3ef9c78974a2d08b8fd73042951d3481d3d32291
|
||||
Subproject commit 125082c75bd469f43f2e445e488a3c425a804fc6
|
||||
@ -41,6 +41,9 @@ namespace JiShe.ServicePro.OneNETManagement.Subscribers
|
||||
{
|
||||
// 为订阅回调创建独立的 FreeSql 客户端
|
||||
var callbackFreeSqlDbContext = FreeSqlDbContext;
|
||||
var callbackFreeSql = RedisProvider;
|
||||
|
||||
|
||||
// 订阅频道
|
||||
await _redisPubSubService.SubscribeReliableAsync<DeviceStatusMessage>(RedisConst.ServiceCommunicationDeviceStatusEventName, async (message) =>
|
||||
{
|
||||
@ -48,7 +51,7 @@ namespace JiShe.ServicePro.OneNETManagement.Subscribers
|
||||
{
|
||||
_logger.LogWarning($"Redis订阅收到设备状态消息: {message.Serialize()}");
|
||||
|
||||
HandDeviceStatus(message, callbackFreeSqlDbContext).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
HandDeviceStatus(message, callbackFreeSqlDbContext, callbackFreeSql).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -71,9 +74,10 @@ namespace JiShe.ServicePro.OneNETManagement.Subscribers
|
||||
/// </summary>
|
||||
/// <param name="deviceStatusMessage"></param>
|
||||
/// <param name="callbackFreeSqlDbContext"></param>
|
||||
/// <param name="callbackFreeRedisProvider"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
private async Task HandDeviceStatus(DeviceStatusMessage deviceStatusMessage, IFreeSqlProvider callbackFreeSqlDbContext)
|
||||
private async Task HandDeviceStatus(DeviceStatusMessage deviceStatusMessage, IFreeSqlProvider callbackFreeSqlDbContext, IFreeRedisProvider callbackFreeRedisProvider)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -100,7 +104,7 @@ namespace JiShe.ServicePro.OneNETManagement.Subscribers
|
||||
deviceEntity.LastOfflineTime = TimestampHelper.ConvertToDateTime(deviceStatusMessage.ReceivedTime, TimestampUnit.Milliseconds, DateTimeKind.Local);
|
||||
}
|
||||
|
||||
var updateResult = await FreeSqlDbContext.Instance.Update<DeviceManagementInfo>()
|
||||
var updateResult = await callbackFreeSqlDbContext.Instance.Update<DeviceManagementInfo>()
|
||||
.SetSource(deviceEntity)
|
||||
.UpdateColumns(a => new { a.DeviceOnlineStatus, a.LastOnlineTime, a.LastOfflineTime })
|
||||
.ExecuteAffrowsAsync();
|
||||
@ -117,7 +121,7 @@ namespace JiShe.ServicePro.OneNETManagement.Subscribers
|
||||
deviceCacheInfos.IoTPlatformResponse = null;
|
||||
deviceCacheInfos.PlatformPassword = null;
|
||||
|
||||
RedisProvider.Instance.HSet<DeviceCacheInfos>(RedisConst.CacheAllDeviceInfoHashKey, deviceEntity.DeviceAddress, deviceCacheInfos);
|
||||
callbackFreeRedisProvider.Instance.HSet<DeviceCacheInfos>(RedisConst.CacheAllDeviceInfoHashKey, deviceEntity.DeviceAddress, deviceCacheInfos);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user