SimpleMessageListenerContainer onMessage每秒调用一次

时间:2016-01-21 23:58:59

标签: java performance spring-rabbitmq

SimpleMessageListenerContainer onMessage每秒调用一次!我有一个消费者实现的ChannelAwareMessageListener。我定义了一个ThreadLocal时间来记住上次调用onMessage的时间。在onMessage的开头,我打印出两次调用之间的间隔。我测试通过发送80 / s发布率的许多消息。并且对于每条消息onMessage花了200ms来处理。间隔大约是1秒。我怎样才能改进它?谢谢!

private ThreadLocal<Long> endTime = new ThreadLocal<Long>() {
    @Override protected Long initialValue() {
        return new Long(0);
    }
};
LOG.info("enter time: "+String.valueOf(System.currentTimeMillis()-endTime.get().longValue()));

以下是我对listener-container和queue的配置:

<rabbit:listener-container id="{{consumer_name}}ListenerContainer"
    connection-factory="{{consumer_name}}RabbitConsumerConnectionFactory"
    prefetch="10"
    concurrency="100"
    auto-startup="true">
    <rabbit:listener queues="{{consumer_name}}RabbitQueue" ref="{{consumer_name}}Consumer"/>
</rabbit:listener-container>
<rabbit:queue id="{{consumer_name}}RabbitQueue"
              name="q_{{host_env}}_{{svc.queue_name}}"
              declared-by="{{consumer_name}}ConsumerRabbitAdmin"
              auto-delete="false"
              durable="true"
              exclusive="false"
        />

0 个答案:

没有答案