use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target in project qpid-broker-j by apache.
the class FlowTest method asynchronousNotification.
@Test
@SpecificationTest(section = "2.6.9", description = "Asynchronous notification can be accomplished as follows." + " The receiver maintains a target amount of link-credit for that link." + " As transfer arrive on the link, the sender’s link-credit decreases" + " as the delivery-count increases. When the sender’s link-credit falls below a threshold," + " the flow state MAY be sent to increase the sender’s link-credit back" + " to the desired target amount.")
public void asynchronousNotification() throws Exception {
BrokerAdmin brokerAdmin = getBrokerAdmin();
brokerAdmin.createQueue(BrokerAdmin.TEST_QUEUE_NAME);
String messageContent1 = "Test1";
String messageContent2 = "Test2";
String messageContent3 = "Test2";
brokerAdmin.putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageContent1);
brokerAdmin.putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageContent2);
brokerAdmin.putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageContent3);
final InetSocketAddress addr = brokerAdmin.getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
try (FrameTransport transport = new FrameTransport(addr).connect()) {
Interaction interaction = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class);
Attach remoteAttach = interaction.getLatestResponse(Attach.class);
UnsignedInteger remoteHandle = remoteAttach.getHandle();
assertThat(remoteHandle, is(notNullValue()));
UnsignedInteger delta = UnsignedInteger.ONE;
UnsignedInteger incomingWindow = UnsignedInteger.valueOf(3);
Object receivedMessageContent1 = interaction.flowIncomingWindow(incomingWindow).flowNextIncomingId(UnsignedInteger.ZERO).flowLinkCredit(delta).flowHandleFromLinkHandle().flow().receiveDelivery().decodeLatestDelivery().getDecodedLatestDelivery();
assertThat(receivedMessageContent1, is(equalTo(messageContent1)));
assertThat(interaction.getLatestDeliveryId(), is(equalTo(UnsignedInteger.ZERO)));
Object receivedMessageContent2 = interaction.flowIncomingWindow(incomingWindow).flowNextIncomingId(UnsignedInteger.ONE).flowLinkCredit(delta).flowHandleFromLinkHandle().flow().receiveDelivery().decodeLatestDelivery().getDecodedLatestDelivery();
assertThat(receivedMessageContent2, is(equalTo(messageContent2)));
assertThat(interaction.getLatestDeliveryId(), is(equalTo(UnsignedInteger.ONE)));
// send session flow with echo=true to verify that no message is delivered without issuing a credit
Flow responseFlow = interaction.flowNextIncomingId(UnsignedInteger.valueOf(2)).flowLinkCredit(null).flowHandle(null).flowEcho(Boolean.TRUE).flow().consumeResponse().getLatestResponse(Flow.class);
assertThat(responseFlow.getHandle(), is(nullValue()));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target in project qpid-broker-j by apache.
the class Interaction method attachTargetAddress.
public Interaction attachTargetAddress(final String address) {
final Target target = ((Target) _attach.getTarget());
target.setAddress(address);
_attach.setTarget(target);
return this;
}
Aggregations