从属性文件设置JMS缓存级别

时间:2016-05-17 06:15:48

标签: java spring spring-jms

我在属性文件中定义了jms.listen.cache.level = 1,如下所示:

jms.listen.get.timeOut = 30000
#conn = 1, session = 2, cunsumer = 3,none = 0
jms.listen.chache.level = 1
jms.concurrency.datapoint.request=10

以下是我已经定义了这个的application-context.xml文件。

<bean id="DataPointRequest:messageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer" scope="prototype">
        <property name="autoStartup" value="false" />
        <property name="receiveTimeout" value="${jms.listen.get.timeOut}"></property>
        <property name="cacheLevel" value="${jms.listen.chache.level}"></property>
        <property name="concurrency" value="${jms.concurrency.datapoint.request}" />
        <property name="connectionFactory" ref="DataPointRequest:connectionFactory"/>
        <property name="destination" ref="DataPointRequest:requestDestination"/>
        <property name="messageListener" ref="DataPointRequest:messageListener" />
        <property name="sessionTransacted" value="true" />
        <property name="errorHandler" ref="jmsErrorHandler"/>
    </bean>

当我运行我的应用程序时,它会打印[...JMSMessageListeningInboundEndpoint] (main) cacheLevel=3。哪个是DefaultMessageListenerContainer类中定义的CACHE_CONSUMER = 3值。 由于事务管理器未在此处设置,因此它需要CACHE_CONSUMER值并在应用程序启动时打印cacheLevel = 3。然后打印[...JMSMessageListeningInboundEndpoint] (main) cacheLevel=1

我想在应用程序启动时设置cacheLevel = 1。这该怎么做 ?请建议我。

下面是我在应用程序启动时获得cacheLevel = 3的类。

public class JMSMessageListeningInboundEndpoint implements InboundEndpoint {

    private AbstractMessageListenerContainer messageListenerContainer;
    private static Logger logger = Logger.getLogger(JMSMessageListeningInboundEndpoint.class);

    @Override
    public void start() throws StartInboundEndpointException {

        try {

            messageListenerContainer.start();
            if(messageListenerContainer  instanceof org.springframework.jms.listener.DefaultMessageListenerContainer){
                int cacheLevel = ((org.springframework.jms.listener.DefaultMessageListenerContainer)messageListenerContainer).getCacheLevel();
                logger.info("cacheLevel=" + cacheLevel + ".");
            }

        } catch (JmsException e) {
            throw new StartInboundEndpointException("Failed to start message listener container.", this, "start_failed", e);
        }
    }

    public void shutdown() {
        messageListenerContainer.shutdown();
    }

    public void setMessageListenerContainer(
            AbstractMessageListenerContainer messageListenerContainer) {
        this.messageListenerContainer = messageListenerContainer;

    }
}

0 个答案:

没有答案