コード例 #1
0
        /// <summary>
        /// The Handle
        /// </summary>
        /// <param name="request">The request<see cref="SendServiceOutPutMessageCommand"/></param>
        /// <param name="cancellationToken">The cancellationToken<see cref="CancellationToken"/></param>
        /// <returns>The <see cref="Task{MessageProcessResponse}"/></returns>
        public async Task <MessageProcessResponse> Handle(SendServiceOutPutMessageCommand request, CancellationToken cancellationToken)
        {
            ICoreKeyVaultClient    keyVault               = app.ApplicationServices.GetRequiredService <ICoreKeyVaultClient>();
            IntegrationEvent       integrationEvent       = null;
            MessageProcessResponse messageProcessResponse = MessageProcessResponse.Abandon;

            try
            {
                request          = request ?? throw new ArgumentNullException(nameof(request));
                integrationEvent = PrepareOutputMessage(request.Items, request.Message);
                if (request.Status)
                {
                    await sendMngr.SendAsync(await keyVault.GetSecret(BusinessValidationConstants.KEYVAULT_BUSINESSVALIDATIONSUCCESSTOPIC), integrationEvent);

                    messageProcessResponse = MessageProcessResponse.Complete;
                }
                else
                {
                    integrationEvent.Body.ServiceOutput = new ServiceOutput();
                    await sendMngr.SendAsync(await keyVault.GetSecret(BusinessValidationConstants.ErrorTopicNameKeyName), integrationEvent);

                    messageProcessResponse = MessageProcessResponse.Complete;
                }
                return(messageProcessResponse);
            }
            catch (Exception ex)
            {
                integrationEvent = GetIntegrationEvent(request?.Message);
                integrationEvent.Body.ServiceOutput = new ServiceOutput();
                await sendMngr.SendAsync(await keyVault.GetSecret(BusinessValidationConstants.KEYVAULT_ERRORTOPICNAME), integrationEvent);

                Log.Error(ex.Message);
                return(MessageProcessResponse.Abandon);
            }
        }
        public async Task RunAsync([QueueTrigger(QueueNames.DistributionQueueName)]
                                   string queueItemContents,
                                   CancellationToken cancellationToken)
        {
            _logger.SetInternalRequestId(Guid.NewGuid());
            _logger.Info($"Starting to process queue item {queueItemContents}");

            var distribution = JsonConvert.DeserializeObject <Distribution>(queueItemContents);

            await _sendManager.SendAsync(distribution, cancellationToken);
        }