/// <summary>Receive and execute.</summary> /// <param name="consumer">The consumer.</param> /// <returns>True if a message was received.</returns> internal bool ReceiveAndExecute(BlockingQueueConsumer consumer) { if (this.transactionManager != null) { try { var transactionTemplate = new TransactionTemplate(this.transactionManager); transactionTemplate.PropagationBehavior = this.transactionAttribute.PropagationBehavior; transactionTemplate.TransactionIsolationLevel = IsolationLevel.Unspecified; // TODO: revert to transactionAttribute once we take dependency on SPRNET 2.0 transactionTemplate.TransactionTimeout = this.transactionAttribute.TransactionTimeout; transactionTemplate.ReadOnly = this.transactionAttribute.ReadOnly; transactionTemplate.Name = this.transactionAttribute.Name; return((bool)transactionTemplate.Execute( status => { ConnectionFactoryUtils.BindResourceToTransaction(new RabbitResourceHolder(consumer.Channel, false), this.ConnectionFactory, true); return this.DoReceiveAndExecute(consumer); })); } catch (Exception ex) { Logger.Error(m => m("Error receiving and executing."), ex); throw; } } return(this.DoReceiveAndExecute(consumer)); }
public void TestReceiveBlockingGlobalTx() { template.ConvertAndSend(ROUTE, "blockGTXNoTO"); var resourceHolder = ConnectionFactoryUtils .GetTransactionalResourceHolder(template.ConnectionFactory, true); TransactionSynchronizationManager.SetActualTransactionActive(true); ConnectionFactoryUtils.BindResourceToTransaction(resourceHolder, template.ConnectionFactory, true); template.ReceiveTimeout = -1; template.IsChannelTransacted = true; var o = template.ReceiveAndConvert <string>(ROUTE); resourceHolder.CommitAll(); resourceHolder.CloseAll(); Assert.Same(resourceHolder, TransactionSynchronizationManager.UnbindResource(template.ConnectionFactory)); Assert.NotNull(o); Assert.Equal("blockGTXNoTO", o); template.ReceiveTimeout = 0; Assert.Null(template.Receive(ROUTE)); }
private void ExecuteListenerInTransaction(Message message, ulong deliveryTag) { if (IsRabbitTxManager) { ConsumerChannelRegistry.RegisterConsumerChannel(Model, ConnectionFactory); } if (TransactionTemplate == null) { TransactionTemplate = new TransactionTemplate(TransactionManager, TransactionAttribute); } TransactionTemplate.Execute <object>(s => { var resourceHolder = ConnectionFactoryUtils.BindResourceToTransaction(new RabbitResourceHolder(Model, false), ConnectionFactory, true); if (resourceHolder != null) { resourceHolder.AddDeliveryTag(Model, deliveryTag); } // unbound in ResourceHolderSynchronization.beforeCompletion() try { CallExecuteListener(message, deliveryTag); } catch (Exception e1) { _container.PrepareHolderForRollback(resourceHolder, e1); throw; } // catch (Throwable e2) // { // //NOSONAR ok to catch Throwable here because we re-throw it below // throw new WrappedTransactionException(e2); // } return(null); }); }