Doing request/reply over Solace websockets using a custom replyTo Destination
tkunnumpurath
Member, Employee Posts: 11 Solace Employee
If you have a requirement to using a custom replyTo destination for your request using the Solace Websockets API - follow along this tutorial - https://solace.com/samples/solace-samples-javascript/request-reply/ and make the following enhancements:
Add the following function to the BasicRequestor.js -
requestor.subscribe = function (topicName) { if (requestor.session !== null) { if (requestor.subscribed) { requestor.log('Already subscribed to "' + topicName + '" and ready to receive messages.'); } else { requestor.log('Subscribing to topic: ' + topicName); try { requestor.session.subscribe( solace.SolclientFactory.createTopicDestination(topicName), true, // generate confirmation when subscription is added successfully topicName, // use topic name as correlation key 10000 // 10 seconds timeout for this operation ); } catch (error) { requestor.log(error.toString()); } } } else { requestor.log('Cannot subscribe because not connected to Solace message router.'); } };
In the requestor.request function, add the following lines of code:
var replyTo = 'REPLY/TOPIC'; request.setReplyTo(solace.SolclientFactory.createTopicDestination(replyTo)); requestor.subscribe(replyTo);
2