Starting a NServiceBus Endpoint in an Azure Function

azure function maxconcurrentcalls
servicebustrigger azure function v2
azure function message bus
azure function brokeredmessage
servicebus trigger azure function
azure function service bus trigger javascript
azure function service bus trigger batch
azure function service bus autocomplete

What I would like to do is just what the title says. Start a NServiceBus SendOnly endpoint within an Azure Function. I created a new Azure Functions project and added a new method. Within the method I tried creating an endpoint using the LearningTransport and using the AzureServiceBusTransport but anytime I try to start the endpoint an exception is thrown. I've tried the same code within an Azure Web App project and it worked fine so I'm wondering if there's something unique with Azure Functions.

public static void ServiceBus() 
    var endpointConfig = new EndpointConfiguration("EndpointName");

    var endpoint = Endpoint.Start(endpointConfig).Result;

The LearningTransport results in an exception with:

Couldn't find the solution directory for the learning transport.

Using the Azure transport with Forwarding Topology results with this exception:

Can't find any behaviors/connectors for the root context (NServiceBus.Pipeline.ITransportReceiveContext)

with a stack trace of:

at NServiceBus.PipelineModelBuilder.Build() at NServiceBus.StepRegistrationsCoordinator.BuildPipelineModelFor[TRootContext]() at NServiceBus.Pipeline`1..ctor(IBuilder builder, ReadOnlySettings settings, PipelineModifications pipelineModifications) at NServiceBus.StartableEndpoint.<Start>d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NServiceBus.Endpoint.<Start>d__1.MoveNext()

I've looked everywhere I can think of and haven't found anyone using NServiceBus within an Azure function only the Web Apps. Ideally The function class would have an endpoint it would open in the constructor and then the functions would process webhook information before sending it through the endpoint.

There is also a proof of concept of integration NServiceBus into Azure Functions now here:

Using NServiceBus in Azure Functions with Service Bus triggers , The Azure Functions SDK enforces certain constraints that are also applied to NServiceBus endpoints. Review these constraints before running  Azure Functions. Azure Functions can be used to run short-lived NServiceBus endpoints triggered by Azure Service Messages. When a message triggers a function, an NServiceBus endpoint can be started to handle the message. Starting an NServiceBus endpoint for each message adds considerable overhead.

Learning transport makes assumptions about file system. Make sure what you provide is valid for Functions.

As for using Learning transport - it will be emitting messages on the file system of the random machine you're using. Is that really what you're trying to do or you'd like to use a transport that would send out a message for your other endpoints to process? I'd think something like Azure Service Bus transport would be a better option.

Azure Samples • NServiceBus • Particular Docs, Azure Blob Storage Data Bus Cleanup with Azure Functions Using an Azure How to use the Azure Service Bus transport for a long-running process. Monitor Azure Service Bus endpoints with ServiceControl adapter Azure Blob Storage Data Bus Cleanup with Azure Functions Using an Azure Function instead of the built in blob cleanup capabilities. Azure Blob Storage DataBus Sending large attachments with NServiceBus over Azure blob storage. Azure Cloud Showcase Implements a fictional store utilizing several features of NServiceBus. Azure Service Bus Performance Tuning

I have a solution on Azure functions version 1 where I tried to put NServiceBus endpoint to use. I also got the same exception: Can't find any behaviors/connectors for the root context (NServiceBus.Pipeline.ITransportReceiveContext).

With Azure functions, NServiceBus does not seem to find the assemblies it needs. Thus the exception. Instructing NServiceBus to scan AppDomain assemblies removed the exception.

var endpointConfiguration = new EndpointConfiguration(endpointName);
var scanner = endpointConfiguration.AssemblyScanner();
scanner.ScanAppDomainAssemblies = true;

According to documentation, AppDomain assembly scanning option should be true by default, but at least in my case I had to set it explicitly. More info on the topic here:

Starting a NServiceBus Endpoint in an Azure Function, There is also a proof of concept of integration NServiceBus into Azure Functions now here: NServiceBus.Functions This is a sample project that demonstrates integration between self-hosted NServiceBus endpoint and an Azure function. In this setup the function plays a role of a handler for PingCommand s send from the Sender endpoint.

sfeldman.NET - Azure Functions, Start a NServiceBus SendOnly endpoint within an Azure Function. I created a new Azure Functions project and added a new method. NServiceBus helps create distributed .NET systems not only on premises but also in the Microsoft Azure cloud. It provides a variety of capabilities built for Microsoft Azure such as hosting, Azure specific transports, and persistence. Hosting. Hosting in Azure Cloud Services; Shared Hosting in Azure Cloud Services; Self-hosting

tmasternak/NServiceBus.Functions: NServiceBus trigger for , When Azure Functions were announced at the Build2016 conference, To start with Azure functions, you can either start at or through the portal. Now back to hosting NServiceBus endpoints. This can be used to self-host NServiceBus endpoint. NServiceBus takes out the manual and tedious work with low level queuing while allowing to dive into more complex scenarios for implementation. Not to mention the tooling that is available as a part of Particular Platform. Additional reasons are:

Building Messaging Endpoints in Azure: Functions, NServiceBus trigger for Azure Functions sample. integration between self-​hosted NServiceBus endpoint and an Azure function. It's tiggered via NServiceBusTrigger running on top of ASQ transport that passes the input POCO command. This executable can run on a development machine outside the context of a service runtime. It can also be used to debug an endpoint locally without starting the Azure emulator. This is done by adding the executable to the debug path in the project properties. Next, pack the build output as a zip file so that the NServiceBus. Hosting. Azure.

  • I was just providing additional information. Learning transport isn't what I intend to use within a production environment. I would like to use Azure transport which was the other option I provided that I was having issues with. That was returning an error regarding "ITransportReceiveContext" that I can't find any additional information on how to fix.
  • What version of NServiceBus bus are you using it with?
  • I've tried 6.4.3 and the latest 7.0.0 beta. I think there's an issue with Azure Functions. You're supposed to be able to chose between Framework and Core when creating an Azure Function project but it always seems to be running with Core. Even with the NSB 7.0.0 beta which is supposed to work with core it still fails to start the endpoint. I can get everything to work with Web Apps just not with Functions.
  • The current Azure Service Bus transport will not work on .NET Core. It has to be a Full framework.
  • Even the 7.0.0 libraries? Documentation reads that they support core. Alternatively is there a way to use .NET Framework for Azure Functions instead of using Core?