﻿# Custom Azure Functions triggers

<!-- Version variant: asbfunctionsworker_6; default: [/nservicebus/hosting/azure-functions-service-bus/custom-triggers.md](/nservicebus/hosting/azure-functions-service-bus/custom-triggers.md) -->


If the trigger function must be customized, you must disable generation of the trigger function by removing the `NServiceBusTriggerFunction` attribute. A custom trigger function can then be added manually to the project:

<!-- snippet: custom-trigger-definition -->

```cs
class CustomTriggerDefinition
{
    IFunctionEndpoint functionEndpoint;

    public CustomTriggerDefinition(IFunctionEndpoint functionEndpoint)
    {
        this.functionEndpoint = functionEndpoint;
    }

    [Function("MyCustomTrigger")]
    public async Task Run(
        [ServiceBusTrigger("MyFunctionsEndpoint")]
        ServiceBusReceivedMessage message, ServiceBusMessageActions messageActions, FunctionContext context,
        CancellationToken cancellationToken = default)
    {
        await functionEndpoint.Process(message, messageActions, context, cancellationToken);
    }
}

public class Program
{
    public async Task Main()
    {
        var host = new HostBuilder()
            .ConfigureFunctionsWorkerDefaults()
            .UseNServiceBus("MyFunctionsEndpoint")
            .Build();

        await host.RunAsync();
    }
}
```

<!-- endsnippet -->

The endpoint name in `UseNServiceBus` must match the queue name in the function, as illustrated above.

