コード例 #1
0
        public static async Task ProcessQueueAsync(IReliableStateManager stateManager,
                                                   IConversationCtrlAppService conversationCtrlAppService,
                                                   Func <Guid, INotifySessionActor> notifySessionActorFactory,
                                                   CancellationToken cancellationToken)
        {
            var queueMessageProcess = await Service.GetMessageProcessQueue(stateManager);

            while (!cancellationToken.IsCancellationRequested)
            {
                using (var tx = stateManager.CreateTransaction())
                {
                    var msgWrap = await queueMessageProcess.TryDequeueAsync(tx);

                    if (msgWrap.HasValue)
                    {
                        var item = msgWrap.Value;

                        await SaveMsgAsync(stateManager, tx, item);

                        await PushNotifyAsync(conversationCtrlAppService, notifySessionActorFactory, item);
                    }
                    else
                    {
                        await tx.CommitAsync();

                        await Task.Delay(100);
                    }
                }
            }
        }
コード例 #2
0
 public InstantMessageController(
     IConversationCtrlAppService conversationCtrlAppService,
     Func <Guid, IConversationMsgAppService> conversationMsgAppServiceFactory,
     Func <Task <IEnumerable <IConversationMsgAppService> > > allConversationMsgAppServiceFactory,
     IEmployeeCacheService employeeMappingService,
     IGroupAppService groupAppService,
     IDepartmentAppService departmentAppService
     )
 {
     _conversationCtrlAppService       = conversationCtrlAppService;
     _conversationMsgAppServiceFactory = conversationMsgAppServiceFactory;
     _logger = Log.ForContext <InstantMessageController>();
     _allConversationMsgAppServiceFactory = allConversationMsgAppServiceFactory;
     _employeeMappingService = employeeMappingService;
     _groupAppService        = groupAppService;
     _departmentAppService   = departmentAppService;
 }
コード例 #3
0
        private static async Task PushNotifyAsync(
            IConversationCtrlAppService conversationCtrlAppService,
            Func <Guid, INotifySessionActor> notifySessionActorFactory,
            ConversationMsg item)
        {
            try
            {
                var entityConversationWrap = await conversationCtrlAppService.GetByIdAsync(item.ConversationId);

                if (entityConversationWrap.HasValue)
                {
                    var entityConversation = entityConversationWrap.Value;

                    var tasks = new List <Task>();
                    foreach (var userId in entityConversation.Participants)
                    {
                        var actorSession = notifySessionActorFactory(userId);
                        tasks.Add(actorSession.PushMsgNotifyAsync(new MessageNotifyDto
                        {
                            Target         = NotifyTargetType.Conversation,
                            TargetId       = item.ConversationId.ToString(),
                            TargetCategory = (int)entityConversation.Type,
                            LatestMsgId    = item.Id,
                        }));
                    }
                    await Task.WhenAll(tasks);
                }
            }
            catch (Exception ex)
            {
                //如果PushMsgNotifyAsync过程出错,也实现保存消息的过程,只是会出现接收方接收不到消息
                Log.Error("ConversationMsgQueueProcessor PushMsgNotifyAsync Message: " +
                          $"ItemId is {item.Id}, ConversationId is {item.ConversationId}, SenderId is {item.SenderId}, Message is {ex.Message}");
                if (IsInUnitTest)
                {
                    throw;
                }
            }
        }