Search code examples
pythonazure-functionsazureservicebus

Azure Function Python - serviceBusTrigger - How to deadletter a message


I have a plain simple Python function which should dead-letter a message if it does not match few constraint. Actually I'm raising an exception and everything works fine (I mean the message is being dead-lettered), but I would like to understand if there is a "clean" way to dead-letter the message without raising an exception.

async def function_handler(message: func.ServiceBusMessage, starter: str):
    for msg in [message]:
        client = df.DurableOrchestrationClient(starter)
        message_body = msg.get_body().decode("utf-8")

        msg = json.loads(message_body)

        if 'valid' in msg:    
           instance_id = await client.start_new('orchestrator', None, json.dumps(message_body))
        else:
           raise Exception(f'not found valid {msg["id"]}')

This is part of host.json, this should indicate I'm working with version 2.0 of Azure Functions

  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  },

Suggestions are welcome


Solution

  • At time of writing, in Python it is not possible interactively send a message in dead-letter.

    I found out that autocomplete=false is only supported for C#.

    This basically means that the only way to dead letter a message is raise an exception, just like I was doing in my code.

    Thanks to @GauravMantri to pointing me the right way (i.e. have a look at how to use the autocomplete configuration parameter).