Esempio n. 1
0
        /// <summary>
        /// Handles the subscription of a new TopicPartition to this fetcher.
        /// Keeps track of the subscribed partitions in order to not fetch messages if the FlowControlState is Closed.
        /// </summary>
        /// <param name="topicPartition"></param>
        /// <returns></returns>
        public IDisposable Subscribe(TopicPartition topicPartition)
        {
            _topicPartitions.Add(topicPartition);
            EtwTrace.Log.FetcherPartitionSubscribed(_id, topicPartition.PartitionId);

            // cleanup
            var topicPartitionCleanup = Disposable.Create(() => _topicPartitions.Remove(topicPartition));
            var receivedMessagesSubscriptionCleanup = ReceivedMessages.
                                                      Where(rm => rm.Topic == topicPartition.Topic && rm.Partition == topicPartition.PartitionId)
                                                      .Subscribe(topicPartition);
            var flowControlCleanup = topicPartition.FlowControl.
                                     // we need to wake up from waiting loop any time flow control hits low watermark and becomes enabled
                                     Where(enabled => enabled).
                                     Subscribe(_ => _wakeupSignal.OnNext(true));

            var cleanup = new CompositeDisposable
            {
                topicPartitionCleanup,
                receivedMessagesSubscriptionCleanup,
                flowControlCleanup
            };

            if (_log.IsDebugEnabled)
            {
                cleanup.Add(Disposable.Create(() => _log.Debug("Fetcher #{0} {1} topicPartition is unsubscribing", _id, topicPartition)));
            }

            _log.Debug("Fetcher #{0} added {1}", _id, topicPartition);

            return(cleanup);
        }
        private void StartConsumeMessages()
        {
            var canStart = !string.IsNullOrEmpty(ZookeeperHostServer) &&
                           !string.IsNullOrEmpty(KafkaHostServer) &&
                           TopicItems.Any() &&
                           !string.IsNullOrEmpty(SelectedTopic);

            if (!canStart)
            {
                MessageBox.Show("Can't start consumer, please check zookeeper host, kafka host and selected topic!");
                return;
            }
            ReceivedMessages.Clear();
            Tables.Clear();
            _cancelConsume = new CancellationTokenSource();
            CurrentStatus  = $"Consuming messages from topic:{SelectedTopic} ...";
            DEKafkaMessageViewer.Common.KafkaConsumer consumer = new Common.KafkaConsumer();
            var groupId = Guid.NewGuid().ToString();

            consumer.ConsumeAsync(KafkaHostServer, SelectedTopic, groupId, _cancelConsume, (resultMsg) =>
            {
                var msgBody = resultMsg.Message;
                EnableStop  = true;
                OnMessageConsumed(msgBody);
            });
        }
Esempio n. 3
0
        public AsyncTestDeDuplicatingActor(DeDuplicatingReceiverSettings settings, string persistenceId) : base(settings)
        {
            PersistenceId = persistenceId ?? Uri.EscapeUriString(Self.Path.ToStringWithoutAddress());

            CommandAsync <TestDeDuplicatingActor.ConfirmableMsg>(async c =>
            {
                _log.Info("async Received {0}", c);
                await Task.Delay(10);
                ReceivedMessages.Add(c.Msg);
                ConfirmAndReply(c);
                _log.Info("await Confirmed {0}", c);
            });

            Command <string>(str => str.Equals("crash"), str => { Crash(); });

            Command <string>(str => str.Equals("canConfirm"), str => { Sender.Tell(IsCurrentMessageConfirmable); });

            CommandAsync <string>(async str =>
            {
                _log.Info("async Received {0}", str);
                await Task.Delay(10);
                if (IsCurrentMessageConfirmable)
                {
                    ReceivedMessages.Add(str);
                    ConfirmAndReply(str);
                }
                _log.Info("await Processed {0}", str);
            });
        }
Esempio n. 4
0
        /// <summary>
        /// Handles the event raised after a mod message is received
        /// </summary>
        /// <param name="sender">The sender of the ModMessageReceived event</param>
        /// <param name="args">Event arguments for the ModMessageReceived event</param>
        public void OnModMessageReceived(object sender, ModMessageReceivedEventArgs args)
        {
            Message message = args.ReadAs <Message>();

            ReceivedMessages.TryAdd(args.Type, new List <Message>());
            ReceivedMessages[args.Type].Add(message);
        }
Esempio n. 5
0
 private void ReceivedNewMessage(string message)
 {
     App.Current.Dispatcher.Invoke(() =>
     {
         ReceivedMessages.Add(message);
     });
 }
Esempio n. 6
0
    // Lives in a thread!
    public void ReadMessages()
    {
        //CheckersMessage nextMessage;
        NetworkStream netStream = Client.GetStream();
        int           bytesRead = 0;

        byte[] bufferFiller = new byte[2048];         // 2048 is just the read batch size, doesn't really matter how big it is
        while (Client.Connected)
        {
            // fill up the read buffer. okay to block here!
            while (netStream.DataAvailable)
            {
                // bufferFiller is just an intermediate data location, so overwriting it is fine.
                bytesRead = netStream.Read(bufferFiller, 0, bufferFiller.Length);
                ReadBuffer.Write(bufferFiller, 0, bytesRead);
                ReadBuffer.Seek(0, SeekOrigin.Begin);
            }

            // get a message if there is one. If there's an InvalidProtocolBufferException, trust/hope
            // that it happened because a delimited message was only partially transmitted upon
            // calling ParseDelimitedFrom

            try{
                ReceivedMessages.Enqueue(parser.ParseDelimitedFrom(ReadBuffer));
                //nextMessage = parser.ParseDelimitedFrom(ReadBuffer);
                //ReceivedMessages.Enqueue(nextMessage);
                ClearReadBufferBeforeCurrentPosition();
            } catch (InvalidProtocolBufferException) {
                // Message wasn't ready;
                //Console.WriteLine (e.Message);
            }
            // don't check too frequently
            Thread.Sleep(100);
        }
    }
Esempio n. 7
0
        /// <summary>
        /// User Data Relay received event handler.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event args.</param>
        private void UserDataRelayReceived(object sender, UserDataRelayReceivedEventArgs e)
        {
            UserDataRelayMessage message = e.UserDataRelayMessage;

            // Add the message to the list.
            ReceivedMessages.Add(string.Format("[{0}] {1}", message.SourceInterface.GetDescription(), Encoding.Default.GetString(message.Data)));
        }
        public string Transact(string dpInputString)
        {
            DataPacket dpInputPacket = new DataPacket();

            try
            {
                dpInputPacket = JsonConvert.DeserializeObject <DataPacket>(dpInputString);
                //dpInputPacket.Message = "ACK. " + dpInputPacket.Message;
                //dpInputPacket.TimeStamp = DateTime.Now;
                //string strSenderName = dpInputPacket.RecepientID;
                //string strReceiverName = dpInputPacket.SenderID;

                //dpInputPacket.SenderID = strSenderName;
                //dpInputPacket.RecepientID = strReceiverName;
                Console.WriteLine("Enqueue web St. " + DateTime.Now.ToString("yyyyMMdd HH:mm:ss:fff") + " Msg: " + ReceivedMessages.Count + " TID: " + Thread.CurrentThread.ManagedThreadId);
                ReceivedMessages.Enqueue(dpInputPacket);
                Console.WriteLine("Enqueue web St. " + DateTime.Now.ToString("yyyyMMdd HH:mm:ss:fff") + " Msg: " + ReceivedMessages.Count + " TID: " + Thread.CurrentThread.ManagedThreadId);
                DataPacket Ack = new DataPacket();
                Ack               = JsonConvert.DeserializeObject <DataPacket>(dpInputString);
                Ack.SenderID      = InstanceName;
                Ack.SenderType    = AppType.Server;
                Ack.RecepientID   = dpInputPacket.SenderID;
                Ack.RecepientType = dpInputPacket.SenderType;
                Ack.Message       = "ACK." + Ack.Message;
                Ack.Type          = PacketType.Acknowledge;
                Ack.TimeStamp     = DateTime.Now;
                return(JsonConvert.SerializeObject(Ack));
            }
            catch (Exception ex)
            {
                dpInputPacket.Message = "Error while processing input." + ex.Message;
            }
            return(JsonConvert.SerializeObject(dpInputPacket));
        }
Esempio n. 9
0
 public void ConnectToServer()
 {
     ReceivedMessages.TryAdd("", "Please input your desired username...");
     Task connectingTask = Task.Run(() =>
     {
         int i = 0;
         if (_connection.EstablishConnection().Result || i < 100)
         {
             i = 0;
             while (_inputMessage == null || i < 1000)
             {
                 i++;
             }
             if (i < 90)
             {
                 _connection.Disconnect();
                 ReceivedMessages.TryAdd("", "Connection timeout. Please try re-connecting.");
                 OnPropertyChanged(nameof(ReceivedMessages));
                 return;
             }
             _userName    = InputMessage;
             InputMessage = "";
             if (_connection.RegisterUsername(_userName).Result)
             {
                 getMessagesTask.Start();
             }
         }
         else
         {
             _connection.Disconnect();
             ReceivedMessages.TryAdd("", "Connection Failed.");
             OnPropertyChanged(nameof(ReceivedMessages));
         }
     });
 }
Esempio n. 10
0
        MessagePayload ReceiveMessage()
        {
            lock (ReceiveLock)
            {
                lock (AliveLock)
                {
                    if (DeathException != null)
                    {
                        throw DeathException;
                    }
                }

                try
                {
                    var framer  = new MessageFramer(NetworkConfig.Magic);
                    var message = framer.NextMessage(Stream);
                    ReceivedMessages.Add(message);
                    return(message);
                }
                catch
                {
                    lock (AliveLock)
                    {
                        if (DeathException == null)
                        {
                            Alive          = false;
                            DeathException = new ConnectionDeadException("ReceiveMessage threw exception.");
                        }
                    }
                    throw DeathException;
                }
            }
        }
Esempio n. 11
0
        public void AddMessage(Guid id, int sequence, string originator, string text, string endpoint)
        {
            string       messageId  = id.ToString() + ":" + sequence;
            RumorMessage newMessage = new RumorMessage(messageId, originator, text, endpoint);

            newMessage.ReceivedStamp = DateTime.Now;
            ReceivedMessages.Add(newMessage);
        }
        public virtual Task <bool> Handle(T message)
        {
            ReceivedMessages.Add(message);

            OnHandle?.Invoke(message);

            return(Task.FromResult(ShouldSucceed));
        }
Esempio n. 13
0
        /// <summary>
        /// Receive the current messages from the Twilio sms gateway
        /// </summary>
        /// <returns></returns>
        public Task <IEnumerable <SmsMessage> > ReceiveMessages()
        {
            List <SmsMessage> results = new List <SmsMessage>();

            results.AddRange(ReceivedMessages);
            ReceivedMessages.Clear();
            return(Task.FromResult(results as IEnumerable <SmsMessage>));
        }
Esempio n. 14
0
 private void btnClearMessages_Click(object sender, RoutedEventArgs e)
 {
     while (ReceivedMessages.Count > 0)
     {
         ReceivedMessages[0].DeleteTemporaryDocumentFiles();
         ReceivedMessages.RemoveAt(0);
     }
 }
Esempio n. 15
0
 private void TtsHelperMessageReceived(object sender,
                                       ReceivedMessageEventArgs e)
 {
     DispatcherHelper.UIDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         ReceivedMessages.Add(e.Message);
     });
 }
Esempio n. 16
0
            public void HandleMessage(NsqSharp.IMessage message)
            {
                (var body, var correlationId) = GetFromMessageBody(message.Body);
                Try.Do(message.Finish, false);
                var rMsg = ReceivedMessages.GetOrAdd(correlationId, cId => new NSQueueMessage());

                rMsg.Body = body;
                rMsg.WaitHandler.Set();
            }
Esempio n. 17
0
 public void AddMessage(RumorMessage message)
 {
     if (ReceivedMessages.Contains(message))
     {
         return;
     }
     message.ReceivedStamp = DateTime.Now;
     ReceivedMessages.Add(message);
 }
Esempio n. 18
0
 private void NewMessageReceived(string message)
 {
     //write new message in collection to display in gui
     //switch thread to gui thread to avoid problems
     App.Current.Dispatcher.Invoke(() =>
     {
         ReceivedMessages.Add(message);
     });
 }
        private void ShowDEKafkaMessageInfo(object msg, string rawXml)
        {
            DEKafkaMessageViewModel vm = new DEKafkaMessageViewModel(rawXml, msg);

            CurrentDispatcher.Invoke(() =>
            {
                ReceivedMessages.Add(vm);
                ShowChangedRecords(msg);
            });
        }
    public static T ReceivedNoCalls <T>(this T substitute, ReceivedCallsConstraint receivedCallsConstraint) where T : class
    {
        if (substitute.ReceivedCalls().Any(receivedCallsConstraint.FailWhenMatched))
        {
            var message = ReceivedMessages.ReceivedNoCallsMatchingPredicateMessageFor(substitute, receivedCallsConstraint.FailWhenMatched, receivedCallsConstraint.ConstraintDescription);
            throw new CallSequenceNotFoundException(message);
        }

        return(substitute);
    }
Esempio n. 21
0
 public LiteDBStorage(IOptions <CapOptions> capOptions, IOptions <LiteDBOptions> ldboption)
 {
     _capOptions       = capOptions;
     _ldboption        = ldboption.Value;
     _lite             = new LiteDatabase(_ldboption.ConnectionString);
     PublishedMessages = _lite.GetCollection <LiteDBMessage>(nameof(PublishedMessages));
     PublishedMessages.EnsureIndex(l => l.Id, true);
     ReceivedMessages = _lite.GetCollection <LiteDBMessage>(nameof(ReceivedMessages));
     ReceivedMessages.EnsureIndex(l => l.Id, true);
 }
Esempio n. 22
0
 public virtual void Receive <TMessage>(Action <TMessage> handler) where TMessage : ITweakMessage
 {
     Messenger.Register <TMessage>(message =>
     {
         if (!DoReceive)
         {
             return;
         }
         ReceivedMessages.Add("Rx: " + message);
         handler(message);
     });
 }
    public static T ReceivedOnly <T>(this T substitute, Quantity requiredQuantity) where T : class
    {
        if (!requiredQuantity.Matches(substitute.ReceivedCalls()))
        {
            throw new ReceivedCallsException(
                      ReceivedMessages.ReceivedDifferentCountThanExpectedCallsMessageFor(
                          substitute,
                          requiredQuantity.Describe("call total on this substitute", "calls total on this substitute")));
        }

        return(substitute.Received(requiredQuantity));
    }
Esempio n. 24
0
 private void ExecuteSend()
 {
     client.Send(ChatName + ": " + Message);
     if (Message != "@quit")
     {
         ReceivedMessages.Add("ME: " + Message);
     }
     else
     {
         Disconnect();
         ReceivedMessages.Add("You disconnected");
     }
 }
Esempio n. 25
0
        /// <summary>
        /// Checks for new messages from a particular farmer that haven't been handled yet
        /// </summary>
        /// <param name="address">Destination address to check for message</param>
        /// <param name="sender">ID of Farmer that sent a message</param>
        /// <returns></returns>
        public IEnumerable <Message> RetrieveMessages(string address, long sender = -1)
        {
            ReceivedMessages.TryAdd(address, new List <Message>());

            List <Message> messages = new List <Message>(ReceivedMessages[address]);

            foreach (Message message in messages)
            {
                if (sender == -1 || sender == message.Sender)
                {
                    Network.Instance.ReceivedMessages[address].Remove(message);
                    yield return(message);
                }
            }
        }
Esempio n. 26
0
 void Listener_Notify(object sender, NotifyEventArgs e)
 {
     if (e.Type == NotifyType.Received)
     {
         ReceivedMessages.Add(e.Message);
     }
     else if (e.Type == NotifyType.Sent)
     {
         SentMessages.Add(e.Message);
     }
     else
     {
         Messages.Add(e.Message);
     }
 }
Esempio n. 27
0
        // UWP App <- Azure Function    [Receiver]
        public static async Task ReceiveMessageAsync(DeviceClient deviceClient, ReceivedMessages receivedMessages)
        {
            while (true)
            {
                // Försök hämta meddelande/"payload" från Azure Function
                var payload = await deviceClient.ReceiveAsync();

                // Uppdatera lista och radera meddelande från kö (om det finns innehåll)
                if (payload != null)
                {
                    receivedMessages.Insert(0, new ReceivedMessageModel(Encoding.UTF8.GetString(payload.GetBytes())));
                    await deviceClient.CompleteAsync(payload);
                }
            }
        }
Esempio n. 28
0
        async Task OnMessageReceived(IMessage message)
        {
            if (Delay > TimeSpan.Zero)
            {
                await Task.Delay(Delay);
            }

            ReceivedMessages.Add(message);

            if (!(message is ISilverbackEvent) &&
                MustFailCount > FailCount || (FailCondition?.Invoke(message) ?? false))
            {
                FailCount++;
                throw new Exception("Test failure");
            }
        }
Esempio n. 29
0
        /// <summary>
        ///     Handlers the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="eventArgs">The <see cref="MessageEventArgs{T}" /> instance containing the event data.</param>
        private void Handler(object sender, MessageEventArgs <T> eventArgs)
        {
            ReceivedMessages.Add(eventArgs);

            if (Filter != null)
            {
                if (Filter(eventArgs))
                {
                    MessageReceived.Set( );
                }
            }
            else
            {
                MessageReceived.Set( );
            }
        }
        public string TransactMin(string Sender, string Receiver, string Message)
        {
            DataPacket dpInputPacket  = new DataPacket();
            DataPacket dpOutputPacket = new DataPacket();

            try
            {
                dpInputPacket.IsManualCmd   = true;
                dpInputPacket.Message       = Message;
                dpInputPacket.MsgID         = DateTime.Now.ToString("ss");
                dpInputPacket.SenderID      = Sender;
                dpInputPacket.SenderType    = AppType.Moderator;
                dpInputPacket.RecepientID   = Receiver;
                dpInputPacket.RecepientType = AppType.Client;
                dpInputPacket.Type          = PacketType.Request;
                dpInputPacket.TimeStamp     = DateTime.Now;

                Console.WriteLine("Enqueue web2 St. " + DateTime.Now.ToString("yyyyMMdd HH:mm:ss:fff") + " Msg: " + ReceivedMessages.Count + " TID: " + Thread.CurrentThread.ManagedThreadId);
                ReceivedMessages.Enqueue(dpInputPacket);
                Console.WriteLine("Enqueue web2 St. " + DateTime.Now.ToString("yyyyMMdd HH:mm:ss:fff") + " Msg: " + ReceivedMessages.Count + " TID: " + Thread.CurrentThread.ManagedThreadId);


                dpOutputPacket.IsManualCmd   = true;
                dpOutputPacket.Message       = "ACK." + Message;
                dpOutputPacket.MsgID         = DateTime.Now.ToString("ss");
                dpOutputPacket.SenderID      = InstanceName;
                dpOutputPacket.SenderType    = AppType.Server;
                dpOutputPacket.RecepientID   = Sender;
                dpOutputPacket.RecepientType = AppType.Moderator;
                dpOutputPacket.TimeStamp     = DateTime.Now;
                dpOutputPacket.Type          = PacketType.Acknowledge;


                return(JsonConvert.SerializeObject(dpOutputPacket));
            }
            catch (Exception ex)
            {
                dpOutputPacket.Message    = "Error while processing input." + ex.Message;
                dpOutputPacket.SenderID   = InstanceName;
                dpOutputPacket.SenderType = AppType.Server;
                dpOutputPacket.TimeStamp  = DateTime.Now;
                dpOutputPacket.Type       = PacketType.Acknowledge;
            }
            return(JsonConvert.SerializeObject(dpOutputPacket));
        }