question

MarijndenHaan avatar image
0 Votes"
MarijndenHaan asked MayankBargali-MSFT edited

Isolated Function handling Service Bus output binding messages on fail

Using Isolated Function, with a Service Bus trigger and a Service Bus output binding.

I have been trying to find the answer to whether there is a possibility that the incoming message fails (and will be retried) but the outgoing message is already send.
Which result in duplications in the output queue. I don't know where in the process 'output-binding-return-values' are being handled.


For Service Bus there is transaction scope to make sure both, completion of incoming message and sending outgoing message, are successful. But in the context of Isolated Function it is not possible to implement that.
And sure, Service Bus duplicate detection can catch the duplicates, but I would like to know which scenarios can cause the duplicates.

azure-functionsazure-service-bus
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I just realized that the "solution" of using Service Bus duplicate detection is not possible with Isolated Functions. Duplicate detection is based on MessageId, which can't be set until Isolated Function supports messaging-specific types.

0 Votes 0 ·

1 Answer

MughundhanRaveendran-MSFT avatar image
0 Votes"
MughundhanRaveendran-MSFT answered MayankBargali-MSFT commented

@MarijndenHaan ,

Thanks for reaching out to Q&A.

As you have mentioned, the message metadata ( messaging-specific types) is not yet supported in the Isolated function and is only available with in-process functions. So for a Isolated process, I would suggest you to continue using the duplicate detection enabled service bus queue and pass a custom message id to the message.

Sample JSON message:
{
"Id": "69da1afa-a61a-4a8e-921d-ad8263679d4c",
"Message": "Test message",
"CreatedDate": "2022-02-15T18:14:24.8770000+07:00"
}

The message id can be retrieved by the function app by reading the string message (myQueueItem in below example)


public static void Run([ServiceBusTrigger("session-queue", Connection = "constring")] string myQueueItem, FunctionContext context)
{

         var logger = context.GetLogger("Function1");
            
         logger.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");

         //split the message id 

         string[] s=myQueueItem.Split(',');
         logger.LogInformation(s[0]);

         //your logic based on message id
     }

I hope this helps!

Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.



· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MarijndenHaan ,

Following up to see if the above answer helps. Do let us know if you have any queries.

Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

0 Votes 0 ·

Thank you for replying. Your suggesting to use duplicate detection does not work, as I mentioned in my comment.. Your 'Id' is not the MessageId, as in meta data of the message, being used by ServiceBus. It's just part of the body.

Besides that, my question is "Where in the process are 'output-binding-return-values' being handled.". Is it before completing the trigger-binding, or after? What happens in between?
I want to know what the chances are duplicates are created due to failure.

0 Votes 0 ·

@MarijndenHaan Apology for delay in reaching out.

Yes, your understanding is correct as per the document here as Isolated function Output binding types only supported Simple types, JSON serializable types, and arrays and currently it doesn’t support BrokeredMessage so it is not possible to set the message ID on the output binding that can help with the duplicate message deduction in case customer have enabled the duplicate deduction on the service bus entity (topic/subscription).

The workaround would be leveraging the service bus SDK directly (not using function output binding) where you can set MessageId directly. As described here there is a chance to have on error on sending messages to Sevic Bus

"Where in the process are 'output-binding-return-values' being handled.". Is it before completing the trigger-binding, or after? What happens in between?
Sending output messages (in output binding) is part of a function execution. When an error occurs during sending outputs or any unhandled exception in function code the function execution will be marked as failed and the message will be visible again for the consumer to be consumed. The function will mark the message as complete if there was no unhandled exception and all function outputs executed without errors.

<<1/2>>

0 Votes 0 ·

@MarijndenHaan In nutshell, only once service bus trigger function executes successfully (no error in output bindings or custom code) then the message will be marked as completed at the service bus end.
In case there is issue with output binding then the message will be again consumed so you should not see duplicate messages to the output entity. But in scenario where the message was consumed Mutiple times and exceeds the maximum delivery count at the service bus end then the message will be moved to dead letter queue in case if you have configured it at the service bus end.

Hope the above helps and feel free to get back to me if you have any questions or concerns.

<<2/2>>

0 Votes 0 ·
MarijndenHaan avatar image MarijndenHaan MayankBargali-MSFT ·

@MayankBargali-MSFT Thank you for your reply, it clarifies a lot.

It's clear to me that if a output binding fails, the function execution fails and the message will be consumed again. Which is great.

Correct me if I'm wrong but with your answer I'm still not sure if it's possible that an output binding succeed but some other exception occurs after it, which makes the function execution fail. In this scenario the issue is not with the output binding but whatever happens after. Message to the output entity has been send but because of function fail, the (input) message will be consumed again, causing duplicate messages to the output entity.

Maybe it's not possible or the changes are very slim, either way I would love to know about it.

0 Votes 0 ·
Show more comments