final AMQChannel channel,
final boolean acks)
throws AMQException
{
final FlowCreditManager singleMessageCredit = new MessageOnlyCreditManager(1L);
final ClientDeliveryMethod getDeliveryMethod = new ClientDeliveryMethod()
{
public void deliverToClient(final Subscription sub, final QueueEntry entry, final long deliveryTag)
throws AMQException
{
singleMessageCredit.useCreditForMessage(entry.getMessage().getSize());
if(entry.getMessage() instanceof AMQMessage)
{
session.getProtocolOutputConverter().writeGetOk(entry, channel.getChannelId(),
deliveryTag, queue.getMessageCount());
entry.incrementDeliveryCount();
}
else
{
//TODO Convert AMQP 0-10 message
throw new AMQException(AMQConstant.NOT_IMPLEMENTED, "Not implemented conversion of 0-10 message", null);
}
}
};
final RecordDeliveryMethod getRecordMethod = new RecordDeliveryMethod()
{
public void recordMessageDelivery(final Subscription sub, final QueueEntry entry, final long deliveryTag)
{
channel.addUnacknowledgedMessage(entry, deliveryTag, null);
}
};
Subscription sub;
if(acks)
{
sub = SubscriptionFactoryImpl.INSTANCE.createSubscription(channel, session, null, acks, null, false, singleMessageCredit, getDeliveryMethod, getRecordMethod);
}
else
{
sub = SubscriptionFactoryImpl.INSTANCE.createBasicGetNoAckSubscription(channel, session, null, null, false, singleMessageCredit, getDeliveryMethod, getRecordMethod);
}
queue.registerSubscription(sub,false);
queue.flushSubscription(sub);
queue.unregisterSubscription(sub);
return(!singleMessageCredit.hasCredit());
}