Since it’s going to be a send-only endpoint, it’s not going to be a “functions endpoint.” The overloading of the word endpoint here is unfortunate, but it’s more like you’re going to have a library sending messages as part of an HTTP API.
So, you’re not going to use any of the NServiceBus Functions libraries here at all. You’re just setting up a send-only endpoint in a curious hosting environment.
But…you can’t really use the .UseNServiceBus(…)
stuff either, because that’s an extension method on normal webapp hosting types, and this isn’t a normal webapp. Instead you have to do it the old-fashioned way.
Here’s what I mocked up:
[assembly: FunctionsStartup(typeof(Startup))]
class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.Add(new ServiceDescriptor(typeof(IMessageSession), provider =>
{
var cfg = new EndpointConfiguration("SendOnly");
cfg.SendOnly();
cfg.UseTransport<AzureServiceBusTransport>();
// set connection string, etc.
// Unfortunately, no async/await here
var endpoint = Endpoint.Start(cfg).GetAwaiter().GetResult();
return endpoint;
}, ServiceLifetime.Singleton));
}
}
Then you can make the HTTP function class non-static and use constructor injection to get your IMessageSession
.