spring Batch取 ActiveMq Queues 每次只能取出一条,怎样才能一次取多条?

发布于 2021-12-05 07:18:12 字数 5225 浏览 1008 评论 1

想从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>



reader
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;
		
	}
 
	 
}



writer 还没写逻辑

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柳絮泡泡 2021-12-05 11:23:46

请问一下你是在做spring batch 远程分块么,我这边刚开始做,不太会,能指教一下么。qq:455795046

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文