Reputation: 1
Is it possible to have a callback while sending Tbrv msg using TibRvdTransport->send(msg)
and in subscriber can we send a reply ?
I want to send "Hello" from publisher and receiver should receieve it and send "Hi" reply. Publisher must get this "Hi" in callback and print it.
TibrvRvdTrasport transport= new TibrvRvdTrasport ("12000","127.0.0.1","6000");
TibrvMsg tibMsg = new TibrvMsg();
tibMsg.add("msg" "hello");
tibMsg.setSendSubject(subject);
transport.send(tibMsg);
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);
Upvotes: 0
Views: 2714
Reputation: 4323
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.
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();
Upvotes: 0