Spring AMQP OutOfMemory异常

时间:2019-05-21 01:51:46

标签: java spring spring-boot rabbitmq spring-amqp

我正在解决这个问题,其中JVM正在运行OutOfMemory,并且由于频繁重启容器而导致队列被卡住。即使我在队列侦听器中有异常处理程序,它也无法正常工作。

这是我的application.properties

spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.listener.simple.concurrency=3
spring.rabbitmq.listener.simple.max-concurrency=10
spring.rabbitmq.listener.simple.idle-event-interval=60000
spring.rabbitmq.listener.simple.prefetch1
spring.rabbitmq.listener.simple.retry.max-attempts=1
spring.rabbitmq.listener.simple.default-requeue-rejected=false

这是我的听众

@RabbitListener(
    bindings = @QueueBinding(
        value = @Queue(value = "queue", durable = "true"),
        exchange = @Exchange(value = "exchange", type = ExchangeTypes.TOPIC),
        key = RabbitConfiguration.RULE_SERVICE_ROUTING_KEY
    )
)
public void processMessage(final Order order, final Message message) {

    try {

        // OutOfMemory is happening inside this service which calls Drools  
        this.service.run(order);      

    } catch (Throwable throwable) {

        logger.info("Message failed");
        throw new AmqpRejectAndDontRequeueException(throwable);
    }
}
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "org.springframework.amqp.rabbit.RabbitListenerEndpointContainer#0-4"

服务代码

public void run(Order order) {

    try {

        kieSession = this.getContainer(group, artifact, version).newKieSession();
        this.setUpListeners(kieSession);
        kieSession.insert(order);
        kieSession.fireAllRules();

    } catch (Throwables t) {

       throw new Exception(t);

    } finally {

        kieSession.dispose();
    }
}

有什么方法可以拒绝此消息并将其放入死信队列。

0 个答案:

没有答案