spring-rabbit-1.4.xsd 解读,寻找提高性能的配置
1.connection-factory 以默认的方式创建一个rabbit的CachingConnectionFactory
<xsd:annotation> <xsd:documentation> <![CDATA[Creates a rabbit CachingConnectionFactory with sensible defaults. 以默认的方式创建一个rabbit的CachingConnectionFactory]]> </xsd:documentation> </xsd:annotation>
<xsd:complexType> connection-factory的复合类型,在其里面声明了connection-factory的所有的属性 id,host,port,addresses,username,password,virtual-host,channel-cache-size,connection-factory,executor,publisher-confirms,publisher-returns,requested-heartbeat,connection-timeout host:主机IP port:端口号 addresses:访问地址(主机IP+端口号) virtual-host:虚拟主机,通过虚拟主机名连接到mq。默认值的虚拟主机是“/”(与rabbitmq管理平台admin菜单下的virtual hosts对应 默认“/”)。每个虚拟主机都有自己单独的quene、exchange、user。 channel-cache-size:通道的最大缓存数量,超出的数量将不被缓存。 connection-factory:使用一个本地的rabbitmq的connection factory。在这里可以使用本地连接的一些特性,如:客户端属性。而其他的属性(主机IP 端口号)会被覆盖掉。 executor:使用线程池(ExecutorService或者ThreadPoolTaskExecutor 可以通过<task:executor>来定义)。在我们创建connection-factory连接的时候,把线程池传递给rabbit库。如果不设置这个属性,rabbit库会使用一个具有5个线程的ExecutorService线程池。 publisher-confirms:发布者确认模式,当这个值为true的时候,通道支持发布者确认。注意:一个具有事务的channel不能放入到确认模式,同样确认模式下的channel不能用事务。当broker确认了一个消息,会通知发布者消息被成功处理; publisher-returns: requested-heartbeat:检测对应的socket连接上数据的收发是否正常,如果一段时间内没有收发数据,则向对端发送一个心跳检测包,如果一段时间内没有回应则认为心跳超时,即认为对端可能异常crash了。 connection-timeout:连接超时时间 cache-mode:缓存模式,CHANNEL 和 CONNECTION ,若为CHANNEL,通道会被缓存在一个连接中,这也是默认的模式。若为CONNECTION,连接和通道都会被缓存起来。CONNECTION 可能更适合listener container。 connection-cache-size:连接缓存数量,这个属性需要与cache-mode为CHANNECTION模式联合使用。如果连接数超出了这个值,超出部分不会被缓存。2.listener-container 侦听器容器 侦听器容器中的每个侦听器是对应一个承载它容器,容器的配置由父元素决定。这些配置构建RabbMQ侦听器容器,来对指定的连接工厂进行操作。
<xsd:annotation> <xsd:documentation> <![CDATA[Each listener child element will be hosted by a container whose configuration is determined by this parent element. This variant builds RabbitMQ listener containers, operating against a specified ConnectionFactory.]]> </xsd:documentation> <xsd:appinfo> <tool:annotation> <tool:exports type="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer" /> </tool:annotation> </xsd:appinfo> </xsd:annotation>