1. 程式人生 > 其它 >C# MVC RabbitMQ 連線提示 None of the specified endpoints were reachable

C# MVC RabbitMQ 連線提示 None of the specified endpoints were reachable

技術標籤:RabbitMQMVC.NETrabbitmqmvc.net

  • 在 VS 中使用 NuGet 將RabbitMQ.Client.5.2.0 程式包更新至 RabbitMQ.Client.6.2.1 版本後,程式連線 RabbitMQ 服務報 “None of the specified endpoints were reachable” 異常問題;

翻譯成中文大概的意思就是 “沒有指定的端點可訪問”;

  • 通過網上搜索了大部分重複的文章,大致都指向了RabbitMQ 許可權未配置問題;

當然許可權未配置也可能是其中之一

  • 這裡先是測試了相同的連線配置、放在另外的 Console 程式中 和 新建的 .NET4.8 MVC 程式中 都可以正常連線,只有在前面的 MVC 程式中會出現此異常;

說明這裡可以排除RabbitMQ 許可權未配置的可能

  • 最後經過各種排除法發現是因為 web.config 中缺少了System.Threading.Tasks.Extensions 的引用;

附原始碼:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

PS:雖然在程式引用中已經新增過 System.Threading.Tasks.Extensions 的引用項了,

但因為 RabbitMQ.Client 程式連線操作是在執行時才引用的System.Threading.Tasks.Extensions.dll、非編譯時,

所以必須在web.config 中新增 runtime繫結 System.Threading.Tasks.Extensions 引用項才行哦