How to implement ConnectionFactory#setMaxInboundMessageBodySize in SpringBoot 2.7.15?

237 Views Asked by At

I am trying to increase the body-size limit of the inbonund amqp-messages.

I have a Cloud-Foundry Springboot 2.7.15 application.

My class currently looks like this:

@Configuration
public class RabbitConfig {

    @Bean
    @Order(Ordered.HIGHEST_PRECEDENCE)
    public ConnectionFactoryCustomizer customizer() {
        return connectionFactory -> connectionFactory.setMaxInboundMessageBodySize(1024 * 1024 * 100);
    }

}

When debugging I can see that after executing the customizer-bean the returned factory, which has a rabbitConnectionFactory does have the maxInboundMessageBodySize-value (1024 * 1024 * 100) set correctly.

picture of maxInboundMessageBodySize-var being set correctly

But when deploying the application to CloudFoundry and trying to process a message from the queue I still get the error-message:

j.l.IllegalStateException: Message body is too large (71506699), maximum configured size is 67108864. See ConnectionFactory#setMaxInboundMessageBodySize if you need to increase the limit.\n\tat c.r.c.i.CommandAssembler.consumeHeaderFrame(CommandAssembler.java:109)\n\tat c.r.c.i.CommandAssembler.handleFrame(CommandAssembler.java:172)\n\tat c.r.c.i.AMQCommand.handleFrame(AMQCommand.java:105)\n\tat c.r.c.i.AMQChannel.handleFrame(AMQChannel.java:115)\n\tat c.r.c.i.AMQConnection.readFrame(AMQConnection.java:746)\n\tat c.r.c.i.AMQConnection.access$300(AMQConnection.java:47)\n\tat c.r.c.i.AMQConnection$MainLoop.run(AMQConnection.java:673)\n\tat java.lang.Thread.run(Unknown Source)\n","message":"An unexpected connection driver error occurred"}

Somehow the original value is still being used.

I have checked that only one ConnectionFactory is created - the one being returned from RabbitAutoConfiguration.class.

I have also tried upgrading to Springboot 3.1.5. But with no luck aswell - same error still.

I have seen the post below and tried the proposed fixes but with no luck: Spring cloud stream with RabbitMQ binder throws java.lang.IllegalStateException: Message body is too large

Any help is appreciated.

1

There are 1 best solutions below

0
Anvar Bratov On
@Bean
public CachingConnectionFactory smtConnectionFactory() {
    RabbitConnectionProperties.Connection connectionParams = rabbitConnectionProperties.getSmt();
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory(connectionParams.getHost());
    connectionFactory.setPort(connectionParams.getPort());
    connectionFactory.setVirtualHost(connectionParams.getVirtualHost());
    connectionFactory.setUsername(connectionParams.getUsername());
    connectionFactory.setPassword(connectionParams.getPassword());
    connectionFactory.getRabbitConnectionFactory().setMaxInboundMessageBodySize(1024*1024*100);
    return connectionFactory;
}