private void addChannel(AMQChannel channel) { synchronized (_channelAddRemoveLock) { _channelMap.put(channel.getChannelId(), channel); if(_blocking) { channel.block(); } } }
void closeChannel(AMQChannel channel, int cause, String message, boolean mark) { int channelId = channel.getChannelId(); try { channel.close(cause, message); if(mark) { markChannelAwaitingCloseOk(channelId); } } finally { removeChannel(channelId); } }
@Override public void receiveTxRollback() { if(LOGGER.isDebugEnabled()) { LOGGER.debug("RECV[" + _channelId + "] TxRollback"); } if (!isTransactional()) { closeChannel(ErrorCodes.COMMAND_INVALID, "Fatal error: rollback called on non-transactional channel"); } else { final MethodRegistry methodRegistry = _connection.getMethodRegistry(); final AMQMethodBody responseBody = methodRegistry.createTxRollbackOkBody(); Runnable task = () -> _connection.writeFrame(responseBody.generateFrame(_channelId)); rollback(task); // TODO: This is not spec compliant but we currently seem to rely on this behaviour resend(); } }
@Override public void receiveTxCommit() { if(LOGGER.isDebugEnabled()) { LOGGER.debug("RECV[" + _channelId + "] TxCommit"); } if (!isTransactional()) { closeChannel(ErrorCodes.COMMAND_INVALID, "Fatal error: commit called on non-transactional channel"); } else { commit(new Runnable() { @Override public void run() { _connection.writeFrame(_txCommitOkFrame); } }, true); } }
? getDefaultQueue() : getQueue(queueName.toString()); ? "No default queue defined on channel and queue was null" : "Queue '" + queueName + "' does not exist."; closeChannel(ErrorCodes.NOT_FOUND, message); else if (isDefaultExchange(exchange)) + "' from the default exchange", getChannelId()); final Exchange<?> exch = getExchange(exchange.toString()); final String bindingKeyStr = bindingKey == null ? "" : AMQShortString.toString(bindingKey); closeChannel(ErrorCodes.NOT_FOUND, "Exchange '" + exchange + "' does not exist."); closeChannel(ErrorCodes.NOT_FOUND, "No such binding"); sync(); _connection.writeFrame(responseBody.generateFrame(getChannelId())); _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
MessageInstance message = getUnacknowledgedMessageMap().get(deliveryTag); ": Requeue:" + requeue " on channel:" + debugIdentity()); requeue(deliveryTag); final boolean maxDeliveryCountEnabled = isMaxDeliveryCountEnabled(deliveryTag); if (LOGGER.isDebugEnabled()) final boolean deliveredTooManyTimes = isDeliveredTooManyTimes(deliveryTag); if (LOGGER.isDebugEnabled()) deadLetter(deliveryTag); requeue(deliveryTag);
if (isDefaultExchange(exchangeName)) + " of type " + ExchangeDefaults.DIRECT_EXCHANGE_CLASS + " to " + type + ".", getChannelId()); sync(); _connection.writeFrame(declareOkBody.generateFrame(getChannelId())); exchange = getExchange(exchangeName.toString()); if (exchange == null) closeChannel(ErrorCodes.NOT_FOUND, "Unknown exchange: '" + exchangeName + "'"); + " to " + type + ".", getChannelId()); sync(); _connection.writeFrame(declareOkBody.generateFrame(getChannelId())); validateAlternateExchangeIsNotQueue(virtualHost, alternateExchangeName); attributes.put(Exchange.ALTERNATE_BINDING, Collections.singletonMap(AlternateBinding.DESTINATION, alternateExchangeName)); validateExchangeDeclareArguments(attributes); exchange = virtualHost.createMessageDestination(Exchange.class, attributes); sync();
queue = getQueue(queueName.toString()); if (queue == null) closeChannel(ErrorCodes.NOT_FOUND, "Queue: '" + queueName + "' is exclusive, but not created on this Connection.", getChannelId()); setDefaultQueue(queue); if (!nowait) sync(); MethodRegistry methodRegistry = _connection.getMethodRegistry(); QueueDeclareOkBody responseBody = queue.getQueueDepthMessages(), queue.getConsumerCount()); _connection.writeFrame(responseBody.generateFrame(getChannelId())); validateAlternateExchangeIsNotQueue(virtualHost, alternateExchangeName); QueueArgumentsConverter.convertWireArgsToModel(queueNameString, wireArguments, getModel()); setDefaultQueue(queue); sync(); MethodRegistry methodRegistry = _connection.getMethodRegistry(); QueueDeclareOkBody responseBody =
if (queueName == null && (queue = getDefaultQueue()) == null) _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "No queue specified.", getChannelId()); else if ((queueName != null) && (queue = getQueue(queueName.toString())) == null) closeChannel(ErrorCodes.NOT_FOUND, "Queue '" + queueName + "' does not exist."); "Queue is exclusive, but not created on this Connection.", getChannelId()); if (!nowait) sync(); MethodRegistry methodRegistry = _connection.getMethodRegistry(); AMQMethodBody responseBody = methodRegistry.createQueuePurgeOkBody(purged); _connection.writeFrame(responseBody.generateFrame(getChannelId())); _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
if(blockingTimeoutExceeded()) message(ChannelMessages.FLOW_CONTROL_IGNORED()); closeChannel(ErrorCodes.MESSAGE_TOO_LARGE, "Channel flow control was requested, but not enforced by sender"); if (isDefaultExchange(exchangeName)) closeChannel(ErrorCodes.NOT_FOUND, "Unknown exchange name: '" + exchangeName + "'"); setPublishFrame(info, destination); _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
sync(); if (isDefaultExchange(exchangeStr)) "Default Exchange cannot be deleted", getChannelId()); final Exchange<?> exchange = getExchange(exchangeName); if (exchange == null) closeChannel(ErrorCodes.NOT_FOUND, "No such exchange: '" + exchangeStr + "'"); closeChannel(ErrorCodes.IN_USE, "Exchange has bindings"); _connection.writeFrame(responseBody.generateFrame(getChannelId())); closeChannel(ErrorCodes.NOT_ALLOWED, "Exchange in use as an alternate binding destination"); closeChannel(ErrorCodes.NOT_ALLOWED, "Exchange '" + exchangeStr + "' cannot be deleted"); _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
sync(); String queueName = AMQShortString.toString(queue); MessageSource queue1 = queueName == null ? getDefaultQueue() : vHost.getAttainedMessageSource(queueName); final Collection<MessageSource> sources = new HashSet<>(); closeChannel(ErrorCodes.NOT_FOUND, "No such queue, '" + queueName + "'"); consumerTag1 = consumeFromSource(consumerTag1, sources, !noAck,
@Override public void receiveMessageHeader(final BasicContentHeaderProperties properties, final long bodySize) { if(LOGGER.isDebugEnabled()) { LOGGER.debug("RECV[" + _channelId + "] MessageHeader[ properties: {" + properties + "} bodySize: " + bodySize + " ]"); } if(hasCurrentMessage()) { if(bodySize > _connection.getMaxMessageSize()) { properties.dispose(); closeChannel(ErrorCodes.MESSAGE_TOO_LARGE, "Message size of " + bodySize + " greater than allowed maximum of " + _connection.getMaxMessageSize()); } else { publishContentHeader(new ContentHeaderBody(properties, bodySize)); } } else { properties.dispose(); _connection.sendConnectionClose(ErrorCodes.COMMAND_INVALID, "Attempt to send a content header without first sending a publish frame", _channelId); } }
@Override protected void doSendInternal(final MessageInstanceConsumer consumer, final MessageInstance entry, final AMQMessage message, final boolean batch) { // put queue entry on a list and then notify the connection to read list. synchronized (getChannel()) { getChannel().getConnection().setDeferFlush(batch); long deliveryTag = getChannel().getNextDeliveryTag(); addUnacknowledgedMessage(entry); getChannel().addUnacknowledgedMessage(entry, deliveryTag, consumer, _usesCredit); sendToClient(consumer, message, entry.getInstanceProperties(), deliveryTag); entry.incrementDeliveryCount(); } } }
final AMQChannel channel = new AMQChannel(this, channelId, virtualHost.getMessageStore()); channel.create();
@Override public void close() { close(0, null); }
@Override public void block() { synchronized (_channelAddRemoveLock) { if(!_blocking) { _blocking = true; for(AMQChannel channel : _channelMap.values()) { channel.block(); } } } }
queue = getDefaultQueue(); queue = getQueue(queueName.toString()); ? "No default queue defined on channel and queue was null" : "Queue " + queueName + " does not exist."; closeChannel(ErrorCodes.NOT_FOUND, message); else if (isDefaultExchange(exchange)) "Cannot bind the queue '" + queueName + "' to the default exchange", getChannelId()); final Exchange<?> exch = getExchange(exchangeName); if (exch == null) closeChannel(ErrorCodes.NOT_FOUND, "Exchange '" + exchangeName + "' does not exist."); exch.getName(), e.getMessage()), getChannelId()); sync(); MethodRegistry methodRegistry = _connection.getMethodRegistry(); AMQMethodBody responseBody = methodRegistry.createQueueBindOkBody(); _connection.writeFrame(responseBody.generateFrame(getChannelId())); _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
": Requeue:" + requeue " on channel:" + debugIdentity()); requeue(deliveryTag); final boolean maxDeliveryCountEnabled = isMaxDeliveryCountEnabled(deliveryTag); if (LOGGER.isDebugEnabled()) final boolean deliveredTooManyTimes = isDeliveredTooManyTimes(deliveryTag); if (LOGGER.isDebugEnabled()) deadLetter(deliveryTag); requeue(deliveryTag);
sync(); Queue<?> queue; if (queueName == null) queue = getDefaultQueue(); queue = getQueue(queueName.toString()); closeChannel(ErrorCodes.NOT_FOUND, "Queue '" + queueName + "' does not exist."); closeChannel(ErrorCodes.IN_USE, "Queue: '" + queueName + "' is not empty."); closeChannel(ErrorCodes.IN_USE, "Queue: '" + queueName + "' is still used."); + "' is exclusive, but not created on this Connection.", getChannelId()); _connection.writeFrame(responseBody.generateFrame(getChannelId())); _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());