Azure WebJob 队列不触发 WebJobs
Azure WebJob Queues are not triggering WebJobs
如果我将二进制格式的消息传递给队列,Azure WebJob 队列不会触发 WebJobs?
我已将 GOOGLE PROTOBUF 字节作为 CloudMessage 推送到 Azure 队列存储中。但是,Azure 队列存储没有 ping 并将 CloudMessage 传递到我的 Azure Continuous 运行 WebJob 而不是那些消息正在移动到 Poison 队列?
以下代码是我用于汇集队列消息的 WebJob。
程序文件:
public class Program
{
// Please set the following connection strings in app.config for this WebJob to run:
// AzureWebJobsDashboard and AzureWebJobsStorage
public static void Main()
{
try
{
JobHost host = new JobHost();
//Following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
catch (Exception ex)
{
throw ex;
}
}
}
Function.cs
public class Function
{
//This function will get triggered/Executed when new message is written on an Azure Queue called messagequeue
public static void ProcessMessageQueue([QueueTrigger("messagequeue")] string message)
{
#region WebAPI Call
#endregion
}
}
将消息字节添加到 Azure 队列的代码:
private void PushPayloadBytesToAzureQueueStorage(byte[] payload)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["AzureWebJobsStorage"]);
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
CloudQueue queue = queueClient.GetQueueReference("messagequeue");
queue.CreateIfNotExists();
CloudQueueMessage msg = new CloudQueueMessage(payload);
queue.AddMessage(msg);
}
我的情况是,我会将消息作为字节添加到队列中,然后队列存储必须发送消息并触发我的 Web 作业,即 published/running在 Azure 云中。
我对下面的方法签名有疑问。
public static void ProcessMessageQueue([QueueTrigger("messagequeue")] string message)
我应该为上述方法签名中的message参数使用什么数据类型,因为消息已成功添加到队列存储中,但队列不会触发 Azure 功能和所有队列消息被移动到毒队列。
我在这里错过了什么?
感谢您对此的看法。
提前致谢!
根据你的代码,我检查了这个问题。我将 payload
作为 System.Text.UTF8Encoding.UTF8.GetBytes("hello world " + DateTime.Now)
传递,然后我可以在我的 ProcessMessageQueue
函数下检索字符串参数 message
。
As How to trigger a function when a queue message is received 状态如下:
Besides string
, the parameter may be a byte array, a CloudQueueMessage
object, or a POCO that you define.
字节数组或者CloudQueueMessage
参数,可以参考下面的代码片段:
System.Text.UTF8Encoding.UTF8.GetString(message); //for byte array
System.Text.UTF8Encoding.UTF8.GetString(message.AsBytes); //for CloudQueueMessage object
Azure Queue storage is not pinging and Passing that CloudMessage to my Azure Continuous running WebJob instead of that, those Messages are moving to the Poison Queues?
WebJobs SDK 最多会处理一个函数 5 次来处理您的队列消息。该消息将被移至毒队列,更多详细信息您可以参考 How to handle poison messages.
下的描述
我假设您需要检查输入的编码格式。你可以查看你的 azure 存储下的日志,更多细节你可以关注 here。此外,您还可以在 ProcessMessageQueue
函数中使用 try-catch-throw
来缩小此问题的范围。
如果我将二进制格式的消息传递给队列,Azure WebJob 队列不会触发 WebJobs?
我已将 GOOGLE PROTOBUF 字节作为 CloudMessage 推送到 Azure 队列存储中。但是,Azure 队列存储没有 ping 并将 CloudMessage 传递到我的 Azure Continuous 运行 WebJob 而不是那些消息正在移动到 Poison 队列?
以下代码是我用于汇集队列消息的 WebJob。
程序文件:
public class Program
{
// Please set the following connection strings in app.config for this WebJob to run:
// AzureWebJobsDashboard and AzureWebJobsStorage
public static void Main()
{
try
{
JobHost host = new JobHost();
//Following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
catch (Exception ex)
{
throw ex;
}
}
}
Function.cs
public class Function
{
//This function will get triggered/Executed when new message is written on an Azure Queue called messagequeue
public static void ProcessMessageQueue([QueueTrigger("messagequeue")] string message)
{
#region WebAPI Call
#endregion
}
}
将消息字节添加到 Azure 队列的代码:
private void PushPayloadBytesToAzureQueueStorage(byte[] payload)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["AzureWebJobsStorage"]);
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
CloudQueue queue = queueClient.GetQueueReference("messagequeue");
queue.CreateIfNotExists();
CloudQueueMessage msg = new CloudQueueMessage(payload);
queue.AddMessage(msg);
}
我的情况是,我会将消息作为字节添加到队列中,然后队列存储必须发送消息并触发我的 Web 作业,即 published/running在 Azure 云中。
我对下面的方法签名有疑问。
public static void ProcessMessageQueue([QueueTrigger("messagequeue")] string message)
我应该为上述方法签名中的message参数使用什么数据类型,因为消息已成功添加到队列存储中,但队列不会触发 Azure 功能和所有队列消息被移动到毒队列。
我在这里错过了什么?
感谢您对此的看法。
提前致谢!
根据你的代码,我检查了这个问题。我将 payload
作为 System.Text.UTF8Encoding.UTF8.GetBytes("hello world " + DateTime.Now)
传递,然后我可以在我的 ProcessMessageQueue
函数下检索字符串参数 message
。
As How to trigger a function when a queue message is received 状态如下:
Besides
string
, the parameter may be a byte array, aCloudQueueMessage
object, or a POCO that you define.
字节数组或者CloudQueueMessage
参数,可以参考下面的代码片段:
System.Text.UTF8Encoding.UTF8.GetString(message); //for byte array
System.Text.UTF8Encoding.UTF8.GetString(message.AsBytes); //for CloudQueueMessage object
Azure Queue storage is not pinging and Passing that CloudMessage to my Azure Continuous running WebJob instead of that, those Messages are moving to the Poison Queues?
WebJobs SDK 最多会处理一个函数 5 次来处理您的队列消息。该消息将被移至毒队列,更多详细信息您可以参考 How to handle poison messages.
下的描述我假设您需要检查输入的编码格式。你可以查看你的 azure 存储下的日志,更多细节你可以关注 here。此外,您还可以在 ProcessMessageQueue
函数中使用 try-catch-throw
来缩小此问题的范围。