@Override protected void acknowledgeSessionIDs(List<Long> sessionIds) { try { for (long id : sessionIds) { channel.basicAck(id, false); } channel.txCommit(); } catch (IOException e) { throw new RuntimeException("Messages could not be acknowledged during checkpoint creation.", e); } }
@Override public CommitOk txCommit() throws IOException { return this.delegate.txCommit(); }
@Override public CommitOk txCommit() throws IOException { return this.delegate.txCommit(); }
this.ackInfo.getChannel().txCommit();
static void commitTransaction(Channel channel) throws IOException { try { LOGGER.info("Committing transaction"); channel.txCommit(); LOGGER.info("Transaction committed"); } catch (IOException e) { LOGGER.error("Failed to commit transaction", e); throw e; } }
/** * Commit the Channel if not within a JTA transaction. * @param channel the RabbitMQ Channel to commit */ public static void commitIfNecessary(Channel channel) { Assert.notNull(channel, "Channel must not be null"); try { channel.txCommit(); } catch (IOException ex) { throw new AmqpIOException(ex); } }
/** * Commit the Channel if not within a JTA transaction. * @param channel the RabbitMQ Channel to commit */ public static void commitIfNecessary(Channel channel) { Assert.notNull(channel, "Channel must not be null"); try { channel.txCommit(); } catch (IOException ex) { throw new AmqpIOException(ex); } }
public static void produceWithTX(String exchangeName, Channel channel, String routingKey, byte[] data, AMQP.BasicProperties properties ) throws IOException { //transaction begin channel.txSelect(); channel.basicPublish(exchangeName, routingKey, properties, data); //commit every message with wrapped a transaction //NOTE: it is almost for security! Not for normal, because of bad performance!!! channel.txCommit(); }
@SuppressWarnings(UNCHECKED) private <R, S> boolean sendReply(final ReceiveAndReplyCallback<R, S> callback, final ReplyToAddressCallback<S> replyToAddressCallback, Channel channel, Message receiveMessage) throws Exception { // NOSONAR TODO change to IOException in 2.2. Object receive = receiveMessage; if (!(ReceiveAndReplyMessageCallback.class.isAssignableFrom(callback.getClass()))) { receive = getRequiredMessageConverter().fromMessage(receiveMessage); } S reply; try { reply = callback.handle((R) receive); } catch (ClassCastException e) { StackTraceElement[] trace = e.getStackTrace(); if (trace[0].getMethodName().equals("handle") && trace[1].getFileName().equals("RabbitTemplate.java")) { throw new IllegalArgumentException("ReceiveAndReplyCallback '" + callback + "' can't handle received object '" + receive + "'", e); } else { throw e; } } if (reply != null) { doSendReply(replyToAddressCallback, channel, receiveMessage, reply); } else if (isChannelLocallyTransacted(channel)) { channel.txCommit(); } return true; }
@SuppressWarnings(UNCHECKED) private <R, S> boolean sendReply(final ReceiveAndReplyCallback<R, S> callback, final ReplyToAddressCallback<S> replyToAddressCallback, Channel channel, Message receiveMessage) throws Exception { // NOSONAR TODO change to IOException in 2.2. Object receive = receiveMessage; if (!(ReceiveAndReplyMessageCallback.class.isAssignableFrom(callback.getClass()))) { receive = getRequiredMessageConverter().fromMessage(receiveMessage); } S reply; try { reply = callback.handle((R) receive); } catch (ClassCastException e) { StackTraceElement[] trace = e.getStackTrace(); if (trace[0].getMethodName().equals("handle") && trace[1].getFileName().equals("RabbitTemplate.java")) { throw new IllegalArgumentException("ReceiveAndReplyCallback '" + callback + "' can't handle received object '" + receive + "'", e); } else { throw e; } } if (reply != null) { doSendReply(replyToAddressCallback, channel, receiveMessage, reply); } else if (isChannelLocallyTransacted(channel)) { channel.txCommit(); } return true; }
/** * {@inheritDoc} */ @Override public void commit() throws JMSException { logger.trace("commit transaction on session {}", this); illegalStateExceptionIfClosed(); if (!this.transacted) throw new IllegalStateException("Session is not transacted"); if (this.enterCommittingBlock()) { try { // Call commit on the channel. // All messages ought already to have been acked. this.channel.txCommit(); } catch (Exception x) { this.logger.error("RabbitMQ exception on channel.txCommit() in session {}", this, x); throw new RMQJMSException(x); } finally { this.leaveCommittingBlock(); } } }
public void commitAll() throws AmqpException { try { for (Channel channel : this.channels) { if (this.deliveryTags.containsKey(channel)) { for (Long deliveryTag : this.deliveryTags.get(channel)) { channel.basicAck(deliveryTag, false); } } channel.txCommit(); } } catch (IOException e) { throw new AmqpException("failed to commit RabbitMQ transaction", e); } }
public void commitAll() throws AmqpException { try { for (Channel channel : this.channels) { if (this.deliveryTags.containsKey(channel)) { for (Long deliveryTag : this.deliveryTags.get(channel)) { channel.basicAck(deliveryTag, false); } } channel.txCommit(); } } catch (IOException e) { throw new AmqpException("failed to commit RabbitMQ transaction", e); } }
channel.txCommit(); }catch (Exception e){ channel.txRollback();
this.ackInfo.getChannel().txCommit();
/** * Non-blocking receive. * @param queueName the queue to receive from. * @return The message, or null if none immediately available. * @since 1.5 */ @Nullable protected Message doReceiveNoWait(final String queueName) { Message message = execute(channel -> { GetResponse response = channel.basicGet(queueName, !isChannelTransacted()); // Response can be null is the case that there is no message on the queue. if (response != null) { long deliveryTag = response.getEnvelope().getDeliveryTag(); if (isChannelLocallyTransacted(channel)) { channel.basicAck(deliveryTag, false); channel.txCommit(); } else if (isChannelTransacted()) { // Not locally transacted but it is transacted so it // could be synchronized with an external transaction ConnectionFactoryUtils.registerDeliveryTag(getConnectionFactory(), channel, deliveryTag); } return RabbitTemplate.this.buildMessageFromResponse(response); } return null; }, obtainTargetConnectionFactory(this.receiveConnectionFactorySelectorExpression, queueName)); logReceived(message); return message; }
/** * Non-blocking receive. * @param queueName the queue to receive from. * @return The message, or null if none immediately available. * @since 1.5 */ @Nullable protected Message doReceiveNoWait(final String queueName) { Message message = execute(channel -> { GetResponse response = channel.basicGet(queueName, !isChannelTransacted()); // Response can be null is the case that there is no message on the queue. if (response != null) { long deliveryTag = response.getEnvelope().getDeliveryTag(); if (isChannelLocallyTransacted(channel)) { channel.basicAck(deliveryTag, false); channel.txCommit(); } else if (isChannelTransacted()) { // Not locally transacted but it is transacted so it // could be synchronized with an external transaction ConnectionFactoryUtils.registerDeliveryTag(getConnectionFactory(), channel, deliveryTag); } return RabbitTemplate.this.buildMessageFromResponse(response); } return null; }, obtainTargetConnectionFactory(this.receiveConnectionFactorySelectorExpression, queueName)); logReceived(message); return message; }
@Override @Nullable public Message receive(final String queueName, final long timeoutMillis) { Message message = execute(channel -> { Delivery delivery = consumeDelivery(channel, queueName, timeoutMillis); if (delivery == null) { return null; } else { if (isChannelLocallyTransacted(channel)) { channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); channel.txCommit(); } else if (isChannelTransacted()) { ConnectionFactoryUtils.registerDeliveryTag(getConnectionFactory(), channel, delivery.getEnvelope().getDeliveryTag()); } else { channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); } return buildMessageFromDelivery(delivery); } }); logReceived(message); return message; }
@Override @Nullable public Message receive(final String queueName, final long timeoutMillis) { Message message = execute(channel -> { Delivery delivery = consumeDelivery(channel, queueName, timeoutMillis); if (delivery == null) { return null; } else { if (isChannelLocallyTransacted(channel)) { channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); channel.txCommit(); } else if (isChannelTransacted()) { ConnectionFactoryUtils.registerDeliveryTag(getConnectionFactory(), channel, delivery.getEnvelope().getDeliveryTag()); } else { channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); } return buildMessageFromDelivery(delivery); } }); logReceived(message); return message; }
verify(channel1).queueDeclare(anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyMap()); assertThat(((ChannelProxy) templateChannel.get()).getTargetChannel(), equalTo(channel1)); verify(channel1).txCommit();