@Override public void onDelivery(Event event) { Receiver recv = (Receiver) event.getLink(); Delivery delivery = recv.current(); if (delivery.isReadable() && !delivery.isPartial()) { int size = delivery.pending(); byte[] buffer = new byte[size]; int read = recv.recv(buffer, 0, buffer.length); recv.advance(); Message msg = Proton.message(); msg.decode(buffer, 0, read); ++count; String msgBody = ((AmqpValue) msg.getBody()).getValue().toString(); String expected = "message-" + count; if (!expected.equals(msgBody)) { throw new RuntimeException( "Received message body '" + msgBody + "', expected: '" + expected + "'"); } if (count == numMsgs) { recv.close(); recv.getSession().close(); recv.getSession().getConnection().close(); acceptor.close(); } } }
@Override public boolean isPartial() { return delivery.isPartial(); }