🎄 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.
HTTP headers
With Solace Cloud, is there a way to get the HTTP headers in my message too? I realize that the HTTP option gives me the complete payload in my message but I wasn’t able to figure out from the docs how I can get the HTTP headers from the request into my message. In some of my cases (or at least where I’d love to use it for) the HTTP headers have information I’d need
Best Answer
-
So, I figured it out
In my REST message I'm not adding a header for thecorrelation ID
, that means that internally the gateway uses a generatedappMessgeID
for correlation between request and reply. The problem is that the defaultsession.sendReply()
method takes the correlationID of the original message if you provide a message to reply to (which I found out after reading the API docs for the session object). When I manually construct the reply, and set the appropriate destination and correlation ID headers, it works perfectly. So in my case, the response should have been constructed as:var reply = solace.SolclientFactory.createMessage(); var replyText = "Sample Reply"; reply.setSdtContainer(solace.SDTField.create(solace.SDTFieldType.STRING, replyText)); reply.setAsReplyMessage(true); reply.setDestination(message.getReplyTo()); reply.setCorrelationId(message.getApplicationMessageId()); subscriber.session.sendReply(null,reply)
6
Answers
-
@retgits said:
I realize that the HTTP option gives me the complete payload in my messageCan you provide a bit more information on what you're trying to do here? "the HTTP option", are you referring to REST?
0 -
Yup, I'm indeed looking at the REST API and working through the REST example (https://docs.solace.com/Open-APIs-Protocols/REST-get-start.htm). When I use the "try me!" option in the UI as a subscriber to my topic called "try-me" and use a cURL command to send a message
curl -X POST https://<host>:<port>/try-me \ -d "Hello World REST" \ -H "content-type: text" \ -H "Solace-delivery-mode: direct" \ --user <user>:<password> --header "MyHeader:x"
I can't find the correct way to let it also display the header called "MyHeader" (it does display the body correctly)
1 -
I've figured out a few things, but I'm still a little stuck so help is still appreciated
After reading through some more docs, I realized that my instance was inmessaging mode
and I had to switch that togateway mode
. After that, and realizing I couldn't use the MQTT client anymore, I was able to get the header parameter using the statementmessage.getUserPropertyMap().getField("JMS_Solace_HTTP_field_<header name>")
. I've taken the TopicSubscriber.js and modified it to my needs. My only issue now is that the gateway assumes there will be a reply and I don't know how to configure that (or how to configure no reply is needed). The response I get from my cURL command is:< HTTP/1.1 504 Reply Wait Timeout < Cache-Control: no-cache < Content-Length: 263 < Content-Type: text/xml < Server: Solace_PubSub+_Enterprise/8.13.1.31 < Set-Cookie: TSID=<>; Path=/ < Solace-Client-Name: #rest-<> < <solace-error-response> <code>504</code> <reason><![CDATA[Reply Wait Timeout]]></reason> <detail><![CDATA[ Timed out waiting for reply after 30001ms; Solace-Reply-Wait-Time=30000ms ]]></detail> <internal-use>1:7422</internal-use> </solace-error-response> * Connection #0 to host <>.messaging.solace.cloud left intact
1 -
Thanks for the updated info - let me do some checking and I will get back with you.
0 -
So, I figured it out
In my REST message I'm not adding a header for thecorrelation ID
, that means that internally the gateway uses a generatedappMessgeID
for correlation between request and reply. The problem is that the defaultsession.sendReply()
method takes the correlationID of the original message if you provide a message to reply to (which I found out after reading the API docs for the session object). When I manually construct the reply, and set the appropriate destination and correlation ID headers, it works perfectly. So in my case, the response should have been constructed as:var reply = solace.SolclientFactory.createMessage(); var replyText = "Sample Reply"; reply.setSdtContainer(solace.SDTField.create(solace.SDTFieldType.STRING, replyText)); reply.setAsReplyMessage(true); reply.setDestination(message.getReplyTo()); reply.setCorrelationId(message.getApplicationMessageId()); subscriber.session.sendReply(null,reply)
6 -
I also made a quick write-up of how I configured everything and the use case I needed this for https://retgits.com/2019/06/how-to-get-webhooks-into-your-system-using-solace-pubsub-cloud/
2