[英]Send JSON message to Azure Queue storage
I am using azure-storage
node module.我正在使用
azure-storage
节点模块。 I would like to send JSON on my queue and get it into my queue on azure function.我想在我的队列中发送 JSON 并通过 azure 函数将其放入我的队列中。
I send message in queue.我在队列中发送消息。 I stringify my message to put in queue.
我将我的消息字符串化以放入队列。
// This is my service who send message to queue via node lib azure-storage
const queueMsg = {
userId,
token: tokenNotif
};
queueSvc.createMessage(Config.REGISTRATION_FCM_PUSH_NOTIFICATION_QUEUE, JSON.stringify(queueMsg), (err) => {
if (!error) {
this._logger.info(`User ${userId} has register this push notification token`);
resolve(true);
} else {
reject(false);
}
});
And in the queue function i have an error because the function think isn't a string and push the message text on xx-queue-poison {"userId":"a6c8a103-dacc-4b15-bffd-60693105f131","token":"xxxx"}
在队列函数中,我有一个错误,因为函数认为不是字符串并将消息文本推
{"userId":"a6c8a103-dacc-4b15-bffd-60693105f131","token":"xxxx"}
xx-queue-poison {"userId":"a6c8a103-dacc-4b15-bffd-60693105f131","token":"xxxx"}
I don't know why the quote is replaced by ASCII code on queue ?我不知道为什么引号被队列上的 ASCII 代码替换?
I have tested something else!我测试了别的东西! From my service i call a Http Azure function, and this function call the Queue Storage and it's work by this way :s ..
在我的服务中,我调用了一个 Http Azure 函数,这个函数调用了队列存储,它是通过这种方式工作的 :s ..
The HttpTrigger function call queue context.bindings.notificationQueue = [{ userId: name, token }];
HttpTrigger 函数调用队列
context.bindings.notificationQueue = [{ userId: name, token }];
And queue received data context.log(`Received userId ${queueItem.userId} :: ${queueItem.token}`);
和队列接收数据
context.log(`Received userId ${queueItem.userId} :: ${queueItem.token}`);
Why by using HttpTrigger function to QueueTrigger function it's working, but when i am using the lib "azure-storage" is not working ?为什么通过使用 HttpTrigger 函数到 QueueTrigger 函数它可以工作,但是当我使用库“azure-storage”时却不起作用?
Thx谢谢
I don't know why the quote is replaced by ASCII code on queue ?
我不知道为什么引号被队列上的 ASCII 代码替换?
Basically the SDK is converting the string message to make it XML safe.基本上,SDK 正在转换字符串消息以使其 XML 安全。 If you look at the code in the SDK, by default it uses
TextXmlQueueMessageEncoder
as the message encoder.如果您查看 SDK 中的代码,默认情况下它使用
TextXmlQueueMessageEncoder
作为消息编码器。 The encode
function replaces "
with "
to make it XML safe.该
encode
函数替换"
与"
使其XML安全。
From the SDK code (partial code snippets):来自 SDK 代码(部分代码片段):
QueueService.prototype.createMessage = function (queue, messageText, optionsOrCallback, callback) {
var userOptions;
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { userOptions = o; callback = c; });
validate.validateArgs('createMessage', function (v) {
v.string(queue, 'queue');
v.queueNameIsValid(queue);
v.callback(callback);
});
var xmlMessageDescriptor = QueueMessageResult.serialize(messageText, this.messageEncoder);
function TextXmlQueueMessageEncoder(){
}
util.inherits(TextXmlQueueMessageEncoder, QueueMessageEncoder);
/**
* Encode utf-8 string by escaping the xml markup characters.
* @this TextXmlQueueMessageEncoder
*
* @param {string} [input] The target to be encoded.
*
* @return {string}
*/
TextXmlQueueMessageEncoder.prototype.encode = function(input){
return input.replace(/&/gm, '&')
.replace(/</gm, '<')
.replace(/>/gm, '>')
.replace(/"/gm, '"')
.replace(/'/gm, ''');
};
One possible solution would be to convert the string to a base64 encoded string as you suggested.一种可能的解决方案是按照您的建议将字符串转换为 base64 编码的字符串。 However if you're using the SDK to retrieve the messages, you should not see these
"
但是,如果您使用 SDK 来检索消息,则不应看到这些
"
in your message body as the SDK takes care of decoding the message.在您的消息正文中,因为 SDK 负责对消息进行解码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.