Reputation: 87
Is there any way I can debug a queuetrigger without the multiple threading? I got several messages in the queue and my program keeps junping back and forth everytime I press contitnue or press forward, it makes it very hard to keep track of things.
I've tried to add IsBatched = false
as run parameter and changing the host file to have "maxConcurrentCalls": 1
but nothing works. I'm using Visual Studio
[Function("ProcessSensorWarningMessages")]
public void Run(
[ServiceBusTrigger("sensor_warningmessagedata", Connection = "ServiceBus-ConnetionString",IsBatched = false)]
ServiceBusReceivedMessage message,
ServiceBusMessageActions messageActions)
{
try
{
_logger.LogInformation("Message ID: {id}", message.MessageId);
_logger.LogInformation("Message Body: {body}", message.Body);
_logger.LogInformation("Message Content-Type: {contentType}", message.ContentType);
SmsServiceTemp smsService = new SmsServiceTemp(_logger);
EmailServiceTemp emailService = new EmailServiceTemp(_logger);
EnviromentVariables.EnviromentConfig(_logger);// fix so program crashes if null
string messageBody = message.Body.ToString(); // change program to use mesage body i dont need controller class here
SensorDatabaseQueryTemp sensorDatabaseQueryTemp = new SensorDatabaseQueryTemp(_logger);
SensorDatabaseQueryLastSeen sensorDatabaseQueryLastSeen = new SensorDatabaseQueryLastSeen(_logger);
SensorDataQueueModel queueData = JsonSerializer.Deserialize<SensorDataQueueModel>(messageBody);
if (queueData.TempId > 0)
{
JoinedSensorDataTemp temp = sensorDatabaseQueryTemp.GetJoinedSensorData(queueData.TempId);
SmsEmailHelperTemp.Warningloop(temp, _logger);
_logger.LogInformation("Successfully sendt Warning");
messageActions.CompleteMessageAsync(message);
}
else if (queueData.LastSeenId > 0)
{
JoinedSensorDataTemp lastSeen = sensorDatabaseQueryLastSeen.GetJoinedSensorData(queueData.LastSeenId);
SmsEmailHelperLastSeen.Warningloop(lastSeen, _logger);
_logger.LogInformation("Successfully sendt Warning");
messageActions.CompleteMessageAsync(message);
}
else
{
//null exception
}
}
catch (JsonException ex)
{
_logger.LogError(ex, "Error deserializing message body.");
messageActions.DeadLetterMessageAsync(message);
}
// Complete the message
}
Upvotes: 1
Views: 69
Reputation: 11113
Debugging with single thread Azure QueueTrigger. Is there any way I can debug a queuetrigger without the multiple threading?
Below code and configuration settings works for me and I followedMicrosoft-Document and SO-Thread:
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_INPROC_NET8_ENABLED": "1",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"AzureFunctionsJobHost__extensions__serviceBus__messageHandlerOptions__maxConcurrentCalls": "1",
"rithcon": "Endpoint=sb://rith02.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=o+25LyrithwikBCHtucjOrithwikhA="
}
}
Fuction.cs:
using System.Threading.Tasks;
using Azure.Messaging.ServiceBus;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.ServiceBus;
using Microsoft.Extensions.Logging;
namespace RithApp
{
public class Function1
{
[FunctionName("Function1")]
public async Task Run(
[ServiceBusTrigger("rithq", Connection = "rithcon", IsSessionsEnabled = false)] ServiceBusReceivedMessage rith, ServiceBusMessageActions messageActions, ILogger ri_lg)
{
ri_lg.LogInformation($"Hello Rithwik, Message is: {rith.Body}");
var messageBody = rith.Body.ToString();
await messageActions.CompleteMessageAsync(rith);
ri_lg.LogInformation("Message has been processed Rithwik.");
}
}
}
host.json:
{
"version": "2.0",
"extensions": {
"serviceBus": {
"messageHandlerOptions": {
"maxConcurrentCalls": 1,
"autoComplete": false
}
}
},
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
},
"enableLiveMetricsFilters": true
}
}
}
Output:
Upvotes: 0