簡體   English   中英

Spring集成通道消息數

[英]Spring integration channel message count

我有兩個問題。 他們來了:

  1. 有什么方法可以確定在Spring集成通道中等待處理的消息數量,同時客戶數量會隨着時間不斷增加?

  2. 在應用程序上下文中,我希望能夠定義bean y的x個實例,其中x和y都從通道p消耗,並根據負載以編程方式增加或減少消耗者。

在春季2gx中顯示了一個示例,但它使用rabbitmq來確定負載。

  • 對於1),Spring Integration通道就像其他任何bean一樣都是bean。 假設您使用的是標准可輪詢頻道,則可以按名稱自動將其連線,然后獲取等待的郵件數:

http://docs.spring.io/spring-integration/api/org/springframework/integration/channel/QueueChannel.html#getQueueSize()

如果需要,您也可以通過JMX進行內部檢查。

  • 對於2)...為此,您需要在對象池頂部使用AOP代理,然后將代理連接到(我假設是)Service Activator。 可以使用PropertyPlaceholderConfigurer將這些屬性外部化。 因此,例如:

     <bean id="propertyPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="systemPropertiesMode" value="2" /> <property name="locations" value="classpath:my_config_params.properties" /> </bean> <bean id="myBusinessObjectImpl" class="com.mycompany.whatever.impl.MyServiceImpl" scope="prototype" autowire-candidate="false" /> <bean id="myBusinessObjPool" class="org.springframework.aop.target.CommonsPoolTargetSource"> <property name="targetBeanName" value="myBusinessObjectImpl" /> <!-- THIS IS THE KEY. myconfig.params.poolsize is the name of the property in the my_config_params.properties above. --> <property name="maxSize" value="${myconfig.params.poolsize}" /> </bean> <bean id="myBusinessObject" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="targetSource" ref="myBusinessObjPool" /> </bean> <int:channel id="myInputChannel"> <int:queue size="500" /> </int:channel> <int:service-activator inputChannel="myInputChannel" ref="myBusinessObject" method="processMessages"> <int:poller max-messages-per-poll="10" fixed-rate="5000"/> </int:service> 

這也使您可以使服務激活程序成為有狀態的。 強制鏈接到對象池功能:

http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/aop-api.html#aop-ts-pool

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM