在Azure函数中启动NServiceBus端点



我想做的就是标题所说的。在Azure函数中启动NServiceBus sendonly端点。我创建了一个新的Azure功能项目,并添加了一种新方法。在方法中,我尝试使用LearningTransport并使用AzureserviceBustransport创建端点,但是每当我尝试启动端点时,就会引发异常。我在Azure Web应用程序项目中尝试了相同的代码,并且它运行良好,所以我想知道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 Transport,此例外:

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的人。理想情况下,功能类将具有端点,它将在构造函数中打开,然后在通过端点发送之前,函数将处理Webhook信息。

现在在此处也有一个集成概念的概念证明:

现在:

https://github.com/tmasternak/nservicebus.functions

学习传输对文件系统做出假设。确保您提供的功能对功能有效。

对于使用学习传输 - 它将在您使用的随机机器的文件系统上发出消息。这真的是您要做的事情,还是您想使用可以向其他端点发送消息的传输?我认为像Azure Service Bus Transport这样的事情将是一个更好的选择。

我在Azure函数版本1上有一个解决方案,我试图将nservicebus端点放置。我也有同样的例外:找不到根上下文的任何行为/连接器(nservicebus.pipeline.itransportorteceivecontext(。。

使用Azure函数,NserviceBus似乎找不到所需的组件。因此例外。指示nservicebus扫描AppDomain组件删除了例外。

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

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

最新更新