发布的消息和收到的响应涉及两个不同的主题。现在,我的 java 类中有以下一组功能。类正在实现 TibrvMsgCallback 接口。我如何确保无论发布什么消息,我都能准确收到它的响应?
public class TibcoRVUtility implements TibrvMsgCallback {
public void onMsg(TibrvListener listener, TibrvMsg msg) {
try {
_log.info("Request and Response found");
msgReceived = true;
} catch (final TibrvException ex) {
_log.error("Exception@" + this.getClass().getName() + ".onMsg", ex);
}
}
private void sendMessage(String messageString, final String soType,
final String responseSubject) {
try {
Tibrv.open(Tibrv.IMPL_NATIVE);
TibrvTransport transport = new TibrvRvdTransport(tibcoSetting.getService(), tibcoSetting.getNetwork(),
tibcoSetting.getDaemon());
String inboxName = transport.createInbox();
TibrvMsg msg = new TibrvMsg();
msg.setSendSubject("PUBLISH_SUBJECT");
msg.add("DATA", "DUMMY_MESSAGE");
TibrvListener listener = new TibrvListener(Tibrv.defaultQueue(), this, transport, responseSubject, null);
transport.send(msg);
_log.info("msg" + msg.toString());
_log.info("message successfully sent.");
while (!msgReceived) {
try {
Tibrv.defaultQueue().dispatch();
} catch (InterruptedException ex) {
_log.error("Exception@" + this.getClass().getName() + ".sendMessage", ex);
break;
} catch (TibrvException ex) {
_log.error("Exception@" + this.getClass().getName() + ".sendMessage", ex);
break;
}
}
listener.destroy();
transport.destroy();
} catch (TibrvException e) {
_log.error("Exception@" + this.getClass().getName() + ".sendMessage", e);
}
}
}