Azure Service Bus - describe logic - azure

I want to have the following logic for Service Bus queue:
only one message in queue (storing datetime)
if we try to add new message never than added to queue - reject it
Is it possible?

Related

Azure Function is not triggerd after putting a message to a queue in service bus

I have a queue in a service bus. After putting a message into a queue an azure logic app and an azure functions should betriggered and process the content.
My Azure logic app is triggered but my azure funcction is not triggered. My code for azure function:
[FunctionName("ReadMEssageFromQueue")]
public static void Run([ServiceBusTrigger("messagequeue", Connection = "AzureWebJobsStorage")]string myQueueItem, ILogger log)
{
log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
}
host json:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"AzureWebJobsStorage": "******" // connection string of my service bus
}
}
should I set something in service bus queue to send message to both ressources?
Azure Service Bus Queue messages are picked up by only one processor. So I think in your case, the logic app is picking up and consuming the message first and the message is not available for the function to process. You can try temporarily disabling the logic app and letting function pick the message to confirm this.
Ref: azure-service-bus-queue-with-multiple-listeners
You can trigger the Azure function from your logic app (not sure if it'll help your use case), or you can use Azure Service Bus topics as topics support the model where multiple consumers can subscribe to a topic.
The former option might be a better approach for you from cost perspective, as you'd need to use Standard tier of service bus in order to use topics feature, which means additional cost for you over your current setup.
Also, you might want to use some other name for service bus connection string as AzureWebJobsStorage is used for storage account connection string

Service Bus Queue Lock Token Expired Error in Azure Function App

I'm more used to Service Bus Queue but have challenges when using it with Azure Function App.
We have Azure Function App which reads data from Service Bus Queue through ServiceBugTrigger. Per this link, Azure Function App manage Queue message PeekLock internally (at the queue trigger and function execution end), we do not require to Complete() message at the end of the process.
My queue message lock duration is set to 3min (which is enough for my execution, I would say more than my requirement). I also applied other required parameters to treat message well like,
"serviceBus": {
"maxAutoRenewDuration": "00:05:00",
"maxConcurrentCalls": 10,
"prefetchCount": 0
}
I am getting LOCK DURATION EXPIRED error frequently with this implementation. Really no idea what's happening here, Any clue?
I am used to Service Bus Queue and aware with each parameter function. Also, have configured each parameter per requirement.
This happens when your maxAutoRenewDuration is more than the lock duration at servicebus side.
You should check the lock duration specified at Service bus queue side. Ensure it is greater or equal to maxAutoRenewDuration specified in your azure function
You can update it from portal or service bus explorer

Azure service bus dead letter queues

I am using azure service bus topic and subscription mechanism and want to process the messages which are all in the dead letter queue.
Moreover i want to process the messages via azure web job in C# and send them back to queue. So i want to know how I can process the messages on the deadletter queue through my application?
When a message is deadlettered it goes onto the dead letter queue for the subscription from which it was read. You access that just like you'd access the original subscription except that you append /$DeadLetterQueue to the subscription name.
Moreover i want to process the messages via azure web job in C# and send them back to queue.
As spodger pointed that the path of your deadletter subscription would be:
{topic-path}/Subscriptions/{subcription-name}/$DeadLetterQueue
You could use the WebJobs SDK for Service Bus and leverage the ServiceBusTrigger to access your dead letter queue message(s) as follows:
public void ProcessDeadletterQueue(
[ServiceBusTrigger("topicName", "subscriptionName/$DeadLetterQueue")] BrokeredMessage message)
{
//TODO:
}
For more details, you could refer to here.
When a message is dead-lettered from a Service Bus Entity(Queue or Topic Subscription), it will be moved to the dead-letter path of the same entity. The reason for dead-lettering will be available in the message's custom properties DeadLetterReason and DeadLetterErrorDescription.
In order to receive the dead-letter messages,
string path = Microsoft.ServiceBus.Messaging.SubscriptionClient.FormatDeadLetterPath(topicPath, subscriptionName);
var subscriptionClient = SubscriptionClient.CreateFromConnectionString(connectionString, path);
BrokeredMessage message = subscriptionClient.Receive();

Routing Event Hub messages to Azure funtion by message type

I've create an Azure Function to listen to an Azure IoT Hub instance. When I post message to the IoT Hub I set a property like so:
Message iotMessage = new Message([myMessage]);
iotMessage.Properties.Add("Type", [MessageType]);
At the Azure Function end I want the Azure function only to receive/process messages that have a Type property and where the Type property equals "MessageType1".
I cannot see a way to do this in an Azure function. Can someone advise if this is possible?
EDIT: this appears to be what you're looking for:
https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-csharp-csharp-process-d2c#add-a-queue-to-your-iot-hub-and-route-messages-to-it
Your condition would be Type=MessageType1 and you would have the function trigger off of the output queue.
What type of input binding are you using for your Azure Function?
AFAIK, this isn't currently possible in one step. However, there are a few options you have:
connect IoT Hub to a ServiceBus Topic/Subscription, which allows you to do some filtering based on properties. Trigger on the subscription which filters by MessageType1
have a function dedicated to filtering IoT Hub messages. When it matches a MessageType1 message, put that message into a queue. This queue triggers another function which only processes matched messages

Azure Service Bus - making sure the job is done

I send a message to ASB, some data (a long task) will start being processed, but the processing fails miserably (someone turns off the computer/out of memory/whatever). How should I handle this situation? Like putting the queue back on the bus? Do I need to create my own monitoring/requeueing unit?
Azure ServiceBus has an internal retry policy. If a message fails to deliver, it will be send back to the queue automatically.
When creating a queue or a topic/subscription you can specify the MaxDeliveryCount.
QueueDescription.MaxDeliveryCount
SubscriptionDescription.MaxDeliveryCount
Default value is 10. A message is automatically deadlettered after this number of deliveries.

Resources