[英]Azure Function QueueTrigger and int message
I want to save int value to queue message and then get it on Azure Function QueueTrigger.我想将 int 值保存到队列消息中,然后在 Azure Function QueueTrigger 上获取它。
I save by the following way:我通过以下方式保存:
int deviceId = -1;
await queue.AddMessageAsync(new CloudQueueMessage(deviceId.ToString()));
and then listen queue:然后听队列:
public async Task Run(
[QueueTrigger("verizon-suspend-device", Connection = "StorageConnectionString")] string queueMessage,
ILogger log)
{
int deviceId = int.Parse(queueMessage);
but all messages are being moved to verizon-suspend-device-poison
queue.但所有消息都被移动到verizon-suspend-device-poison
队列。 What is wrong?怎么了?
It's an unfortunate limitation that Azure Function Queue Triggers currently require Base64-encoded messages .不幸的限制是Azure Function 队列触发器当前需要 Base64 编码的消息。 If you run your code against the storage emulator you should see an exception from your trigger like The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
如果您针对存储模拟器运行代码,您应该会从触发器中看到一个异常,例如The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
For now, at least (ie, until the trigger can handle binary/utf8 messages), queueing code has to place messages on the queues as Base64 strings.目前,至少(即,直到触发器可以处理二进制/utf8 消息),排队代码必须将消息作为 Base64 字符串放在队列中。 The queue trigger code for a string
message ends up here , and AsString
assumes a Base64 encoding . string
消息的队列触发代码到此结束, AsString
采用 Base64 编码。
For that (old) version of the storage SDK , you can send a Base64-encoded UTF-8 string representation of the integer:对于 存储 SDK 的那个(旧)版本,您可以发送 integer 的 Base64 编码 UTF-8 字符串表示:
var bytes = Encoding.UTF8.GetBytes(deviceId.ToString());
await queue.AddMessageAsync(new CloudQueueMessage(Convert.ToBase64String(bytes), isBase64Encoded: true));
With the new storage SDK , you would set MessageEncoding
on your QueueClient
to QueueMessageEncoding.Base64
and then just send the string representation of the integer (the new storage SDK will UTF-8 encode and then Base64-encode for you). With the new storage SDK , you would set MessageEncoding
on your QueueClient
to QueueMessageEncoding.Base64
and then just send the string representation of the integer (the new storage SDK will UTF-8 encode and then Base64-encode for you).
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.