🎄 Happy Holidays! 🥳
Most of Solace is closed December 24–January 1 so our employees can spend time with their families. We will re-open Thursday, January 2, 2024. Please expect slower response times during this period and open a support ticket for anything needing immediate assistance.
Happy Holidays!
Please note: most of Solace is closed December 25–January 2, and will re-open Tuesday, January 3, 2023.
Doing request/reply over Solace websockets using a custom replyTo Destination
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);