创建TIBCO Rendezvous Listener等待对不同主题和候选事件键的响应

时间:2017-08-28 10:21:27

标签: java tibco-rv

发布的消息和收到的回复有两个不同的主题。现在我在我的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);
        }
    }
}

1 个答案:

答案 0 :(得分:2)

发送消息时,请添加其他字段

day_before = now - datetime.timedelta(days=1,
                                      hours=now.hour,
                                      minutes=now.minute,
                                      seconds=now.second)

然后将某个相关ID存储在某个哈希集中。

让发布者从请求中读取CORRELATION_ID并将其添加到响应中。

当您收到消息时,只有在CORRELATION_ID字段中具有您期望的ID时才处理它。