Пример #1
0
        internal Type GetHandlerType(KMessage message)
        {
            if (message.Name == null)
            {
                throw new ArgumentNullException($"{nameof(KafkaConsumer)} exception: event Name is missing");
            }

            return(_options.Handlers.TryGetValue(message.Name, out var handlerType) ? handlerType : null);
        }
Пример #2
0
        // Implement Consumer interface
        public void Consume(CancellationToken cancellationToken,
                            Func <KMessage, Task> messageHandler,
                            Func <Error, Task> errorHandler,
                            Func <Message, Task> consumptionErrorHandler
                            )
        {
            _logger.LogDebug(LoggingEvents.Debug, $"Reading from Kafka streams.");

            if (this._consumer == null)
            {
                throw new InvalidOperationException("You need to setup Kafka Consumer before you can consume messages");
            }


            this._consumer.Subscribe(this._topics);

            this._consumer.OnMessage += async(_, msg) =>
            {
                // _logger.LogTrace(LoggingEvents.Trace,$"Read '{msg.Value}' from: {msg.TopicPartitionOffset}");
                // _logger.LogTrace(LoggingEvents.Trace,$"Topic: {msg.Topic} Partition: {msg.Partition} Offset: {msg.Offset} {msg.Value}");

                var payload = new KMessage()
                {
                    Topic     = msg.Topic,
                    Partition = msg.Partition,
                    Offset    = msg.Offset.Value,
                    Message   = msg.Value
                };
                await messageHandler(payload);

                await this._consumer.CommitAsync(msg);
            };

            this._consumer.OnError += async(_, error) =>
            {
                _logger.LogError(LoggingEvents.Error, $"Error: {error}");
                if (errorHandler != null)
                {
                    await errorHandler(error);
                }
            };

            this._consumer.OnConsumeError += async(_, msg) =>
            {
                _logger.LogError(LoggingEvents.Error, $"Consume error ({msg.TopicPartitionOffset}): {msg.Error}");

                if (consumptionErrorHandler != null)
                {
                    await consumptionErrorHandler(msg);
                }
            };

            while ((cancellationToken == null) || (!cancellationToken.IsCancellationRequested))
            {
                this._consumer.Poll(TimeSpan.FromMilliseconds(100));
            }
        }
Пример #3
0
        // Implement Consumer interface
        public IEnumerable <KMessage <T> > Consume(CancellationToken cancellationToken)
        {
            if (this._consumer == null)
            {
                throw new InvalidOperationException("You need to setup Kafka Consumer before you can consume messages");
            }

            _logger.LogDebug(LoggingEvents.Debug, $"Reading from Kafka streams.");

            var msgbuffer = new List <KMessage <T> >();


            this._consumer.Subscribe(this._topics);

            this._consumer.OnMessage += (_, msg) =>
            {
                // _logger.LogTrace(LoggingEvents.Trace,$"Read '{msg.Value}' from: {msg.TopicPartitionOffset}");
                // _logger.LogTrace(LoggingEvents.Trace,$"Topic: {msg.Topic} Partition: {msg.Partition} Offset: {msg.Offset} {msg.Value}");

                this._consumer.CommitAsync(msg);

                var payload = new KMessage <T>()
                {
                    Topic     = msg.Topic,
                    Partition = msg.Partition,
                    Offset    = msg.Offset.Value,
                    Message   = msg.Value
                };
                msgbuffer.Add(payload);
            };

            this._consumer.OnError += (_, error)
                                      => _logger.LogError(LoggingEvents.Error, $"Error: {error}");

            this._consumer.OnConsumeError += (_, msg)
                                             => _logger.LogError(LoggingEvents.Error, $"Consume error ({msg.TopicPartitionOffset}): {msg.Error}");

            while ((cancellationToken == null) || (!cancellationToken.IsCancellationRequested))
            {
                this._consumer.Poll(TimeSpan.FromMilliseconds(100));

                if (msgbuffer.Count > 0)
                {
                    foreach (var msg in msgbuffer)
                    {
                        yield return(msg);
                    }
                    msgbuffer.Clear();
                }
            }
        }
Пример #4
0
    IEnumerator HandleMessage(KMessage message)
    {
        // Instantear prefab
        GameObject target = Instantiate(messagePrefab);

        // Establecer posicion
        target.transform.SetParent(canvas);
        target.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0);
        // Conseguir cambiar el texto
        TextMeshProUGUI tmpro = target.transform.Find("Solid").Find("Text").GetComponent <TextMeshProUGUI>();

        tmpro.text = message.text;
        // Conseguir cambiar el color
        target.transform.Find("Solid").GetComponent <Image>().color = message.color;
        target.transform.Find("Solid").Find("Slider").Find("Background").GetComponent <Image>().color = message.color;
        // Conseguir functionar la cross xd
        Button but = target.transform.Find("Solid").Find("Cross").GetComponent <Button>();

        but.onClick.AddListener(() => DesactiveAnObject(target));
        // Ahora a hacer animacion
        Slider sli = target.transform.Find("Solid").Find("Slider").GetComponent <Slider>();

        sli.maxValue = message.time;
        for (float i = 0f; i < message.time; i += 0.02f)
        {
            sli.value = i;
            if (!target.activeSelf)
            {
                break;
            }
            yield return(new WaitForFixedUpdate());
        }

        Destroy(target);

        // Espera bonita para no estresar
        for (int i = 0; i < 50; i++)
        {
            yield return(new WaitForFixedUpdate());
        }
    }
Пример #5
0
        /// <summary>
        /// Send message
        /// </summary>
        /// <param name="lblTextEnvoi">String : Text to send</param>
        /// <param name="type">message | initialization</param>
        public void EnvoiDuMessage(string lblTextEnvoi, int type)
        {
            var kMessage = new KMessage(lblTextEnvoi, type);

            try
            {
                var enc = new UTF8Encoding();
                var msg = enc.GetBytes(kMessage.ReadyToSend());

                _sck.Send(msg);
                if (kMessage.GetMessageType() == KMessage.Type.Init().ToString())
                {
                    lbxTchat.Items.Add("Me : " + tbxMessageEnvoit.Text);
                    tbxMessageEnvoit.Clear();
                }
            }
            catch
            {
                MessageBox.Show("An error occured. \r\nPlease restart Kubeah Chat" + "\r\n" + "\r\n", "An error occurred");
                Application.Exit();
            }
        }
        private string GetMessage(IEvent @event)
        {
            var attribute = @event.GetType().GetCustomAttribute <EventAttribute>();

            if (attribute == null)
            {
                throw new ArgumentException($"{nameof(EventAttribute)} missing on {nameof(@event)}");
            }

            if (string.IsNullOrEmpty(attribute.Name))
            {
                throw new ArgumentNullException(
                          $"{nameof(EventAttribute)}.Name missing on {nameof(@event)}");
            }

            var message = new KMessage
            {
                Name      = attribute.Name,
                EventData = JsonConvert.SerializeObject(@event, Options.SerializerSettings)
            };

            return(JsonConvert.SerializeObject(message, Options.SerializerSettings));
        }
Пример #7
0
 public static void Message(KMessage.MessageType messageType, string text)
 {
     staticInterceptor.Invoke("message$$", "message(KMessage::MessageType, const QString&)", typeof(void), typeof(KMessage.MessageType), messageType, typeof(string), text);
 }
Пример #8
0
 public virtual void Message(KMessage.MessageType messageType, string text, string caption)
 {
     interceptor.Invoke("message$$$", "message(KMessage::MessageType, const QString&, const QString&)", typeof(void), typeof(KMessage.MessageType), messageType, typeof(string), text, typeof(string), caption);
 }
Пример #9
0
 public abstract void Message(KMessage.MessageType type, string text, string caption);
Пример #10
0
        /// <summary>
        /// The code for the method (Recipient connected/Disconnected) is integrated directly into the message sending function.
        /// It is likely to evolve and change place.
        /// The keys are used in this case as a means of comparison.
        /// </summary>
        /// <param name="aResult">Type IAsyncResult</param>
        private void MessageReceived(IAsyncResult aResult)
        {
            try
            {
                var size = _sck.EndReceiveFrom(aResult, ref _epRemote);
                if (size > 0)
                {
                    var receivedData = new byte[1464];

                    receivedData = (byte[])aResult.AsyncState;

                    var enc      = new UTF8Encoding();
                    var kMessage = new KMessage(enc.GetString(receivedData));
                    //Comparaison chaine de caractère reçu
                    if (kMessage.GetMessageType() == KMessage.Type.Init().ToString())
                    {
                        switch (kMessage.GetMessageContent())
                        {
                        case "789ZCFZTiniwjZTUvjkas79012798":
                            FrmMain.CheckForIllegalCrossThreadCalls = false;
                            _bEtatDestinataire = false;
                            RecipientStatus(_bEtatDestinataire);
                            FrmMain.CheckForIllegalCrossThreadCalls = true;
                            break;

                        case "tuiFZCz56786casdcssdcvuivgboRTSDetre67Rz7463178":
                            if (!_bEtatDestinataire)
                            {
                                FrmMain.CheckForIllegalCrossThreadCalls = false;
                                _bEtatDestinataire = true;
                                RecipientStatus(_bEtatDestinataire);
                                FrmMain.CheckForIllegalCrossThreadCalls = true;
                            }
                            break;

                        default:
                            Console.WriteLine("Default case");
                            break;
                        }
                    }
                    else
                    {
                        FrmMain.CheckForIllegalCrossThreadCalls = false;
                        lbxTchat.Items.Add("Him :      " + kMessage.GetMessageContent());
                        FrmMain.CheckForIllegalCrossThreadCalls = true;
                        if (_bNotificationsEnable)
                        {
                            KNotification.Show(kMessage.GetMessageContent());
                        }
                    }
                }

                var buffer = new byte[1500];
                _sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref _epRemote, new AsyncCallback(MessageReceived), buffer);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
                Application.Exit();
            }
        }
Пример #11
0
 private async Task HandleMessage(IServiceEventHandler handler, KMessage integrationMessage, ILog log,
                                  CancellationToken cancellationToken)
 {
     await handler.Handle(JObject.Parse(integrationMessage.EventData), log, cancellationToken);
 }