Beispiel #1
0
        public async Task EmployeeUpdatesQueue(
            [QueueTrigger(AppResources.Queue.EmployeeUpdates)] CloudQueueMessage queueMessage,
            ILogger log)
        {
            log.LogInformation($"Processing {AppResources.Queue.EmployeeUpdates} queue: [{queueMessage}]");

            string eventName = QueueMessageHandler.GetEventName(queueMessage);

            switch (eventName)
            {
            case nameof(EmployeeCreation):
                await HandleEmployeeCreation(queueMessage, log);

                return;

            case nameof(EmployeeUpdate):
                await HandleEmployeeUpdate(queueMessage, log);

                return;

            default:
                log.LogWarning("Queue message with {eventName} cannot be handled", eventName);

                return;
            }
        }
        /// <summary>
        /// Dequeue a message
        /// </summary>
        /// <param name="queueConfiguration">(sic)</param>
        /// <param name="handler">QueueMessageHandler</param>
        public void SetupDequeueEvent(Models.RabbitMqInstanceConfiguration queueConfiguration, QueueMessageHandler handler)
        {
            var factory = RabbitMqUtility.RabbitMQMakeConnectionFactory(this._engineConfiguration.Host, this._engineConfiguration.Port, this._engineConfiguration.Username, this._engineConfiguration.Password);

            using (var connection = factory.CreateConnection())
            {
                using (var model = connection.CreateModel())
                {
                    RabbitMqUtility.SetupDurableQueue(model, this._engineConfiguration, queueConfiguration);

                    var consumer = new EventingBasicConsumer(model);

                    consumer.Received += (_, ea) =>
                    {
                        handler(this, this._logger, model, ea);
                    };

                    model.BasicConsume(queue: queueConfiguration.QueueName,
                                       autoAck: false,
                                       consumer: consumer);

                    while (this.KeepListening)
                    {
                    }
                }
            }
        }