spring Batch取 ActiveMq Queues 每次只能取出一条,怎样才能一次取多条?
想从mq 队列上一次取得多个消息,但是目前这样配置每次只能读取一个, 十秒后下一个轮才能读第二个。请问应该怎么改才能一次读取多个?
job xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task" xmlns:batch="http://www.springframework.org/schema/batch" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-3.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd"> <context:component-scan base-package="com.zsyl" /> <import resource="applicationContext.xml" /> <!-- <import resource="datasource-config.xml" /> --> <!-- A destination in ActiveMQ --> <!-- class="org.apache.activemq.command.ActiveMQQueue"> --> <bean class="org.apache.activemq.ActiveMQConnectionFactory" id="mqfactory"> <property name="brokerURL" value="tcp://192.168.1.4:61616"></property> <property name="useAsyncSend"> <value>true</value> </property> <property name="redeliveryPolicy"> <bean class="org.apache.activemq.RedeliveryPolicy"> <property name="maximumRedeliveries" value="0"></property> </bean> </property> </bean> <bean id="destination" class="org.apache.activemq.command.ActiveMQQueue"> <constructor-arg value="enroll" /> </bean> <bean id="destination2" class="org.apache.activemq.command.ActiveMQQueue"> <constructor-arg value="enrollMq" /> </bean> <bean class="org.springframework.jms.core.JmsTemplate" id="jmsTemplate"> <property name="connectionFactory" ref="mqfactory" /> <property name="messageConverter"> <bean class="org.springframework.jms.support.converter.SimpleMessageConverter"></bean> </property> <property name="defaultDestination" ref="destination" /> <property name="receiveTimeout" value="10" /> <property name="sessionTransacted" value="true" /> <property name="sessionAcknowledgeModeName" value="CLIENT_ACKNOWLEDGE" /> </bean> <bean class="org.springframework.jms.core.JmsTemplate" id="jmsTemplate2"> <property name="connectionFactory" ref="mqfactory" /> <property name="messageConverter"> <bean class="org.springframework.jms.support.converter.SimpleMessageConverter"></bean> </property> <property name="defaultDestination" ref="destination2" /> <property name="receiveTimeout" value="10" /> <property name="sessionTransacted" value="true" /> <property name="sessionAcknowledgeModeName" value="CLIENT_ACKNOWLEDGE" /> </bean> <bean id="jmsreader" class="com.zsyl.batch.reader.JMSReader"> <property name="jmsTemplate" ref="jmsTemplate" /> </bean> <bean id="jmsreader2" class="com.zsyl.batch.reader.JMSReader2"> <property name="jmsTemplate" ref="jmsTemplate2" /> </bean> <bean id="jmswriter" class="com.zsyl.batch.writer.JMSWriter"></bean> <!-- --> <batch:job id="TestJob1" parent="simpleJob"> <batch:step id="step1"> <tasklet> <chunk reader="jmsreader" writer="jmswriter" commit-interval="100" /> </tasklet> </batch:step> </batch:job> <batch:job id="TestJob2" parent="simpleJob"> <batch:step id="step2"> <tasklet> <chunk reader="jmsreader2" writer="jmswriter" commit-interval="100" /> </tasklet> </batch:step> </batch:job> <bean id="runScheduler" class="com.zsyl.batch.scheduler.RunScheduler" /> <!-- Run every 1 minute --> <task:scheduled-tasks> <task:scheduled ref="runScheduler" method="run" cron="*/10 * * * * *" /> </task:scheduled-tasks> </beans>
package com.zsyl.batch.reader; import java.util.Map; import org.springframework.batch.item.jms.JmsItemReader; import com.alibaba.fastjson.JSONObject; public class JMSReader extends JmsItemReader<Map>{ @SuppressWarnings("unchecked") @Override public Map<String, Map> read(){ Map<String, Map> rtn = super.read(); if(rtn!=null){ Map<String, String> aa=rtn.get("enroll"); } return rtn; } }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请问一下你是在做spring batch 远程分块么,我这边刚开始做,不太会,能指教一下么。qq:455795046