azure-sdk-for-js icon indicating copy to clipboard operation
azure-sdk-for-js copied to clipboard

Storage Queue process message returns base64 encoded messages

Open tmschbgr opened this issue 5 years ago • 8 comments

  • Package Name: @azure/storage-queue
  • Package Version: 12.0.1
  • Operating system: Windows OS
  • [x] nodejs
    • version: v12.13.1
  • [ ] browser
    • name/version:
  • [ ] typescript
    • version:
  • Is the bug related to documentation in
    • [ ] README.md
    • [ ] source code documentation
    • [ ] SDK API docs on https://docs.microsoft.com

Describe the bug When using the Queue Client sdk to receive messages the messageText is base64 encrypted. There is no documentation around this and I do not see the point of decrypting outside of the sdk.

     "receivedMessageItems": [
        {
            "messageId": "58a0a42b-0857-40bf-ba2b-7e011a1326f1",
            "insertedOn": "2020-01-06T23:46:43.000Z",
            "expiresOn": "2020-01-13T23:46:43.000Z",
            "popReceipt": "AgAAAAMAAAAAAAAACp5XUvPE1QE=",
            "nextVisibleOn": "2020-01-07T00:42:21.000Z",
            "dequeueCount": 5,
            "messageText": "eyJ0b3BpYyI6Ii9zdWJzY3JpcHRpb25zL2VjNWQzZDIxLTZmN2UtNGFjYS05ZTljLTE3NjFlNTNjZjhiOS9yZXNvdXJjZUdyb3Vwcy9BVV9ERUFfREVBTFNBQ0NFTEVSQVRPUkFQUC9wcm92aWRlcnMvTWljcm9zb2Z0LlN0b3JhZ2Uvc3RvcmFnZUFjY291bnRzL2F1ZGVhZGFhdWVkZXYiLCJzdWJqZWN0IjoiL2Jsb2JTZXJ2aWNlcy9kZWZhdWx..."
        }
    ]

To Reproduce Just follow the tutorial https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue#processing-a-message

Expected behavior Messages are getting returned as decrypted json

tmschbgr avatar Jan 07 '20 03:01 tmschbgr

@tmschbgr could you please share your code snippets that reproduced the issue? I just tried the sample of sending "hello world" and the received message text is still "hello world", i.e., not base64-encoded.

jeremymeng avatar Jan 07 '20 19:01 jeremymeng

The important question is if you encrypt message when adding it to the queue.

When manually adding a message to the queue in Azure Portal you get a checkbox "Encode the message body in Base64. I created an encrypted and an unencrypted message. In Node I get back:

Encrypted: SGVsbG8gV29ybGQgRW5jb2RlZA== Unencrypted: Hello World Decoded

The messages I am trying to consume get generated by Blob Event subscriptions and it seems like all of those messages get encrypted by default and I can not control.

Currently I am encrypting the messages myself, but I think there should be that option in the sdk.

const messageString = Buffer.from(receivedMessageItem.messageText, 'base64');
const message = JSON.parse(messageString);

My code otherwise is the same as the example code.

tmschbgr avatar Jan 07 '20 21:01 tmschbgr

Thanks @tmschbgr it is clearer to me now this is more a feature request of specifying option to decode the messages text when retrieving messages. /cc @XiaoningLiu @bterlson

jeremymeng avatar Jan 07 '20 21:01 jeremymeng

Thanks @tmschbgr for providing the feedback here. BTW. Do you think "adding samples for this usage" is good for you? Or you prefer to an inline implementation?

jiacfan avatar Jan 09 '20 09:01 jiacfan

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.

msftbot[bot] avatar May 14 '20 21:05 msftbot[bot]

There's still no mention of this in the documentation. This really needs to be raised front and center if this is the default. I am using an Azure Function to write a message to a queue using the QueueAttribute. When I look at the queue in Azure Storage Explorer, I don't see my messages Base64 encoded. But then when I use the Azure.Storage.Queues library to download these messages, they are coming through Base64 encoded. It took a fair bit of searching to figure out what's going on here, and it would be great to see this resolved after two years.

stephajn avatar Apr 08 '22 19:04 stephajn

@stephajn thank you for the report! I see you are using Azure.Storage.Queues. Just want to make sure that you are using JavaScript SDK, or we might need to improve the docs for other langauges as well if you are using .NET/Java/Python etc.

@EmmaZhu maybe mentioning in the ref doc of receiveMessages() that if the received message is base64-encoded, you can decode it with something like Buffer.from(receivedMessageItem.messageText, 'base64'); in NodeJS? We can also update the sample in the readme to have a comment about this too.

jeremymeng avatar Apr 08 '22 20:04 jeremymeng

@jeremymeng I am using the .NET SDK. It looks like this is an issue that is across other languages too.

stephajn avatar Apr 08 '22 21:04 stephajn