Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclusive Consumer Logging Improvements #2536

Closed
zhangheng0027 opened this issue Sep 28, 2023 · 3 comments · Fixed by #2537
Closed

Exclusive Consumer Logging Improvements #2536

zhangheng0027 opened this issue Sep 28, 2023 · 3 comments · Fixed by #2537

Comments

@zhangheng0027
Copy link
Contributor

When the consumer is set to exclusive and multiple instances are started, the console continuously outputs info level restart consumers log.

When setting consumers as exclusive and bound, the restart log level for other consumers should be TRACE or DEBUG.

https://github.com/zhangheng0027/testRabbitMQ.git

@RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(value = "test2Queue"),
                    exchange = @Exchange(value = "testExchange"),
                    key = "test2"
            ),
            concurrency = "1",
            exclusive = true,
            ackMode = "MANUAL",
            containerFactory = "batchListenerContainerFactory"
    )
    @SneakyThrows
    public void test(@Payload List<Message<EquipmentStatusChangeEvent>> event, Channel channel) {
    }

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(value = "test2Queue"),
                    exchange = @Exchange(value = "testExchange"),
                    key = "test2"
            ),
            concurrency = "1",
            exclusive = true,
            ackMode = "MANUAL",
            containerFactory = "batchListenerContainerFactory"
    )
    @SneakyThrows
    public void test2(@Payload List<Message<EquipmentStatusChangeEvent>> event, Channel channel) {
    }
2023-09-28T17:11:57.492+08:00  WARN 21016 --- [ntContainer#1-1] o.s.a.r.l.SimpleMessageListenerContainer : Exclusive consumer failure: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=403, reply-text=ACCESS_REFUSED - queue 'test2Queue' in vhost '/test' in exclusive use, class-id=60, method-id=20)
2023-09-28T17:11:57.498+08:00  INFO 21016 --- [ntContainer#1-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer@43982337: tags=[[]], channel=Cached Rabbit Channel: AMQChannel(amqp://oee@192.168.115.248:4626//test,2), conn: Proxy@42fb8c87 Shared Rabbit Connection: SimpleConnection@5a50d9fc [delegate=amqp://oee@192.168.115.248:4626//test, localPort=9562], acknowledgeMode=MANUAL local queue size=0
2023-09-28T17:11:57.508+08:00  INFO 21016 --- [68.115.248:4626] o.s.a.r.c.CachingConnectionFactory       : Shutdown Signal: channel error; protocol method: #method<channel.close>(reply-code=403, reply-text=ACCESS_REFUSED - queue 'test2Queue' in vhost '/test' in exclusive use, class-id=60, method-id=20)

@garyrussell
Copy link
Contributor

This is a reasonable request, but consider setting Single Active Consumer on the queue rather than using exclusive consumers; it is more efficient and avoids this problem.

https://www.rabbitmq.com/consumers.html#single-active-consumer

Difference from Exclusive Consumers

Compared to AMQP 0-9-1 exclusive consumer, single active consumer puts less pressure on the application side to maintain consumption continuity. Consumers just need to be registered and failover is handled automatically, there's no need to detect the active consumer failure and to register a new consumer.

@garyrussell
Copy link
Contributor

By the way, the WARN log can be avoided by setting a custom logger here:

	/**
	 * Set a {@link ConditionalExceptionLogger} for logging exclusive consumer failures. The
	 * default is to log such failures at WARN level.
	 * @param exclusiveConsumerExceptionLogger the conditional exception logger.
	 * @since 1.5
	 */
	public void setExclusiveConsumerExceptionLogger(ConditionalExceptionLogger exclusiveConsumerExceptionLogger) {

The INFO logs for the restart can be avoided by setting the container's logger level to WARN.

@garyrussell
Copy link
Contributor

There is also a closeExceptionLogger on the connection factory:

	/**
	 * Set the strategy for logging close exceptions; by default, if a channel is closed due to a failed
	 * passive queue declaration, it is logged at debug level. Normal channel closes (200 OK) are not
	 * logged. All others are logged at ERROR level (unless access is refused due to an exclusive consumer
	 * condition, in which case, it is logged at INFO level).
	 * @param closeExceptionLogger the {@link ConditionalExceptionLogger}.
	 * @since 1.5
	 */
	public void setCloseExceptionLogger(ConditionalExceptionLogger closeExceptionLogger) {

garyrussell added a commit to garyrussell/spring-amqp that referenced this issue Sep 28, 2023
Resolves spring-projects#2536

Log messages due to access refused due to exclusive consumers at DEBUG
level instead of WARN and INFO.
garyrussell added a commit to garyrussell/spring-amqp that referenced this issue Sep 28, 2023
Resolves spring-projects#2536

Log messages due to access refused due to exclusive consumers at DEBUG
level instead of WARN and INFO.
garyrussell added a commit to garyrussell/spring-amqp that referenced this issue Sep 28, 2023
Resolves spring-projects#2536

Log messages due to access refused due to exclusive consumers at DEBUG
level instead of WARN and INFO.
garyrussell added a commit to garyrussell/spring-amqp that referenced this issue Sep 28, 2023
Resolves spring-projects#2536

Log messages due to access refused due to exclusive consumers at DEBUG
level instead of WARN and INFO.
garyrussell added a commit to garyrussell/spring-amqp that referenced this issue Sep 28, 2023
Resolves spring-projects#2536

Log messages due to access refused due to exclusive consumers at DEBUG
level instead of WARN and INFO.
garyrussell added a commit to garyrussell/spring-amqp that referenced this issue Oct 4, 2023
Resolves spring-projects#2536

Log messages due to access refused due to exclusive consumers at DEBUG
level instead of WARN and INFO.
artembilan pushed a commit that referenced this issue Oct 4, 2023
Resolves #2536

Log messages due to access refused due to exclusive consumers at DEBUG
level instead of WARN and INFO.

* Use LogMessage to avoid enabled check.

* Use LogMessage at INFO level too.
@garyrussell garyrussell changed the title The log level should be adjusted Exclusive Consumer Logging Improvements Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants