Smeghead Sev
Smeghead Sev

Reputation: 439

Starting a NServiceBus Endpoint in an Azure Function

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");
    endpointConfig.SendOnly();
    endpointConfig.UsePersistence<LearningPersistence>();
    endpointConfig.UseTransport<LearningTransport>();

    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.

Upvotes: 0

Views: 1076

Answers (3)

Udi Dahan
Udi Dahan

Reputation: 12057

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

https://github.com/tmasternak/NServiceBus.Functions

Upvotes: 1

Yuhis
Yuhis

Reputation: 542

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: https://docs.particular.net/nservicebus/hosting/assembly-scanning

Upvotes: 0

Sean Feldman
Sean Feldman

Reputation: 25994

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.

Upvotes: 0

Related Questions