在Azure函数中启动NServiceBus端点

时间:2018-02-14 15:03:55

标签: azure nservicebus azure-functions azureservicebus

我想做的就是标题所说的内容。在Azure功能中启动NServiceBus SendOnly端点。我创建了一个新的Azure Functions项目并添加了一个新方法。在该方法中,我尝试使用LearningTransport创建端点并使用AzureServiceBusTransport,但是当我尝试启动端点时,会抛出异常。我在Azure Web App项目中尝试了相同的代码并且工作正常,因此我想知道Azure功能是否有独特之处。

public static void ServiceBus() 
{
    var endpointConfig = new EndpointConfiguration("EndpointName");
    endpointConfig.SendOnly();
    endpointConfig.UsePersistence<LearningPersistence>();
    endpointConfig.UseTransport<LearningTransport>();

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

LearningTransport导致例外:

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

使用带有转发拓扑的Azure传输结果具有以下异常:

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

堆栈跟踪:

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()

我看到了我能想到的所有地方,并且没有发现任何人在Azure功能中使用NServiceBus只有Web应用程序。理想情况下,函数类将有一个它将在构造函数中打开的端点,然后函数将在通过端点发送webhook信息之前对其进行处理。

3 个答案:

答案 0 :(得分:1)

现在这里还提供了将NServiceBus集成到Azure Functions中的概念证明:

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

答案 1 :(得分:0)

学习传输对文件系统做出假设。确保you provide对函数有效。

至于使用学习传输 - 它将在您正在使用的随机机器的文件系统上发出消息。这真的是您尝试做的事情,或者您是否希望使用能够为其他端点发送消息的传输进行处理?我认为像Azure Service Bus transport之类的东西会是更好的选择。

答案 2 :(得分:0)

我在Azure功能版本1上有一个解决方案,我尝试使用NServiceBus端点。我也遇到了同样的异常:无法找到根上下文的任何行为/连接器(NServiceBus.Pipeline.ITransportReceiveContext)

使用Azure功能,NServiceBus似乎找不到它需要的程序集。因此例外。指示NServiceBus扫描AppDomain程序集删除了异常。

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

根据文档,默认情况下AppDomain程序集扫描选项应为true,但至少在我的情况下我必须明确设置它。 有关此主题的更多信息,请访问:https://docs.particular.net/nservicebus/hosting/assembly-scanning