Ejemplo n.º 1
0
        public async Task HandleReceivedMessage(string message, int retryCount, ulong deliveryTag, string requestKey, Func <string, int, ulong, string, Task <bool> > func)
        {
            var success = await func.Invoke(message, retryCount, deliveryTag, requestKey);

            try
            {
                if (success)
                {
                    if (this.QueueProcessorSettings.AutoAckOnSuccess)
                    {
                        this.HandleSuccededEvent(deliveryTag);
                    }
                }
                else
                {
                    this.HandleFailedEvent(message, retryCount, deliveryTag, requestKey);
                }
            }
            catch (Exception)
            {
                lock (this.LockAckError)
                {
                    StaticSimpleLogger.Error(nameof(QueueProcessor), nameof(HandleReceivedMessage), $"Error on handle received message {deliveryTag}", null, requestKey);
                    this.QueueClient.TryConnect();
                }
            }
        }
Ejemplo n.º 2
0
        public bool ExecuteConsumer(Func <string, int, ulong, string, Task <bool> > func)
        {
            try
            {
                this.QueueClient.TryConnect();

                this.QueueClient.ReceiveMessage += (message, retryCount, deliveryTag, requestKey) =>
                {
                    lock (this.LockThreads)
                    {
                        do
                        {
                            this.Threads.Where(t => t.IsCompleted).ToList()
                            .ForEach(task => task.Dispose());
                            this.Threads.RemoveAll(t => t.IsCompleted);
                        }while (this.CanAddThread() == false);
                    }

                    this.Threads.Add(HandleReceivedMessage(message, retryCount, deliveryTag, requestKey, func));

                    return(Task.CompletedTask);
                };

                StaticSimpleLogger.Info(nameof(QueueProcessor), nameof(ExecuteConsumer), "Queue connected!");

                return(true);
            }
            catch (Exception e)
            {
                StaticSimpleLogger.Error(nameof(QueueProcessor), nameof(ExecuteConsumer), "An exception occurred while trying to connect with queue!", e);
                Thread.Sleep(2000);
                return(false);
            }
        }
Ejemplo n.º 3
0
 public void Start()
 {
     Task.Delay(1000).ContinueWith((state) =>
     {
         this.CurrentThread.Start();
         StaticSimpleLogger.Info("WorkerRunner", nameof(Start), "Worker started!");
     });
 }
        public IActionResult Post([FromBody] CustomerRequest3 request)
        {
            LogAdditionalInfo.Data.Add("CustomerId", request.CustomerId);

            StaticSimpleLogger.Info("teste teste teste", "requestKey", new { request });

            return(Ok(new
            {
                request,
                test = "1",
                test_1 = "123",
                customer = new Customer("xx", "yy")
            }));
        }
Ejemplo n.º 5
0
 public void Stop()
 {
     StaticSimpleLogger.Info("WorkerRunner", nameof(Stop), "Worker stopped!");
     Thread.Sleep(2000);
     this.CurrentThread.Abort();
 }