Exemple #1
0
        private async Task <XXXDeliveryResult> InternalProduceAsync(ProducerMessageContext context)
        {
            XXXDeliveryResult result = null;

            try
            {
                var result2 = await this.EnsureProducer().ProduceAsync(context.Topic, CreateMessage(context)).ConfigureAwait(false);

                result = Util.XXXDeliveryResult(result2);
            }
            catch (ProduceException <byte[], byte[]> e)
            {
                if (e.Error.IsFatal)
                {
                    this.InvalidateProducer(e.Error, result);
                }

                throw;
            }

            context.Offset    = result.Offset;
            context.Partition = result.Partition;

            return(result);
        }
Exemple #2
0
        public async Task <XXXDeliveryResult> ProduceAsync(
            string topic,
            string partitionKey,
            object message,
            IMessageHeaders headers = null)
        {
            var messageKey = partitionKey is null ? null : Encoding.UTF8.GetBytes(partitionKey);

            XXXDeliveryResult report = null;

            await this.middlewareExecutor.Execute(new ProducerMessageContext(message, messageKey, headers, topic),
                                                  async context =>
            {
                report = await this.InternalProduceAsync((ProducerMessageContext)context).ConfigureAwait(false);
            }).ConfigureAwait(false);

            return(report);
        }
Exemple #3
0
        private void InvalidateProducer(Error error, XXXDeliveryResult result)
        {
            lock (this.producerCreationSync)
            {
                this.producer = null;
            }
            XXXError xerror = new XXXError();

            xerror.Reason        = error.Reason;
            xerror.IsLocalError  = error.IsLocalError;
            xerror.IsBrokerError = error.IsBrokerError;
            xerror.IsError       = error.IsError;
            xerror.IsFatal       = error.IsFatal;

            this.dependencyResolverScope.Resolver.Resolve <ILogHandler>()
            .Error("Kafka produce fatal error occurred. The producer will be recreated",
                   result is null ? new XXXProduceException(xerror) : new XXXProduceException(xerror, result),
                   new { Error = error });
        }