使用 ServiceBusProcessor 时出错 - Azure.Messaging.ServiceBus SDK

Posted

技术标签:

【中文标题】使用 ServiceBusProcessor 时出错 - Azure.Messaging.ServiceBus SDK【英文标题】:Error while using ServiceBusProcessor - Azure.Messaging.ServiceBus SDK 【发布时间】:2022-01-17 18:26:01 【问题描述】:

在 StartProcessingAsync() 方法之后出现异常。调试指针指向“ProcessorErrorAsync”方法。我遵循了链接中提供的类似步骤 - https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample04_Processor.md 我在这里错过了一些步骤吗? 异常详情:error.Exception.Message:

Method not found: 'System.Threading.Tasks.Task`1<System.Collections.Generic.IEnumerable`1<Microsoft.Azure.Amqp.AmqpMessage>> Microsoft.Azure.Amqp.ReceivingAmqpLink.ReceiveMessagesAsync(Int32, System.TimeSpan, System.TimeSpan, System.Threading.CancellationToken)'.
private void ListenerBind(string key, ServiceBusProcessorOptions onMessageOptions)
        
            ServiceBusClient tempClient = this._cacheClient.Get(key);
            ServiceBusProcessor tempProcessor = tempClient.CreateProcessor(this._topicName, this._subscriptionName, onMessageOptions);
            try
            
                //temp.OnMessageAsync(this.MessageProcessCallBackAsync, onMessageOptions);
                tempProcessor.ProcessMessageAsync += MessageProcessCallBackAsync;
                tempProcessor.ProcessErrorAsync += ProcessErrorAsync;
                tempProcessor.StartProcessingAsync();
            
            catch (InvalidOperationException ex)
            
                this._logger.Log($"ex.Message", EventLevel.Informational);
            
            catch (Exception ex)
            
                this._logger.LogException(ex);
            
        
        private Task ProcessErrorAsync(ProcessErrorEventArgs error)
        
            Exception ex = new Exception(
                $" , Action error.ErrorSource, " +
                $" , Endpoint error.FullyQualifiedNamespace" +
                $",EntityPath error.EntityPath "
                , error.Exception);
            this._logger.LogException(ex);

            this._onErrorCallback(ex, string.Empty);

            return Task.CompletedTask;
        

【问题讨论】:

很高兴您的问题已得到解决。您可以接受并投票赞成答案,以便对可能面临相同问题的其他社区成员有所帮助。 【参考方案1】:

谢谢jsquire 和arunprakashn。发布您的建议作为帮助其他社区成员的答案。

原来在引用新的 Amqp nuget 时存在问题。我看到最新的 Azure.Amqp 是新服务总线 SDK 附带的依赖项,但仍然存在参考问题。我多次删除了 Amqp nuget 并重新添加,但这并没有解决问题。 “.nuspec”文件仍然引用旧版 SDK,当我评论它时,重新添加了新的 Azure.Messaging.Servicebus nuget,错误消失了。

对旧版 SDK 的行进行了注释,如下所示:
<group targetFramework=".NETFramework4.8">
        <dependency id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.0.0"/>
        <dependency id="Microsoft.Rest.ClientRuntime" version="2.2.0"/>
        <dependency id="Newtonsoft.Json" version="12.0.3"/>
        <dependency id="Ninject" version="3.3.4"/>
        <!--<dependency id="WindowsAzure.ServiceBus" version="5.1.0"/>-->
        <dependency id="Polly" version="7.1.0"/>
        <dependency id="RabbitMQ.Client" version="5.0.1"/>
        <dependency id="System.Diagnostics.DiagnosticSource" version="4.5.0"/>
        <dependency id="System.Diagnostics.TraceSource" version="4.3.0"/>
        <dependency id="System.Diagnostics.Tracing" version="4.3.0"/>
      </group>

可以参考GitHub issue:Error while using ServiceBusProcessor - Azure.Messaging.ServiceBus SDK

【讨论】:

以上是关于使用 ServiceBusProcessor 时出错 - Azure.Messaging.ServiceBus SDK的主要内容,如果未能解决你的问题,请参考以下文章

Azure.Messaging.ServiceBus:我应该在处置时从 ServiceBusProcessor 中删除 ProcessMessageAsync 处理程序吗?

运行 adb 命令时出现问题 / 使用平板设备进行开发时出现问题

使用 FolderBrowserDialog 时出现异常

使用串行插件时出现 Ionic Capacitor Android 错误 - 连接到外部设备时出现 Cordova_not_available

在 keras 中使用 EfficientNet 时出现 ResourceExhaustedError

使用 htdocs xampp 运行命令时出现以下错误