public Task StartAsync(CancellationToken cancellationToken) { _offlineMessageService = _serviceProvider.CreateScope().ServiceProvider.GetRequiredService <IOfflineMessageService>(); _rabbitManager.Receiver("Cat.IM.OfflineMessage", x => { var offlineMessage = new OfflineMessage { Id = Guid.Parse(x.Chat.Info.Id), Body = x.Chat.Body, Sender = Guid.Parse(x.Chat.Info.Sender), Receiver = Guid.Parse(x.Chat.Info.Receiver), SendOn = Convert.ToDateTime(x.Chat.Info.SendOn), Type = x.Type }; _offlineMessageService.Add(offlineMessage); }, "Cat.IM.OfflineMessage"); return(Task.CompletedTask); }
public Task StartAsync(CancellationToken cancellationToken) { var routerKey = $"{_configuration["Service:IP"]}:{_configuration["Service:Port"]}"; _rabbitManager.Receiver(routerKey, x => { var context = SessionSocketHolder.Get(Guid.Parse(x.Chat.Info.Receiver)); if (context == null) { _logger.LogWarning($"用户[{x.Chat.Info.Receiver}]不在线!"); _rabbitManager.SendMsg("Cat.IM.OfflineMessage", x, "Cat.IM.OfflineMessage"); return; } context.WriteAndFlushAsync(x); }); return(Task.CompletedTask); }