{ // setup the sender client ...
sender = glob.getXmlBlasterAccess();
ConnectQos qos = new ConnectQos(sender.getGlobal(), senderName, "secret");
ConnectReturnQos conRetQos = sender.connect(qos, null); // Login to xmlBlaster
log.info("Sender connected to xmlBlaster " + conRetQos.getSessionName().getRelativeName());
}
{ // setup the receiver client which processes the request (usually another process) ...
Global globReceiver = glob.getClone(null);
receiver = globReceiver.getXmlBlasterAccess();
ConnectQos qos = new ConnectQos(receiver.getGlobal(), receiverName, "secret");
ConnectReturnQos conRetQos = receiver.connect(qos, new I_Callback() {
public String update(String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos) {
log.info(receiverName+": Receiving asynchronous message '" + updateKey.getOid() + "' in receiver default handler");
log.info(receiverName+": Received: " + updateKey.toXml() + "\n <content>" + new String(content) + "</content>" + updateQos.toXml());
if (updateKey.isInternal()) return "";
if (updateQos.isErased()) return "";
try {
String tempTopicOid = updateQos.getClientProperty(Constants.JMS_REPLY_TO, ""); // __jms:JMSReplyTo
log.info(receiverName+": Got request, using topic '" + tempTopicOid + "' for response");
// Send reply back ...
PublishKey pk = new PublishKey(receiver.getGlobal(), tempTopicOid, "text/plain", "1.0");
PublishQos pq = new PublishQos(receiver.getGlobal());
MsgUnit msgUnit = new MsgUnit(pk, "On doubt no ultimate truth, my dear.", pq);
//try { Thread.sleep(8000); } catch (InterruptedException e) { e.printStackTrace(); }
PublishReturnQos retQos = receiver.publish(msgUnit);
log.info(receiverName+": Published reply message using temporary topic " + retQos.getKeyOid());
}
catch (XmlBlasterException e) {
log.severe(receiverName+": Sending reply to " + updateQos.getSender() + " failed: " + e.getMessage());
}
return "";
}
}); // Login to xmlBlaster, default handler for updates
log.info("Receiver connected to xmlBlaster " + conRetQos.getSessionName().getRelativeName());
}
// Send a message to 'receiver' and block for the reply
PublishKey pk = new PublishKey(sender.getGlobal(), "requestForEnlightenment");
PublishQos pq = new PublishQos(sender.getGlobal());