【问题标题】:Spring integration channel message countSpring集成通道消息计数
【发布时间】:2013-02-25 03:28:02
【问题描述】:

我有 2 个问题。他们在这里:

  1. 有没有办法确定等待的消息数量 在弹簧集成通道中处理,而数量 客户不断增加?

  2. 在应用程序上下文中,我希望能够定义 x 个实例 x 和 y 都从通道 p 以编程方式消耗的 bean y 根据负载增加或减少消费者。

spring 2gx 中显示了一个示例,但它使用rabbitmq 来确定负载。

【问题讨论】:

    标签: spring integration


    【解决方案1】:
    • 对于 1),Spring 集成通道就像任何其他 bean 一样只是 bean。假设您使用的是标准可轮询通道,您可以按名称自动连接它,然后获取等待消息的数量:

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

    如果你愿意,你也可以通过 JMX 进行内省。

    • 对于 2)... 为此,您需要在对象池之上使用 AOP 代理,然后将代理连接到(我假设是)服务激活器。这些属性可以使用 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

    【讨论】:

      猜你喜欢
      • 2014-01-23
      • 2017-07-27
      • 1970-01-01
      • 2017-06-22
      • 2022-01-07
      • 1970-01-01
      • 2018-08-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多