问题描述
我有这个队列触发器
.预期是当我在 Queue
中插入消息时,触发器必须触发并处理出队的消息.
[FunctionName("NewPayrollQueueTrigger")]公共异步静态无效运行([QueueTrigger(myqueue",连接="AzureWebJobsStorage")]string myQueueItem,[DurableClient] IDurableOrchestrationClient 启动器,ILogger 日志){log.LogInformation($"C# 队列触发函数处理:{myQueueItem}");await starter.StartNewAsync("NewPayrollOrchestrator", input: myQueueItem);}
触发器正在正常激活,但正在发生这种奇怪的行为.该函数显然期望 message
以 Base-64
编码.
异常绑定参数'myQueueItem' <--- 输入不是有效的 Base-64 字符串,因为它包含一个非 base 64 字符,多于两个填充字符,或填充中的非法字符字符.
我正在使用来自 Azure.Storage.Queues
的 Azure Queue
库 v.12 中的此方法向队列发送消息,但没有发现对消息进行编码的重载Base-64
.请注意,_queue
是
实现此功能的唯一方法是,如果我使用 Azure 存储资源管理器
选择通过 UI 对消息进行编码,手动将消息发送到队列.
作为替代方案,您可以通过使用 QueueClientOptions
创建客户端,利用内置功能将消息转换为 Base64MessageEncoding
设置为 QueueMessageEncoding.Base64
.
例如:
_queue = new QueueClient(connectionString, queueName, new QueueClientOptions{MessageEncoding = QueueMessageEncoding.Base64});...var message = "一些消息";等待_queue.SendMessageAsync(消息);//将转换为 Base64.
I have this Queue Trigger
. The expected is when I insert a message in the Queue
, the trigger must fire and process the dequeued message.
[FunctionName("NewPayrollQueueTrigger")]
public async static void Run([QueueTrigger("myqueue", Connection =
"AzureWebJobsStorage")]string myQueueItem,
[DurableClient] IDurableOrchestrationClient starter,
ILogger log)
{
log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
await starter.StartNewAsync("NewPayrollOrchestrator", input: myQueueItem);
}
The trigger is being activated normally, but this weird behavior is happening. The function apparently expects that the message
is encoded in Base-64
.
Exception binding parameter 'myQueueItem' <--- 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.
I'm sending messages to the queue using this method from the Azure Queue
library v.12 from Azure.Storage.Queues
and found no overloads that encodes the message to Base-64
.
Note that _queue
is a QueueClient
instance.
public async Task<Response<SendReceipt>> SendAsync(string message)
{
return await _queue.SendMessageAsync(message);
}
So I tried to encode the message by myself...
public async Task<Response<SendReceipt>> SendAsBase64Async(string message)
{
byte[] buffer = Encoding.Unicode.GetBytes(message);
string msg = Convert.ToBase64String(buffer);
return await _queue.SendMessageAsync(msg);
}
... and it doesn't work either. Here's my code passing by that part but throwing error further on, indicating that it could get the message but it was not decoded correctly, since it was a filename of an existing blob in a storage:
The only way to get this working is if I manually send a message to the queue using the Azure Storage Explorer
choosing for encode the message via UI.
As an alternative, you can take advantage of the built in functionality for converting the message to Base64 by creating the client with an QueueClientOptions
with MessageEncoding
set to QueueMessageEncoding.Base64
.
For example:
_queue = new QueueClient(connectionString, queueName, new QueueClientOptions
{
MessageEncoding = QueueMessageEncoding.Base64
});
...
var message = "some message";
await _queue.SendMessageAsync(message); // Will be converted as Base64.
这篇关于Azure Functions:队列触发器需要 Base-64 消息,但未正确处理它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!