Activemq 活动mq和spring jmstemplate如何正确关闭
对于某些上下文,我正在使用符合jsr的实现在Spring批处理中执行JMS读写器。我使用的是SpringBatch提供的JMSReader和JMS编写器类,但我将它们包装在自己的阅读器和编写器中。 我没有典型的应用程序上下文,因为我使用的是JSR方法。这些类通过作业规范或根据jsr规范通过batch.xml进行初始化 我遇到的问题是,我有一个独立的批处理应用程序,当我定义一个JMS读取器和/或JMS编写器为活动mq创建连接工厂并将其设置为spring的JMSTemplate类的目标工厂时,处理完成后的应用程序不会正常关闭。使用IBM MQ连接工厂的替代方案可以正常工作 让我提供一些我已经完成的代码 这是我创建连接工厂的地方。我做了几行修改,试图在应用程序运行时,让那些还活着的线程死掉Activemq 活动mq和spring jmstemplate如何正确关闭,activemq,spring-batch,jmstemplate,Activemq,Spring Batch,Jmstemplate,对于某些上下文,我正在使用符合jsr的实现在Spring批处理中执行JMS读写器。我使用的是SpringBatch提供的JMSReader和JMS编写器类,但我将它们包装在自己的阅读器和编写器中。 我没有典型的应用程序上下文,因为我使用的是JSR方法。这些类通过作业规范或根据jsr规范通过batch.xml进行初始化 我遇到的问题是,我有一个独立的批处理应用程序,当我定义一个JMS读取器和/或JMS编写器为活动mq创建连接工厂并将其设置为spring的JMSTemplate类的目标工厂时,处理完
private ConnectionFactory openAMQ() throws IllegalArgumentException{
ActiveMQConnectionFactory targetConnectionFactory = new ActiveMQConnectionFactory();
if(protocol == null){
throw new IllegalArgumentException("Active MQ protocol can not be empty");
}
AMQProtocols proto = AMQProtocols.valueOf(protocol.toUpperCase());
StringBuilder sb = new StringBuilder();
sb.append(proto.getProtocol()).append("://").append(this.host).append(":").append(this.port);
if(amqParams != null && amqParams.trim().length() > 0){
sb.append("?").append(amqParams);
}
targetConnectionFactory.setBrokerURL(sb.toString());
//targetConnectionFactory.setAlwaysSessionAsync(false);
//targetConnectionFactory.setUseAsyncSend(false);
return targetConnectionFactory;
}
这里是我创建JMSTemplate对象的地方
protected JmsTemplate getJMSTemplate(ConnectionFactory targetConnectionFactory){
CachingConnectionFactory ccf = new CachingConnectionFactory();
ccf.setTargetConnectionFactory(targetConnectionFactory);
JmsTemplate template = new JmsTemplate(ccf);
template.setDefaultDestinationName(jmsDefaultDestinationName);
template.setReceiveTimeout(Long.parseLong(jmsReceiveTimeoutValue));
template.setSessionTransacted(Boolean.parseBoolean(jmsSessionTransacted));
//template.setMessageConverter(messageConverter);
return template;
}
最后是JMSReader的开放方法,作者几乎完全相同
public void open(Serializable checkpoint) throws Exception {
//First we need to get our broker specific connection factory
ConnectionFactory targetConnectionFactory = getTargetConnectionFactory();
this.template = getJMSTemplate(targetConnectionFactory);
reader = new JmsItemReader();
reader.setItemType(Class.forName(jmsItemTypeFullyQualifiedName));
reader.setJmsTemplate(template);
}
我看到的活动线程似乎与连接以及一些非活动监视线程有关。由于这些应用程序保持其活动状态,因此可以防止独立应用程序关闭
有人知道我如何配置连接工厂或jms模板来阻止这种情况发生,或者在读取器完成后管理它以使其正确关闭吗 我想我回答了我自己的问题。在CachingConnectionFactory上,我在jms read和writer的close方法中添加了对destroy方法的调用。我确实有些担心,打电话不允许进行适当的清理,但它允许应用程序关闭而不是挂起。我想我回答了我自己的问题。在CachingConnectionFactory上,我在jms read和writer的close方法中添加了对destroy方法的调用。我确实有点担心,打电话不允许进行适当的清理,但它允许应用程序关闭而不是挂起