Wait on broker response for async broker commands.
This commit is contained in:
Timothy Bish 2016-06-29 20:13:34 -04:00
parent 4e23adfcc9
commit 83827f2770
3 changed files with 44 additions and 22 deletions

View File

@ -90,11 +90,17 @@ public class AmqpReceiver extends AmqpAbstractReceiver {
@Override
public void close() {
if (!isClosed() && isOpened()) {
sendToActiveMQ(new RemoveInfo(getProducerId()));
}
sendToActiveMQ(new RemoveInfo(getProducerId()), new ResponseHandler() {
@Override
public void onResponse(AmqpProtocolConverter converter, Response response) throws IOException {
AmqpReceiver.super.close();
}
});
} else {
super.close();
}
}
//----- Configuration accessors ------------------------------------------//

View File

@ -118,21 +118,30 @@ public class AmqpSender extends AmqpAbstractLink<Sender> {
if (!isClosed() && isOpened()) {
RemoveInfo removeCommand = new RemoveInfo(getConsumerId());
removeCommand.setLastDeliveredSequenceId(lastDeliveredSequenceId);
sendToActiveMQ(removeCommand);
sendToActiveMQ(removeCommand, new ResponseHandler() {
@Override
public void onResponse(AmqpProtocolConverter converter, Response response) throws IOException {
session.unregisterSender(getConsumerId());
AmqpSender.super.detach();
}
});
} else {
super.detach();
}
}
@Override
public void close() {
if (!isClosed() && isOpened()) {
RemoveInfo removeCommand = new RemoveInfo(getConsumerId());
removeCommand.setLastDeliveredSequenceId(lastDeliveredSequenceId);
sendToActiveMQ(removeCommand);
sendToActiveMQ(removeCommand, new ResponseHandler() {
@Override
public void onResponse(AmqpProtocolConverter converter, Response response) throws IOException {
if (consumerInfo.isDurable()) {
RemoveSubscriptionInfo rsi = new RemoveSubscriptionInfo();
rsi.setConnectionId(session.getConnection().getConnectionId());
@ -143,10 +152,13 @@ public class AmqpSender extends AmqpAbstractLink<Sender> {
}
session.unregisterSender(getConsumerId());
AmqpSender.super.close();
}
});
} else {
super.close();
}
}
@Override
public void flow() throws Exception {

View File

@ -108,11 +108,15 @@ public class AmqpSession implements AmqpResource {
public void close() {
LOG.debug("Session {} closed", getSessionId());
connection.sendToActiveMQ(new RemoveInfo(getSessionId()), new ResponseHandler() {
@Override
public void onResponse(AmqpProtocolConverter converter, Response response) throws IOException {
getEndpoint().setContext(null);
getEndpoint().close();
getEndpoint().free();
connection.sendToActiveMQ(new RemoveInfo(getSessionId()));
}
});
}
/**