Azure功能:队列触发器期望使用Base-64消息,并且无法正确处理它们 [英] Azure Functions: Queue Trigger is expecting Base-64 messages and doesn't process them correctly

查看:56
本文介绍了Azure功能:队列触发器期望使用Base-64消息,并且无法正确处理它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个队列触发器.预期是当我在 Queue 中插入一条消息时,触发器必须触发并处理出队消息.

  [FunctionName("NewPayrollQueueTrigger")]公共异步静态void Run([[QueueTrigger("myqueue",Connection =" AzureWebJobsStorage")]字符串myQueueItem,[DurableClient] IDurableOrchestrationClient启动器,ILogger日志){log.LogInformation($已处理的C#队列触发函数:{myQueueItem}"));等待starter.StartNewAsync("NewPayrollOrchestrator",输入:myQueueItem);} 

触发器正常被激活,但是这种奇怪的行为正在发生.该函数显然期望 message Base-64 编码.

异常绑定参数'myQueueItem'< ---输入不是有效的Base-64字符串,因为它包含非base 64字符,且大于两个填充字符,或填充中的非法字符字符.

我正在使用 Azure.Storage.Queues Azure Queue 库v.12中的此方法将消息发送到队列,没有发现对消息进行编码的重载到 Base-64 .请注意, _queue

唯一可行的方法是使用 Azure Storage Explorer 选择通过UI对消息进行编码的方式,将消息手动发送到队列.

解决方案

作为替代方案,您可以通过使用 QueueClientOptions 创建客户端,利用内置功能将消息转换为Base64.将 MessageEncoding 设置为 QueueMessageEncoding.Base64 .

例如:

  _queue = new QueueClient(connectionString,queueName,new QueueClientOptions{MessageEncoding = QueueMessageEncoding.Base64});...var message =某条消息";等待_queue.SendMessageAsync(message);//将转换为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 Explorerchoosing 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功能:队列触发器期望使用Base-64消息,并且无法正确处理它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆