Azure WebJob Queues are not triggering WebJobs If I pass message in binary format to Queues?
I have Pushed GOOGLE PROTOBUF Bytes as CloudMessage into the Azure Queue Storage. But, 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?
Following Code is my WebJob for pooling the Queue Message.
Program file:
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
}
}
Code for Adding Message Bytes into Azure Queue:
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);
}
My case is, I will add the message as Bytes in the Queue then That Queue Storage have to send a message and trigger my Web job which is published/running in the Azure Cloud.
I have a doubt about the below Method Signature.
public static void ProcessMessageQueue([QueueTrigger("messagequeue")] string message)
What datatype should I use for the message parameter in the above method signature since Messages are added into the Queue Storage Successfully but Queue does not trigger Azure function and all the Queue Messages are moved to Poison Queue.
What am I missing here?
Appreciate your thoughts on this.
Thanks in Advance!
Based on your code, I checked this issue. I passed the payload
as System.Text.UTF8Encoding.UTF8.GetBytes("hello world " + DateTime.Now)
, then I could retrieve the string parameter message
under my ProcessMessageQueue
function.
As How to trigger a function when a queue message is received states as follows:
Besides
string
, the parameter may be a byte array, aCloudQueueMessage
object, or a POCO that you define.
For the byte array or CloudQueueMessage
parameter, you could refer to the following code snippet:
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?
The WebJobs SDK would handle a function up to 5 times to process your queue message. The message would be moved to a poison queue, more details your could refer to the description under How to handle poison messages.
I assumed that you need to check the encoding format of your input. And you could check the logs under your azure storage, more details you could follow here. Moreover, you could also use try-catch-throw
within your ProcessMessageQueue
function to narrow this issue.