Try PubSub+
If you haven't already, check out our new Developer Portal! You'll find useful information about Solace PubSub+ as well as handy resources to get you started.

what method should I use to return the contents of a solace.message in human readable string

eddieeddie Member Posts: 3

I am exploring the node.js SOLACE REST API. I got the pub/sub to work with the sample code to work substituting vpn/url/credentials.
The received message, however, has the payload plus a lot of other things and I couldn't isolate the payload by itself. I looked up the API ( for class solace.Message and I saw methods associated with message such as getBinaryAttachment() and dump(Number flags). None of them does what I want which is to return a human readable string of the payload and nothing else. Can somebody help?

Best Answers

  • eddieeddie Posts: 3
    Accepted Answer

    Hi TomF,
    Thanks for your response. The payload in this case was generated by running a java program which generates ActiveMQ messages (kind of like JMS messages). I displayed the message type and it shows up as "0 - I think it means BINARY (the other types are MAP(1), STREAM(2) and TEXT(3). I 've tried something like message.getBinaryAttachment.toString(,xy) and message.getSdtContainer but they didn't get me what I want.
    Any ideas?



  • TamimiTamimi Member, Administrator, Employee Posts: 2 admin

    Hey Eddie!
    The getBinaryAttachment() method on the message object returns the payload and the dump() returns everything in the message

    You can perhaps as well take a look at the sample Node.js code under the "Receiving a message" section

    Another helpful resource could be checking out the nodejs sample code on github. Here is an example of the subscriber outputting the content of the message using the getBinaryAttachment() method

    Hopefully this helps

  • eddieeddie Member Posts: 3

    Thanks for the response. I am familiar with the links you posted. The sample code that you referred to in the links was the exact source of my code. All I did was cloned the code, changed the only changed the pub/sub parameters to match my environment and I did get the pub/sub to work exact the output was not in the form that I can use. The following is an excerpt from my console log. The code that I used to display this was straight from the sample (line 112):
    console.log('Received message: "' + message.getBinaryAttachment() + '", details:\n' + message.dump());
    partial output follows. Any ideas?
    Received message: "¬í sr ,com.solacesystems.jms.message.SolTextMessageõ�?ï�?$â L mTextt Ljava/lang/String;xr (com.solacesystems.jms.message.SolMessageû÷/Ñ_-iø I mJMSDeliveryModeZ mJMSDestinati
    mJMSTimestampZ mJMSTimestampSetZ mReadOnlyPropertiesL mDMQEligiblet Ljava/lang/Boolean;L mDiscardIndicationq ~ L mElidingEligibleq ~ L mHTTPContentEncodingq ~ L mHTTPContentTypeq ~ L mIsDT
    mJMSMessageIDq ~ L mJMSReplyToq ~ LmJMSTypeq ~ L mPropertiest Ljava/util/Map;L mmSenderIDq ~ L mTopicSequenceNumbert Ljava/lang/Long;xp ppppppppppppppsr java.uti
    l.HashMapÚ�?Ã`Ñ F
    loadFactorI [email protected] t EventTypet SAVEt EventNamet CONTACT_RECORD_SAVE_EVENTxppxtD{"dataObject":{"callDuration":416545,"preferredLanguageCode":"English","contactChanne
    lType":"Phone","consumerLastName":"mDadbVSekoAX","linkRefId":-200309084220205,"consumerPhone":"4574339910","contactType":"Third Party","createdOn":"2020-03-09T17:57:11.716-05:00","inboundCallQueue":"El
    716-05:00","contactCompaignType":"Enrollment Reminder","updatedBy":null,"organizationName":"Brg","contactRecordStatusType":"Dropped","updatedOn":null,"linkRefType":"consumer","consumerFirstName":"wKdlh
    o","contactOutcome":"Reached Successfully","wrapUpTime":"00:00:59","createdBy":"txxhc","consumerAuthenticatedInd":"false","contactRecordType":"Inbound","contactReasonEditType":"Correcting Contact Reaso
    n/Action","consumerEmail":"[email protected]"},"recordType":"Contact Record","action":"Create","eventCreatedOn":"2020-03-09T18:20:48.663-05:00","projectName":"StxdWRhnnXrrOsG","projectId":-20030908421825
    6}x", details:
    Destination: [Topic A/B]
    AppMessageID: ID:fe80:0:0:0:890:ef43:a717:e2a2%eth12f8f2170bf5144bb0:41827
    SendTimestamp: 1583796048663 (Mon Mar 09 2020 19:20:48 GMT-0400 (Eastern Daylight Time))
    Class Of Service: COS1
    DeliveryMode: DIRECT
    User Property Map: 3 entries
    Key 'EventType' (STRING): SAVE
    Key 'JMSXUserID' (STRING): solace-cloud-client

    Binary Attachment: len=2016
    ac ed 00 05 73 72 00 2c 63 6f 6d 2e 73 6f 6c 61,com.sola
    63 65 73 79 73 74 65 6d 73 2e 6a 6d 73 2e 6d 65
    73 73 61 67 65 2e 53 6f 6c 54 65 78 74 4d 65 73 ssage.SolTextMes
    73 61 67 65 f5 8f ef 0e cd 24 1e e2 03 00 01 4c sage.....$.....L....

  • TamimiTamimi Member, Administrator, Employee Posts: 2 admin
    edited March 10

    @eddie Was the message from the publisher attached as a binary attachment (or did you do any modifications on the publisher side from the samples)? i.e. message.setBinaryAttachment(PayloadMessageText);

    You can check out a simpler demo usage here, this repo sets up a simple PubSub locally with a broker using a docker image that you can try it on your machine (simply run the docker-compose up command and follow the readme). In this example message.getBinaryAttachment() prints out the content of the message in text format. If you also attempted to access the SDT container field message.getSdtContainer() you will see that its null

Sign In or Register to comment.