Codota Logo
ConnectionFactoryUtils
Code IndexAdd Codota to your IDE (free)

How to use
ConnectionFactoryUtils
in
org.springframework.amqp.rabbit.connection

Best Java code snippets using org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Charset c =
  • Codota IconString charsetName;Charset.forName(charsetName)
  • Codota IconCharset.defaultCharset()
  • Codota IconContentType contentType;contentType.getCharset()
  • Smart code suggestions by Codota
}
origin: org.springframework.amqp/spring-rabbit

/**
 * Obtain a RabbitMQ Channel that is synchronized with the current transaction, if any.
 * @param connectionFactory the ConnectionFactory to obtain a Channel for
 * @param synchedLocalTransactionAllowed whether to allow for a local RabbitMQ transaction that is synchronized with
 * a Spring-managed transaction (where the main transaction might be a JDBC-based one for a specific DataSource, for
 * example), with the RabbitMQ transaction committing right after the main transaction. If not allowed, the given
 * ConnectionFactory needs to handle transaction enlistment underneath the covers.
 * @return the transactional Channel, or <code>null</code> if none found
 */
public static RabbitResourceHolder getTransactionalResourceHolder(final ConnectionFactory connectionFactory,
    final boolean synchedLocalTransactionAllowed) {
  return getTransactionalResourceHolder(connectionFactory, synchedLocalTransactionAllowed, false);
}
origin: spring-projects/spring-amqp

@Override
public Connection createConnection() throws IOException {
  return ConnectionFactoryUtils.createConnection(this.connectionFactory,
      this.publisherConnectionIfPossible);
}
origin: spring-projects/spring-amqp

/**
 * Obtain a RabbitMQ Channel that is synchronized with the current transaction, if any.
 * @param connectionFactory the ConnectionFactory to obtain a Channel for
 * @param synchedLocalTransactionAllowed whether to allow for a local RabbitMQ transaction that is synchronized with
 * a Spring-managed transaction (where the main transaction might be a JDBC-based one for a specific DataSource, for
 * example), with the RabbitMQ transaction committing right after the main transaction. If not allowed, the given
 * ConnectionFactory needs to handle transaction enlistment underneath the covers.
 * @param publisherConnectionIfPossible obtain a connection from a separate publisher connection
 * if possible.
 * @return the transactional Channel, or <code>null</code> if none found
 */
public static RabbitResourceHolder getTransactionalResourceHolder(final ConnectionFactory connectionFactory,
    final boolean synchedLocalTransactionAllowed, final boolean publisherConnectionIfPossible) {
  return doGetTransactionalResourceHolder(connectionFactory, new RabbitResourceFactory(connectionFactory,
      synchedLocalTransactionAllowed, publisherConnectionIfPossible));
}
origin: org.springframework.amqp/spring-rabbit

resourceHolder = ConnectionFactoryUtils.getTransactionalResourceHolder(getConnectionFactory(), true);
channel = resourceHolder.getChannel();
if (channel == null) {
  ConnectionFactoryUtils.releaseResources(resourceHolder);
  throw new IllegalStateException("Resource holder returned a null channel");
origin: org.springframework.amqp/spring-rabbit

if (isChannelTransacted()) {
  resourceHolder = ConnectionFactoryUtils.
    getTransactionalResourceHolder(connectionFactory, true, this.usePublisherConnection);
  channel = resourceHolder.getChannel();
  if (channel == null) {
    ConnectionFactoryUtils.releaseResources(resourceHolder);
    throw new IllegalStateException("Resource holder returned a null channel");
  connection = ConnectionFactoryUtils.createConnection(connectionFactory,
      this.usePublisherConnection); // NOSONAR - RabbitUtils closes
  if (connection == null) {
origin: spring-projects/spring-amqp

@Test
public void testReceiveBlockingGlobalTx() throws Exception {
  template.convertAndSend(ROUTE, "blockGTXNoTO");
  RabbitResourceHolder resourceHolder = ConnectionFactoryUtils
      .getTransactionalResourceHolder(this.template.getConnectionFactory(), true);
  TransactionSynchronizationManager.setActualTransactionActive(true);
  ConnectionFactoryUtils.bindResourceToTransaction(resourceHolder, this.template.getConnectionFactory(), true);
  template.setReceiveTimeout(-1);
  template.setChannelTransacted(true);
  String out = (String) template.receiveAndConvert(ROUTE);
  resourceHolder.commitAll();
  resourceHolder.closeAll();
  assertSame(resourceHolder, TransactionSynchronizationManager.unbindResource(template.getConnectionFactory()));
  assertNotNull(out);
  assertEquals("blockGTXNoTO", out);
  this.template.setReceiveTimeout(0);
  assertNull(this.template.receive(ROUTE));
}
origin: spring-projects/spring-amqp

@Test
public void testResourceHolder() {
  RabbitResourceHolder h1 = new RabbitResourceHolder();
  RabbitResourceHolder h2 = new RabbitResourceHolder();
  ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
  TransactionSynchronizationManager.setActualTransactionActive(true);
  ConnectionFactoryUtils.bindResourceToTransaction(h1, connectionFactory, true);
  assertSame(h1, ConnectionFactoryUtils.bindResourceToTransaction(h2, connectionFactory, true));
  TransactionSynchronizationManager.clear();
}
origin: spring-projects/spring-amqp

@Override
protected void releaseResource(RabbitResourceHolder resourceHolder, Object resourceKey) {
  ConnectionFactoryUtils.releaseResources(resourceHolder);
}
origin: spring-projects/spring-amqp

ConnectionFactoryUtils.registerDeliveryTag(this.connectionFactory, this.channel,
    delivery.getEnvelope().getDeliveryTag());
origin: spring-projects/spring-amqp

/**
 * Check whether the given Channel is locally transacted, that is, whether its transaction is managed by this
 * template's Channel handling and not by an external transaction coordinator.
 * @param channel the Channel to check
 * @return whether the given Channel is locally transacted
 * @see ConnectionFactoryUtils#isChannelTransactional
 * @see #isChannelTransacted
 */
protected boolean isChannelLocallyTransacted(Channel channel) {
  return isChannelTransacted() && !ConnectionFactoryUtils.isChannelTransactional(channel, getConnectionFactory());
}
origin: spring-projects/spring-amqp

resourceHolder = ConnectionFactoryUtils.getTransactionalResourceHolder(getConnectionFactory(), true);
channel = resourceHolder.getChannel();
if (channel == null) {
  ConnectionFactoryUtils.releaseResources(resourceHolder);
  throw new IllegalStateException("Resource holder returned a null channel");
origin: spring-projects/spring-amqp

if (isChannelTransacted()) {
  resourceHolder = ConnectionFactoryUtils.
    getTransactionalResourceHolder(connectionFactory, true, this.usePublisherConnection);
  channel = resourceHolder.getChannel();
  if (channel == null) {
    ConnectionFactoryUtils.releaseResources(resourceHolder);
    throw new IllegalStateException("Resource holder returned a null channel");
  connection = ConnectionFactoryUtils.createConnection(connectionFactory,
      this.usePublisherConnection); // NOSONAR - RabbitUtils closes
  if (connection == null) {
origin: spring-projects/spring-amqp

private void executeListenerInTransaction(Message message, long deliveryTag) {
  if (this.isRabbitTxManager) {
    ConsumerChannelRegistry.registerConsumerChannel(getChannel(), this.connectionFactory);
  }
  if (this.transactionTemplate == null) {
    this.transactionTemplate =
        new TransactionTemplate(this.transactionManager, this.transactionAttribute);
  }
  this.transactionTemplate.execute(s -> {
    RabbitResourceHolder resourceHolder = ConnectionFactoryUtils.bindResourceToTransaction(
        new RabbitResourceHolder(getChannel(), false), this.connectionFactory, true);
    if (resourceHolder != null) {
      resourceHolder.addDeliveryTag(getChannel(), deliveryTag);
    }
    // unbound in ResourceHolderSynchronization.beforeCompletion()
    try {
      callExecuteListener(message, deliveryTag);
    }
    catch (RuntimeException e1) {
      prepareHolderForRollback(resourceHolder, e1);
      throw e1;
    }
    catch (Throwable e2) { //NOSONAR ok to catch Throwable here because we re-throw it below
      throw new WrappedTransactionException(e2);
    }
    return null;
  });
}
origin: org.springframework.amqp/spring-rabbit

@Override
protected void releaseResource(RabbitResourceHolder resourceHolder, Object resourceKey) {
  ConnectionFactoryUtils.releaseResources(resourceHolder);
}
origin: org.springframework.amqp/spring-rabbit

ConnectionFactoryUtils.registerDeliveryTag(this.connectionFactory, this.channel,
    delivery.getEnvelope().getDeliveryTag());
origin: org.springframework.amqp/spring-rabbit

/**
 * Check whether the given Channel is locally transacted, that is, whether its transaction is managed by this
 * template's Channel handling and not by an external transaction coordinator.
 * @param channel the Channel to check
 * @return whether the given Channel is locally transacted
 * @see ConnectionFactoryUtils#isChannelTransactional
 * @see #isChannelTransacted
 */
protected boolean isChannelLocallyTransacted(Channel channel) {
  return isChannelTransacted() && !ConnectionFactoryUtils.isChannelTransactional(channel, getConnectionFactory());
}
origin: spring-projects/spring-amqp

@Override
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);
    if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
      txObject.getResourceHolder().setTimeoutInSeconds(timeout);
    }
    TransactionSynchronizationManager.bindResource(getConnectionFactory(), txObject.getResourceHolder());
  }
  catch (AmqpException ex) {
    if (resourceHolder != null) {
      ConnectionFactoryUtils.releaseResources(resourceHolder);
    }
    throw new CannotCreateTransactionException("Could not create AMQP transaction", ex);
  }
}
origin: org.springframework.amqp/spring-rabbit

private void executeListenerInTransaction(Message message, long deliveryTag) {
  if (this.isRabbitTxManager) {
    ConsumerChannelRegistry.registerConsumerChannel(getChannel(), this.connectionFactory);
  }
  if (this.transactionTemplate == null) {
    this.transactionTemplate =
        new TransactionTemplate(this.transactionManager, this.transactionAttribute);
  }
  this.transactionTemplate.execute(s -> {
    RabbitResourceHolder resourceHolder = ConnectionFactoryUtils.bindResourceToTransaction(
        new RabbitResourceHolder(getChannel(), false), this.connectionFactory, true);
    if (resourceHolder != null) {
      resourceHolder.addDeliveryTag(getChannel(), deliveryTag);
    }
    // unbound in ResourceHolderSynchronization.beforeCompletion()
    try {
      callExecuteListener(message, deliveryTag);
    }
    catch (RuntimeException e1) {
      prepareHolderForRollback(resourceHolder, e1);
      throw e1;
    }
    catch (Throwable e2) { //NOSONAR ok to catch Throwable here because we re-throw it below
      throw new WrappedTransactionException(e2);
    }
    return null;
  });
}
origin: spring-projects/spring-amqp

/**
 * Obtain a RabbitMQ Channel that is synchronized with the current transaction, if any.
 * @param connectionFactory the ConnectionFactory to obtain a Channel for
 * @param synchedLocalTransactionAllowed whether to allow for a local RabbitMQ transaction that is synchronized with
 * a Spring-managed transaction (where the main transaction might be a JDBC-based one for a specific DataSource, for
 * example), with the RabbitMQ transaction committing right after the main transaction. If not allowed, the given
 * ConnectionFactory needs to handle transaction enlistment underneath the covers.
 * @return the transactional Channel, or <code>null</code> if none found
 */
public static RabbitResourceHolder getTransactionalResourceHolder(final ConnectionFactory connectionFactory,
    final boolean synchedLocalTransactionAllowed) {
  return getTransactionalResourceHolder(connectionFactory, synchedLocalTransactionAllowed, false);
}
origin: org.springframework.amqp/spring-rabbit

private void cleanUpAfterAction(Channel channel, boolean invokeScope, RabbitResourceHolder resourceHolder,
    Connection connection) {
  if (!invokeScope) {
    if (resourceHolder != null) {
      ConnectionFactoryUtils.releaseResources(resourceHolder);
    }
    else {
      RabbitUtils.closeChannel(channel);
      RabbitUtils.closeConnection(connection);
    }
  }
}
org.springframework.amqp.rabbit.connectionConnectionFactoryUtils

Javadoc

Helper class for managing a Spring based Rabbit org.springframework.amqp.rabbit.connection.ConnectionFactory, in particular for obtaining transactional Rabbit resources for a given ConnectionFactory.

Mainly for internal use within the framework. Used by org.springframework.amqp.rabbit.core.RabbitTemplate as well as org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.

Most used methods

  • bindResourceToTransaction
  • getTransactionalResourceHolder
    Obtain a RabbitMQ Channel that is synchronized with the current transaction, if any.
  • createConnection
    Create a connection with this connection factory and/or its publisher factory.
  • doGetTransactionalResourceHolder
    Obtain a RabbitMQ Channel that is synchronized with the current transaction, if any.
  • isChannelTransactional
    Determine whether the given RabbitMQ Channel is transactional, that is, bound to the current thread
  • registerDeliveryTag
  • releaseResources

Popular in Java

  • Updating database using SQL prepared statement
  • onCreateOptionsMenu (Activity)
  • scheduleAtFixedRate (ScheduledExecutorService)
    Creates and executes a periodic action that becomes enabled first after the given initial delay, and
  • getResourceAsStream (ClassLoader)
    Returns a stream for the resource with the specified name. See #getResource(String) for a descriptio
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • BigInteger (java.math)
    Immutable arbitrary-precision integers. All operations behave as if BigIntegers were represented in
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • JLabel (javax.swing)
  • JTable (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now