/// <summary>
        /// 事务版本   貌似没必要 要求 配置TransactionalId,Acks必须等于all
        /// </summary>
        /// <param name="topic"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task <DeliveryResult <TKey, TValue> > ProduceAsync2(string topic, Message <TKey, TValue> message)
        {
            DeliveryResult <TKey, TValue> result = null;

            try
            {
                _producer.InitTransactions(DefaultTimeout);
                _producer.BeginTransaction();
                result = await this._producer.ProduceAsync(topic, message);

                _producer.CommitTransaction(DefaultTimeout);
            }
            catch (Exception)
            {
                _producer.AbortTransaction(DefaultTimeout);
                throw;
            }
            return(result);
        }
Exemplo n.º 2
0
        public override void Suspend()
        {
            log.Debug($"{logPrefix}Suspending");

            try
            {
                Commit(false);
            }
            finally
            {
                if (eosEnabled)
                {
                    if (transactionInFlight)
                    {
                        producer.AbortTransaction(configuration.TransactionTimeout);
                    }

                    collector.Close();
                    producer = null;
                }
            }
        }
Exemplo n.º 3
0
        public override void Suspend()
        {
            log.LogDebug($"{logPrefix}Suspending");

            if (state == TaskState.CREATED || state == TaskState.RESTORING)
            {
                log.LogInformation($"{logPrefix}Suspended {(state == TaskState.CREATED ? "created" : "restoring")}");

                // TODO : remove when stream task refactoring is finished
                if (eosEnabled)
                {
                    if (transactionInFlight)
                    {
                        producer.AbortTransaction(configuration.TransactionTimeout);
                    }

                    collector.Close();
                    producer = null;
                }

                FlushState();
                CloseStateManager();

                TransitTo(TaskState.SUSPENDED);
            }
            else if (state == TaskState.RUNNING)
            {
                try
                {
                    Commit(false);
                }
                finally
                {
                    partitionGrouper.Clear();

                    if (eosEnabled)
                    {
                        if (transactionInFlight)
                        {
                            producer.AbortTransaction(configuration.TransactionTimeout);
                        }

                        collector.Close();
                        producer = null;
                    }

                    FlushState();
                    CloseStateManager();
                }

                log.LogInformation($"{logPrefix}Suspended running");
                TransitTo(TaskState.SUSPENDED);
            }
            else if (state == TaskState.SUSPENDED)
            {
                log.LogInformation($"{logPrefix}Skip suspended since state is {state}");
                return;
            }
            else if (state == TaskState.CLOSED)
            {
                throw new IllegalStateException($"Illegal state {state} while suspending active task {Id}");
            }
            else
            {
                throw new IllegalStateException($"Unknow state {state} while suspending active task {Id}");
            }
        }
 public void AbortTransaction(TimeSpan timeout)
 {
     _producer.AbortTransaction(timeout);
 }