添加项目文件。
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using CommonDomain;
|
||||
using CommonDomain.BaseModel;
|
||||
using DotNetCore.CAP;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace UserService.Hubs
|
||||
{
|
||||
public class AssetSyncFrontendSubscriber : ICapSubscribe
|
||||
{
|
||||
private readonly IHubContext<LoginHub> _hubContext;
|
||||
private readonly ILogger<AssetSyncFrontendSubscriber> _logger;
|
||||
|
||||
public AssetSyncFrontendSubscriber(IHubContext<LoginHub> hubContext, ILogger<AssetSyncFrontendSubscriber> logger)
|
||||
{
|
||||
_hubContext = hubContext;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[CapSubscribe(TopicKeys.用户资产同步前端)]
|
||||
public async Task HandleUserAssetSync(UserAssetSyncParam param)
|
||||
{
|
||||
if (param == null || string.IsNullOrWhiteSpace(param.UserId))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
await _hubContext.Clients.Group(param.UserId).SendAsync("AssetUpdated", new
|
||||
{
|
||||
param.CurrencyType,
|
||||
param.ChangeType,
|
||||
param.Amount,
|
||||
param.NewGold,
|
||||
param.NewDiamond,
|
||||
param.Source,
|
||||
param.Remark
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "AssetUpdated推送失败 userId={UserId} currencyType={CurrencyType}",
|
||||
param.UserId, param.CurrencyType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user