コード例 #1
0
ファイル: Chat.cs プロジェクト: verloka/Networking
 /// <summary>
 /// Init the connection
 /// </summary>
 /// <returns></returns>
 public void Init()
 {
     Connection.On <List <string> >("SendGroups", (e) => { OnGroups?.Invoke(this, new GroupsArgs(e)); });
     Connection.On <Message>("Send", (e) => { OnMessage?.Invoke(this, new MessageEventArgs(e)); });
     Connection.On <Message>("PM", (e) => { OnMessage?.Invoke(this, new MessageEventArgs(e)); });
     Connection.On <List <Message> >("SendBulk", (e) => { OnMessages?.Invoke(this, new MessagesEventArgs(e)); });
     Connection.On <LoginData>("Connected", (e) => { OnConnected?.Invoke(this, new AlertArgs(e)); });
     Connection.On <LoginData>("Disconnected", (e) => { OnDisconnected?.Invoke(this, new AlertArgs(e)); });
 }
コード例 #2
0
        public BasicConsumer(string validQueueName, IModel model, CancellationToken?cancellationToken = null, ILogger consumerErrorLogger = null) : base(validQueueName, model)
        {
            //start consumimg

            Task.Run(() =>
            {
                base.HandleMultipleMessagesAsync(async msgs =>
                {
                    if (OnMessagesAsync != null)
                    {
                        await OnMessagesAsync?.Invoke((BasicMessage[])msgs);
                    }
                });

                base.HandleMultipleMessages(msgs =>
                {
                    if (OnMessages != null)
                    {
                        OnMessages?.Invoke((BasicMessage[])msgs);
                    }
                });

                base.HandleMessageAsync(async msg =>
                {
                    if (OnMessageAsync != null)
                    {
                        await OnMessageAsync?.Invoke((BasicMessage)msg);
                    }
                });


                base.HandleMessage(msg =>
                {
                    if (OnMessage != null)
                    {
                        OnMessage?.Invoke((BasicMessage)msg);
                    }
                });

                base.HandleMessageError((ex, msg) =>
                {
                    consumerErrorLogger?.LogError(ex, $"{ex.Message}\r\nQueueName:{validQueueName}", $"MaxFetchCount:{base.MaxFetchCount}", msg?.ToJsonString());
                });
            });
        }
コード例 #3
0
            public void Enqueue(T message)
            {
                if (OnMessages == null)
                {
                    throw new LogReadyException(LogTag.OnMessagesListenerRequired);
                }
                if (OnQueueOverflow == null)
                {
                    throw new LogReadyException(LogTag.OnQueueOverflowListenerRequired);
                }
                if (Queue.Count > MaxQueueLength)
                {
                    OnQueueOverflow.Invoke(); return;
                }

                lock (thisLock) {
                    Queue.Add(new QueuedMessage <T> {
                        OrderId = NextOrderId++,
                        Message = message
                    });
                    OnMessages.Invoke(Queue.Skip(Queue.Count - 1).ToList());
                }
            }
コード例 #4
0
            public void RequestResend(OrderId[] orderIds)
            {
                lock (thisLock) {
                    if (OnMessages == null)
                    {
                        throw new LogReadyException(LogTag.OnMessagesListenerRequired);
                    }
                    if (OnUnexpectedResendOrderIds == null)
                    {
                        throw new LogReadyException(LogTag.OnUnexpectedResendOrderIdListenerRequired);
                    }

                    // Collect and send messages to resend
                    var messagesToResend = Queue.Where(msg => orderIds.Contains <OrderId>(msg.OrderId)).ToList();
                    OnMessages.Invoke(messagesToResend);

                    // If we're missing one or more requested messages, something is deeply wrong somewhere
                    var missingIds = orderIds.Where(id => messagesToResend.All(msg => msg.OrderId != id)).Select(r => r.Value).ToArray();
                    if (missingIds.Length != 0)
                    {
                        OnUnexpectedResendOrderIds.Invoke($"Ids [{string.Join(",", missingIds)}] not in existing Ids {string.Join(",", Queue.Select(msg => msg.OrderId))}");
                    }
                }
            }