List of usage examples for com.rabbitmq.client Channel basicRecover
Basic.RecoverOk basicRecover(boolean requeue) throws IOException;
From source file:org.mule.transport.amqp.AmqpRecover.java
License:Open Source License
public static void recover(final MuleMessage message, final boolean requeue) throws MuleException { final Channel channel = getChannelOrFail(message, CHANNEL_ACTION); try {/*from www. j a va2 s. c om*/ channel.basicRecover(requeue); } catch (final IOException ioe) { throw new DefaultMuleException("Failed to recover channel: " + channel, ioe); } if (LOG.isDebugEnabled()) { LOG.debug("Manually recovered channel: " + channel); } }
From source file:org.mule.transport.amqp.AmqpTransaction.java
License:Open Source License
@Override protected void doRollback() throws TransactionException { if (resource == null) { logger.warn(CoreMessages.rollbackTxButNoResource(this)); return;/*from w ww. jav a2 s. c o m*/ } final Channel channel = getTransactedChannel(); try { channel.txRollback(); } catch (final IOException ioe) { throw new TransactionException(CoreMessages.transactionRollbackFailed(), ioe); } try { channel.txRollback(); switch (recoverStrategy) { case NONE: // NOOP break; case NO_REQUEUE: channel.basicRecover(false); break; case REQUEUE: channel.basicRecover(true); break; } } catch (final IOException ioe) { logger.warn("Failed to recover channel " + channel + " after rollback (recoverStrategy is " + recoverStrategy + ")"); } }
From source file:org.mule.transport.amqp.internal.processor.Recover.java
License:Open Source License
public void recover(final MuleMessage message, final boolean requeue) throws MuleException { final Channel channel = getChannelOrFail(message, CHANNEL_ACTION); try {/*w w w . ja va2 s .c o m*/ channel.basicRecover(requeue); } catch (final Exception e) { throw new DefaultMuleException("Failed to recover channel: " + channel, e); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Manually recovered channel: " + channel); } }
From source file:org.mule.transport.amqp.internal.transaction.AmqpTransaction.java
License:Open Source License
protected void applyRecoverStrategy(final Channel channel) { try {/*from w ww .j a va 2s . co m*/ switch (recoverStrategy) { case NONE: // NOOP break; case NO_REQUEUE: channel.basicRecover(false); break; case REQUEUE: channel.basicRecover(true); break; } if ((recoverStrategy != NONE) && (logger.isDebugEnabled())) { logger.debug("Applied " + recoverStrategy + " recover strategy on channel: " + channel); } } catch (final IOException ioe) { logger.warn("Failed to recover channel " + channel + " after rollback (recoverStrategy is " + recoverStrategy + ")"); } }
From source file:org.springframework.amqp.rabbit.connection.RabbitUtils.java
License:Apache License
public static void closeMessageConsumer(Channel channel, Collection<String> consumerTags, boolean transactional) { if (!channel.isOpen()) { return;/*from www .j a v a 2s . c o m*/ } try { synchronized (consumerTags) { for (String consumerTag : consumerTags) { channel.basicCancel(consumerTag); } } if (transactional) { /* * Re-queue in-flight messages if any (after the consumer is cancelled to prevent the broker from simply * sending them back to us). Does not require a tx.commit. */ channel.basicRecover(true); } /* * If not transactional then we are auto-acking (at least as of 1.0.0.M2) so there is nothing to recover. * Messages are going to be lost in general. */ } catch (Exception ex) { throw RabbitExceptionTranslator.convertRabbitAccessException(ex); } }
From source file:org.springframework.amqp.rabbit.core.RabbitTemplateIntegrationTests.java
License:Apache License
@Test public void testSendAndReceiveTransactedWithImplicitRollback() throws Exception { template.setChannelTransacted(true); template.convertAndSend(ROUTE, "message"); // Rollback of manual receive is implicit because the channel is // closed...//from www. j a v a 2 s .co m try { template.execute(new ChannelCallback<String>() { @Override public String doInRabbit(Channel channel) throws Exception { // Switch off the auto-ack so the message is rolled back... channel.basicGet(ROUTE, false); // This is the way to rollback with a cached channel (it is // the way the ConnectionFactoryUtils // handles it via a synchronization): channel.basicRecover(true); throw new PlannedException(); } }); fail("Expected PlannedException"); } catch (Exception e) { assertTrue(e.getCause() instanceof PlannedException); } String result = (String) template.receiveAndConvert(ROUTE); assertEquals("message", result); result = (String) template.receiveAndConvert(ROUTE); assertEquals(null, result); }
From source file:org.springframework.amqp.rabbit.support.RabbitUtils.java
License:Apache License
public static void closeMessageConsumer(Channel channel, String consumerTag, boolean transactional) { if (!channel.isOpen()) { return;/*from w w w . j a va2s .c o m*/ } try { channel.basicCancel(consumerTag); if (transactional) { /* * Re-queue in-flight messages if any (after the consumer is cancelled to prevent the broker from simply * sending them back to us). Does not require a tx.commit. */ channel.basicRecover(true); } } catch (Exception ex) { throw convertRabbitAccessException(ex); } }