channel rabbitmq 配置"/>
channel rabbitmq 配置
java NIO是IO的多路复用,Channel连接是TCP的多路复用。那么他们有什么关系呢?
NIO是服务器开启一个线程,在内核中使用select()进行轮询管理一些socket,当socket数据准备好时,会通知应用程序进行读写请求。系统之间那点事-NIO(内附IO模型)-IO/NIO/AIO到底是什么。服务器看起来就好像是一个socket在通信,实现了多路复用。
channel复用TCP连接,是为了避免TCP连接创建和销毁的性能损耗,而多个channel使用一个tcp连接。
1. rabbitmq的connection连接池
RabbitMQ.png
我们看到一个Connection里面可以包含多个channel。那么我们在连接broker时,connection和channel的关系是什么?
1.1 问题提出
1.1.1 Connection对象管理以及性能
Connection连接本质上就是TCP连接,系统之间那点事-问题驱动-TCP的连接和关闭是比较耗费时间的。我们可以使用一个单例的Connection对象创建多个Channel来实现数据传输,但是在channel信息比较大的情况下,Connection带宽会限制消息的传输。那么需要设计Connection池,将流量分摊到不同的connection上。
1.1.2 Channel对象管理以及性能
Channel对象的创建和销毁也是非常耗时的,推荐共享使用Channel,而不是每次都创建和销毁Channel。那如何设计一个channel线程池呢?
1.2 官网解读
官网对于Connection的解读:
AMQP 0-9-1 connections are typically long-lived. AMQP 0-9-1 is an application level protocol that uses TCP for reliable delivery. Connections use authentication and can be protected using TLS. When an application no longer needs to be connected to the server, it should gracefully close its AMQP 0-9-1 connection instead of abruptly closing the underlying TCP connection.
大概意思就是:AMQP 0-9-1一般是一个TCP的长链接,当应用程序不再需要连接到服务器时,应该正常关闭AMQP 0-9-1连接而不是关闭TCP连接。
官网对于Channel的解读:
Some applications need multiple connections to the broker. However, it is undesirable to keep many TCP connections open at the same time because doing so consumes system resources and makes it more difficult to configure firewalls. AMQP 0-9-1 connections are multiplexed withchannels that can be thought of as "lightweight connections that share a single TCP connection".
Every protocol operation performed by a client happens on a channel. Communication on a particular channel is completely separate from communication on another channel, therefore every protocol method also carries a channel ID (a.k.a. channel number), an integer that both the broker and cli
更多推荐
channel rabbitmq 配置
发布评论