Mix Publisher подтверждает и не подтверждает через транзакцию - PullRequest
0 голосов
/ 30 апреля 2018

Я пытался использовать транзакцию, охватывающую как Подтверждение издателя, так и неподтверждение для производителей, как в приведенном ниже коде, но я получил ошибку ниже:

 RabbitMQ.Client.Exceptions.OperationInterruptedException
      HResult=0x80131500
      Message=The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=406, text="PRECONDITION_FAILED - cannot switch from confirm to tx mode", classId=90, methodId=10, cause=
      Source=RabbitMQ.Client
      StackTrace:
       at RabbitMQ.Client.Impl.SimpleBlockingRpcContinuation.GetReply(TimeSpan timeout)
       at RabbitMQ.Client.Impl.ModelBase.ModelRpc(MethodBase method, ContentHeaderBase header, Byte[] body)
       at RabbitMQ.Client.Framing.Impl.Model.TxSelect()



 public class ProducerConfirmsTx
    {
        public void Run()
        {
            Produce();
        }
        public void Produce()
        {
            var factory = new ConnectionFactory() {
                HostName = _appSetting.MessagingServerSetting.ServerName,
                UserName = _appSetting.MessagingServerSetting.UserName,
                Password = _appSetting.MessagingServerSetting.Password,               
            };
            using (var connection = factory.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare(
                    queue: QUEUE_NAME,
                    durable: true,
                    exclusive: false,
                    autoDelete: false,
                    arguments: null);         

                //3
                channel.BasicAcks += Channel_BasicAcks; 

                //1
                channel.ConfirmSelect(); 

                var properties = channel.CreateBasicProperties();
                properties.Persistent = true;

                    channel.TxSelect();  //tx starts

                    channel.BasicPublish(
                    exchange: "",
                    routingKey: QUEUE_NAME,
                    basicProperties: properties,
                    body: ConvertMessageToByte(message));

                    //2
                    channel.WaitForConfirmsOrDie();  //blocked and wait


                    //other works that need tx here

                    channel.TxCommit();   //tx ends
                    //channel.TxRollback();            
            }

        }

        private void Channel_BasicAcks(object sender, RabbitMQ.Client.Events.BasicAckEventArgs e)
        {
            DisplayResponseInfo(e.DeliveryTag);            
        }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...