Spring Batch& Spring Integration(JMS)&负载平衡从属

时间:2018-06-13 21:34:23

标签: spring spring-integration activemq spring-batch jmstemplate

我正在使用

  1. Spring Batch

    • 第1步
    • Step 2 Master(Partitioner)
    • 第3步
  2. Spring Integration(JMS)来传达Master和Slave

  3. 我们看到的问题是,第一个从设备处理所有JMS消息而不是从设备之间的均匀分配。

    参见下面的配置

    1. 主                                                                                                                                 

      <bean id="PreProcess" class="com.job.tasklet.PreProcessTasklet" scope="step">
          <constructor-arg index="0" value="${run.slave}"/>
          <property name="maxNumberOfSlaves" value="#{jobParameters['max-slave-count']}"/>
      </bean>
      
      <bean id="PostProcess" class="com.job.tasklet.PostProcessTasklet" scope="prototype">
          <constructor-arg index="0" ref="chpsJobDataSource"/>
      </bean>
      
      
      <bean id="partitioner" class="com.job.partition.DatabasePartitioner" scope="step">
          <constructor-arg index="3" value="${max.row.count}"/>
      </bean>
      
      <bean id="partitionHandler" class="com.job.handler.StepExecutionAggregatorHandler">
          <property name="stepName" value="processAutoHoldSlaveStep"/>
          <property name="gridSize" value="${grid.size}"/>
          <property name="replyChannel" ref="aggregatedGroupRuleReplyChannel"/>
          <property name="messagingOperations">
              <bean class="org.springframework.integration.core.MessagingTemplate">
                  <property name="defaultChannel" ref="groupRuleRequestsChannel"/>
              </bean>
          </property>
      </bean>
      

      <!-- Request Start -->
      <int:channel id="groupRuleRequestsChannel" />
      <int-jms:outbound-channel-adapter channel="groupRuleRequestsChannel" jms-template="jmsTemplateToSlave"/>
      
      <bean id="jmsTemplateToSlave" class="org.springframework.jms.core.JmsTemplate">
          <property name="connectionFactory" ref="connectionFactory"/>
          <property name="receiveTimeout" value="5000"/>
          <property name="defaultDestinationName" value="defaultRequest"/>
      </bean>
      
      <bean id="jmsTemplateFromSlave" class="org.springframework.jms.core.JmsTemplate" parent="jmsTemplateToSlave">
          <property name="defaultDestinationName" value="defaultRequest"/>
      </bean>
      
      
      <!-- Response Test Start -->
      <int:channel id="groupRuleReplyChannel">
          <!-- <int:queue/> -->
      </int:channel>
      
      <int-jms:inbound-channel-adapter channel="groupRuleReplyChannel" jms-template="jmsTemplateFromSlave">
          <int:poller id="defaultPoller" default="true" max-messages-per-poll="1" fixed-rate="3000"  />
      </int-jms:inbound-channel-adapter>
      
      <!-- define aggregatedReplyChannel -->
      <int:channel id="aggregatedGroupRuleReplyChannel">
          <int:queue/>
      </int:channel>
      
      <int:aggregator ref="partitionHandler"
                      input-channel="groupRuleReplyChannel"
                      output-channel="aggregatedGroupRuleReplyChannel"
                      send-timeout="3600000"/>
      
    2. <int:channel id="requestsChannel" />
      
      <bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
          <property name="brokerURL" value="${spring.activemq.broker-url}" />
          <property name="trustAllPackages" value="true" />
      </bean>
      
       <int-jms:message-driven-channel-adapter id="jmsIn" destination-name="#{args[0]}" channel="requestsChannel" connection-factory="connectionFactory" max-messages-per-task="1"/>
      
      <int:service-activator input-channel="requestsChannel" output-channel="replyChannel" ref="stepExecutionRequestHandler" />
      
      <int:channel id="replyChannel" />
      
      <int-jms:outbound-channel-adapter connection-factory="connectionFactory" destination-name="#{args[1]}" channel="replyChannel" />
      

                                                                                                                   

    3. 如果您遇到此问题,请提供建议。

      如果您需要更多信息,请与我们联系。

      注意:我已经在这里和谷歌进行了很多搜索但是还没有运气解决方案。

1 个答案:

答案 0 :(得分:1)

ActiveMQ默认使用1000的预取see here

换句话说,第一个(最多)1000个分区将转到第一个消费者等。

您可以减少预取; 1适用于此应用程序。