gpt4 book ai didi

c# - ASP.NET + Rabbit MQ 连接和 channel 生命周期

转载 作者:行者123 更新时间:2023-11-30 17:30:51 27 4
gpt4 key购买 nike

我在 .NET(在 ASP.NET 或控制台应用程序中)中看到了很多使用 RabbitMq 的示例。他们中的大多数看起来像这样:

using (var connecttion = MyConnectionFactoryWrapper.CreateConnection())
using (var channel = connection.CreateChannel())
{
...
}

效率高吗?在 documentation我明白了:

AMQP connections are typically long-lived. AMQP is an application level protocol that uses TCP for reliable delivery.

所以我想应用程序最好有一个连接。关于 channel 的另一点:

AMQP 0-9-1 connections are multiplexed with channels that can be thought of as "lightweight connections that share a single TCP connection".

在这里,我想我可以在 ASP.NET 应用程序中使用 channel-per-request。我的问题:connection-per-applicationchannel-per-request 是最佳实践吗?

最佳答案

是的,connection-per-application 是一种建议的方法。 Channel-per-request 也应该这样做,但我会针对您所需的吞吐量对其进行测试。对于我们的项目,我们使用了 EasyNetQ它负责为您创建连接/ channel 。我们只为应用程序保留了一个 MessageBus 实例。

关于c# - ASP.NET + Rabbit MQ 连接和 channel 生命周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48987437/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com