AMQProtocolSession session = stateManager.getProtocolSession();
AMQChannel channel = session.getChannel(channelId);
VirtualHost vHost = session.getVirtualHost();
if (channel == null)
{
throw body.getChannelNotFoundException(channelId);
}
else
{
if (_logger.isDebugEnabled())
{
_logger.debug("BasicConsume: from '" + body.getQueue() +
"' for:" + body.getConsumerTag() +
" nowait:" + body.getNowait() +
" args:" + body.getArguments());
}
AMQQueue queue = body.getQueue() == null ? channel.getDefaultQueue() : vHost.getQueueRegistry().getQueue(body.getQueue().intern());
if (queue == null)
{
if (_logger.isDebugEnabled())
{
_logger.debug("No queue for '" + body.getQueue() + "'");
}
if (body.getQueue() != null)
{
String msg = "No such queue, '" + body.getQueue() + "'";
throw body.getChannelException(AMQConstant.NOT_FOUND, msg);
}
else
{
String msg = "No queue name provided, no default queue defined.";
throw body.getConnectionException(AMQConstant.NOT_ALLOWED, msg);
}
}
else
{
final AMQShortString consumerTagName;
// Check authz
if (!vHost.getAccessManager().authoriseConsume(session,
body.getExclusive(), body.getNoAck(),
body.getNoLocal(), body.getNowait(), queue))
{
throw body.getConnectionException(AMQConstant.ACCESS_REFUSED, "Permission denied");
}
if (body.getConsumerTag() != null)
{
consumerTagName = body.getConsumerTag().intern();
}
else
{
consumerTagName = null;
}
try
{
AMQShortString consumerTag = channel.subscribeToQueue(consumerTagName, queue, !body.getNoAck(),
body.getArguments(), body.getNoLocal(), body.getExclusive());
if (!body.getNowait())
{
MethodRegistry methodRegistry = session.getMethodRegistry();
AMQMethodBody responseBody = methodRegistry.createBasicConsumeOkBody(consumerTag);