0

Messages published and response received are on two different subjects. Right now I have following set of functionality in my java class. Class is implementing TibrvMsgCallback interface. How can i make sure that whatever the message is published i am receiving exactly its response?

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);
        }
    }
}
Umair
  • 860
  • 2
  • 13
  • 30
  • 1
    This will only work if the publisher supports sending back to your inbox, or if it supports passing a correlation ID back - do you control the publisher? – dsolimano Aug 28 '17 at 22:09
  • What do you mean by control the publisher? I publish message on one subject and expect its response on the other subject. No Inbox thing in case of two separate subjects. How can i implement it through correlation ID? Please elaborate. – Umair Aug 29 '17 at 05:19

1 Answers1

2

When you send a message, add another field

var correlation_id = Guid.NewGuid().ToString();
msg.add("CORRELATION_ID", correlation_id);

and then stash that correlation ID somewhere, in a hash set perhaps.

Have the publisher read the CORRELATION_ID off of the request and add it to the response.

When you receive a message, only process it if it has the ID that you are expecting in the CORRELATION_ID field.

dsolimano
  • 8,870
  • 3
  • 48
  • 63
  • Yeah, i have implemented the same thing. wont it put overhead on application? It will check message that will be received in onMsg method. What do you suggest? – Umair Aug 30 '17 at 05:14
  • 2
    Sure, but processor time is cheap. Inboxes get around this by publishing just to your inbox, but it seems like you don't want to use them, so this is the cheapest workaround. – dsolimano Aug 30 '17 at 14:30