简体   繁体   English

Tibco-Rv:如何使用TibRv-Java API建立双向通信

[英]Tibco-Rv: How to establish two way communication using TibRv-Java api

Is it possible to have a callback while sending Tbrv msg using TibRvdTransport->send(msg) and in subscriber can we send a reply ? 使用TibRvdTransport->send(msg)发送Tbrv msg时是否可能有回调,并且在订户中我们可以发送回复吗?

I want to send "Hello" from publisher and receiver should receieve it and send "Hi" reply. 我想从发布者和接收者发送“ Hello”,并且应该接收并发送“ Hi”回复。 Publisher must get this "Hi" in callback and print it. 发布者必须在回调中获取此“ Hi”并进行打印。

Publisher=> 发布者=>

TibrvRvdTrasport transport= new TibrvRvdTrasport ("12000","127.0.0.1","6000");
TibrvMsg tibMsg = new TibrvMsg();
tibMsg.add("msg" "hello");
tibMsg.setSendSubject(subject);
transport.send(tibMsg);

Subscriber=> 订阅者=>

listener = new TibRvListener(tibRvQueue, new TibRvMsgCallback(){
    @Override
    public void onMsg(TibRvListener listener,TibRvMsg msg){
        try{
            -----//sendReply("Hi")
        }
        catch(Exception e){

        }
    }, 
    new TibRvdTransport("12000","127.0.0.1","6000")),subject,null);

Sure, here's one way of doing this. 当然,这是一种方法。 Typically you create a private 'inbox' subject that is used as reply subject on the original request. 通常,您创建一个私人“收件箱”主题,该主题用作原始请求的回复主题。 This 'inbox' is just a simple unique string. 该“收件箱”只是一个简单的唯一字符串。 It could be anything (also "REPLY"), but it's useful to have a unique one in most cases. 它可以是任何东西(也可以是“ REPLY”),但是在大多数情况下拥有一个唯一的东西很有用。

Sender side: 发件人方面:

  Tibrv.open(Tibrv.IMPL_NATIVE);
  TibrvRvdTransport transport = new TibrvRvdTransport ("12000","127.0.0.1","6000");
  TibrvMsg request = new TibrvMsg();
  request.add("msg", "hello ");
  request.setSendSubject("TEST");
  request.setReplySubject(transport.createInbox()); // the subject we expect a reply on

  System.err.println("sending request: " + request);
  TibrvMsg reply = transport.sendRequest(request, 10*1000); // wait 10 seconds for reply
  System.err.println("received response: " + reply);
  Tibrv.close();

And receiver side: 和接收方:

  Tibrv.open(Tibrv.IMPL_NATIVE);
  TibrvRvdTransport transport = new TibrvRvdTransport ("12000","127.0.0.1","6000");

  new TibrvListener( Tibrv.defaultQueue(), new TibrvMsgCallback() {

    @Override
    public void onMsg(TibrvListener listener, TibrvMsg msg)
    {
      try {
        System.err.println("received request: " + msg );
        TibrvMsg reply = new TibrvMsg();
        reply.setSendSubject(msg.getReplySubject()); // send response to the 'reply' subject
        reply.add("response","world!");
        System.err.println("sending response: " + reply );
        transport.send(reply);
      }
      catch (TibrvException e) {
        e.printStackTrace();
      }

    }}, transport, "TEST", null );

  TibrvDispatcher dispatcher = new TibrvDispatcher(Tibrv.defaultQueue());
  Thread.sleep(100*1000);
  dispatcher.destroy();
  Tibrv.close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM