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 @Override
public void close() { public void close() {
if (!isClosed() && isOpened()) { 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(); super.close();
} }
}
//----- Configuration accessors ------------------------------------------// //----- Configuration accessors ------------------------------------------//

View File

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

View File

@ -108,11 +108,15 @@ public class AmqpSession implements AmqpResource {
public void close() { public void close() {
LOG.debug("Session {} closed", getSessionId()); 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().setContext(null);
getEndpoint().close(); getEndpoint().close();
getEndpoint().free(); getEndpoint().free();
}
connection.sendToActiveMQ(new RemoveInfo(getSessionId())); });
} }
/** /**