Beispiel #1
0
            public Task <Model.Output> Handle(Model.Input request, CancellationToken cancellationToken)
            {
                try
                {
                    var queues = new QueuesPool(_awsSqsSettingsOptions.AccessKey, _awsSqsSettingsOptions.SecretKey, _awsSqsSettingsOptions.Region);
                    var queue  = queues.AddQueue(_awsSqsSettingsOptions.QueueRequestPingUrl);

                    queue.ErrorEvent += ErrorEvent;

                    queue.Receive <PingRequestQueueMessage>(ReceiveMessage);

                    return(Task.FromResult(new Model.Output {
                        Success = true, Message = $"The Queue {_awsSqsSettingsOptions.QueueRequestPingUrl} has been started!"
                    }));
                }
                catch (Exception ex)
                {
                    var errorMessage = $"[MESSAGE_RECEIVED_ERROR] Error on to start receiving messages!!! Message: {ex.Message}";

                    _logger.Error(ex, errorMessage);

                    return(Task.FromResult(new Model.Output {
                        Success = false, Message = errorMessage
                    }));
                }
            }
            private void Send(Object stateInfo)
            {
                try
                {
                    Task.Run(async() =>
                    {
                        try
                        {
                            using (var queues = new QueuesPool(_awsSqsSettings.AccessKey, _awsSqsSettings.SecretKey, _awsSqsSettings.Region))
                            {
                                var queue = queues.AddQueue(_awsSqsSettings.QueueRequestPingUrl);

                                await queue.SendOne(new Message <PingRequestQueueMessage>(new PingRequestQueueMessage
                                {
                                    RequestId = Guid.NewGuid().ToString(),
                                    TimeStamp = DateTimeUtils.UnixTimestamp()
                                }));
                            }
                        }
                        catch (Exception ex)
                        {
                            var errorMessage = $"[SCHEDULE_START_ERROR] Error on to schedule message sending!!! Message: {ex.Message}";

                            _logger.Error(ex, errorMessage);
                        }
                    });
                }
                catch (Exception ex)
                {
                    var errorMessage = $"[SCHEDULE_START_ERROR] Error on to schedule message sending!!! Message: {ex.Message}";

                    _logger.Error(ex, errorMessage);
                }
            }
Beispiel #3
0
            public async Task Handle(Model.Input notification, CancellationToken cancellationToken)
            {
                try
                {
                    using (var queues = new QueuesPool(_awsSqsSettingsOptions.AccessKey, _awsSqsSettingsOptions.SecretKey, _awsSqsSettingsOptions.Region))
                    {
                        var queue = queues.AddQueue(_awsSqsSettingsOptions.QueuePingUrl);

                        await queue.SendOne(new Message <PingQueueMessage>(new PingQueueMessage
                        {
                            ServiceId = $"{ServiceInstanceHandler.Instance(_serviceSettings).GetServiceInstanceId}",
                            MessageId = notification.RequestId,
                            EventUnixTimestamp = DateTimeUtils.UnixTimestamp(),
                            Message = $"{notification.Message}"
                        }));
                    }
                }
                catch (Exception ex)
                {
                    var errorMessage = $"Error in when sending message! Message not sent: {notification.Message} - Error: {ex.Message}";

                    _logger.Error(ex, errorMessage);
                }
            }