Examples of RabbitResourceHolder


Examples of org.springframework.amqp.rabbit.connection.RabbitResourceHolder

    }
  }

  private <T> T doExecute(ChannelCallback<T> action) {
    Assert.notNull(action, "Callback object must not be null");
    RabbitResourceHolder resourceHolder = getTransactionalResourceHolder();
    Channel channel = resourceHolder.getChannel();
    if (this.confirmCallback != null || this.returnCallback != null) {
      addListener(channel);
    }
    try {
      if (logger.isDebugEnabled()) {
        logger.debug("Executing callback on RabbitMQ Channel: "
            + channel);
      }
      return action.doInRabbit(channel);
    } catch (Exception ex) {
      if (isChannelLocallyTransacted(channel)) {
        resourceHolder.rollbackAll();
      }
      throw convertRabbitAccessException(ex);
    } finally {
      ConnectionFactoryUtils.releaseResources(resourceHolder);
    }
View Full Code Here

Examples of org.springframework.amqp.rabbit.connection.RabbitResourceHolder

      doInvokeListener((ChannelAwareMessageListener) listener, channel, message);
    }
    else if (listener instanceof MessageListener) {
      boolean bindChannel = isExposeListenerChannel() && isChannelLocallyTransacted(channel);
      if (bindChannel) {
        RabbitResourceHolder resourceHolder = new RabbitResourceHolder(channel, false);
        resourceHolder.setSynchronizedWithTransaction(true);
        TransactionSynchronizationManager.bindResource(this.getConnectionFactory(),
            resourceHolder);
      }
      try {
        doInvokeListener((MessageListener) listener, message);
View Full Code Here

Examples of org.springframework.amqp.rabbit.connection.RabbitResourceHolder

   * @see #setExposeListenerChannel(boolean)
   */
  protected void doInvokeListener(ChannelAwareMessageListener listener, Channel channel, Message message)
      throws Exception {

    RabbitResourceHolder resourceHolder = null;
    Channel channelToUse = channel;
    boolean boundHere = false;
    try {
      if (!isExposeListenerChannel()) {
        // We need to expose a separate Channel.
        resourceHolder = getTransactionalResourceHolder();
        channelToUse = resourceHolder.getChannel();
        /*
         * If there is a real transaction, the resource will have been bound; otherwise
         * we need to bind it temporarily here. Any work done on this channel
         * will be committed in the finally block.
         */
        if (isChannelLocallyTransacted(channelToUse) &&
              !TransactionSynchronizationManager.isActualTransactionActive()) {
            resourceHolder.setSynchronizedWithTransaction(true);
            TransactionSynchronizationManager.bindResource(this.getConnectionFactory(),
                resourceHolder);
          boundHere = true;
        }
      }
      else {
        // if locally transacted, bind the current channel to make it available to RabbitTemplate
        if (isChannelLocallyTransacted(channel)) {
          RabbitResourceHolder localResourceHolder = new RabbitResourceHolder(channelToUse, false);
          localResourceHolder.setSynchronizedWithTransaction(true);
          TransactionSynchronizationManager.bindResource(this.getConnectionFactory(),
              localResourceHolder);
          boundHere = true;
        }
      }
View Full Code Here

Examples of org.springframework.amqp.rabbit.connection.RabbitResourceHolder

  }


  private <T> T doExecute(ChannelCallback<T> action, ConnectionFactory connectionFactory) {
    Assert.notNull(action, "Callback object must not be null");
    RabbitResourceHolder resourceHolder = ConnectionFactoryUtils.getTransactionalResourceHolder(
        (connectionFactory != null ? connectionFactory : getConnectionFactory()), isChannelTransacted());
    Channel channel = resourceHolder.getChannel();
    if (this.confirmCallback != null || this.returnCallback != null) {
      addListener(channel);
    }
    try {
      if (logger.isDebugEnabled()) {
        logger.debug("Executing callback on RabbitMQ Channel: " + channel);
      }
      return action.doInRabbit(channel);
    }
    catch (Exception ex) {
      if (isChannelLocallyTransacted(channel)) {
        resourceHolder.rollbackAll();
      }
      throw convertRabbitAccessException(ex);
    }
    finally {
      ConnectionFactoryUtils.releaseResources(resourceHolder);
View Full Code Here

Examples of org.springframework.amqp.rabbit.connection.RabbitResourceHolder

        return new TransactionTemplate(transactionManager, transactionAttribute)
            .execute(new TransactionCallback<Boolean>() {
              @Override
              public Boolean doInTransaction(TransactionStatus status) {
                ConnectionFactoryUtils.bindResourceToTransaction(
                    new RabbitResourceHolder(consumer.getChannel(), false),
                    getConnectionFactory(), true);
                try {
                  return doReceiveAndExecute(consumer);
                } catch (RuntimeException e) {
                  throw e;
View Full Code Here

Examples of org.springframework.amqp.rabbit.connection.RabbitResourceHolder

  protected void doBegin(Object transaction, TransactionDefinition definition) {
    if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
      throw new InvalidIsolationLevelException("AMQP does not support an isolation level concept");
    }
    RabbitTransactionObject txObject = (RabbitTransactionObject) transaction;
    RabbitResourceHolder resourceHolder = null;
    try {
      resourceHolder = ConnectionFactoryUtils.getTransactionalResourceHolder(getConnectionFactory(), true);
      if (logger.isDebugEnabled()) {
        logger.debug("Created AMQP transaction on channel [" + resourceHolder.getChannel() + "]");
      }
      // resourceHolder.declareTransactional();
      txObject.setResourceHolder(resourceHolder);
      txObject.getResourceHolder().setSynchronizedWithTransaction(true);
      int timeout = determineTimeout(definition);
View Full Code Here

Examples of org.springframework.amqp.rabbit.connection.RabbitResourceHolder

    return TransactionSynchronizationManager.unbindResource(getConnectionFactory());
  }

  @Override
  protected void doResume(Object transaction, Object suspendedResources) {
    RabbitResourceHolder conHolder = (RabbitResourceHolder) suspendedResources;
    TransactionSynchronizationManager.bindResource(getConnectionFactory(), conHolder);
  }
View Full Code Here

Examples of org.springframework.amqp.rabbit.connection.RabbitResourceHolder

  }

  @Override
  protected void doCommit(DefaultTransactionStatus status) {
    RabbitTransactionObject txObject = (RabbitTransactionObject) status.getTransaction();
    RabbitResourceHolder resourceHolder = txObject.getResourceHolder();
    resourceHolder.commitAll();
  }
View Full Code Here

Examples of org.springframework.amqp.rabbit.connection.RabbitResourceHolder

  }

  @Override
  protected void doRollback(DefaultTransactionStatus status) {
    RabbitTransactionObject txObject = (RabbitTransactionObject) status.getTransaction();
    RabbitResourceHolder resourceHolder = txObject.getResourceHolder();
    resourceHolder.rollbackAll();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.