GH-5123: Add LockRegistry to AbstractMessageGroupStore

Fixes: https://github.com/spring-projects/spring-integration/issues/5123

When `RedisMessageStore`, for example, adds and removes messages, it operates on two keys separately, which may cause problems in multi-threading due to non-atomic operations.
Although using Redis to delay messages is not a good idea, the abnormal loss of messages in the logs alerted me when the number of requests was not large.
By comparing the logs, the problem that the message group representing the metadata is not consistent with the actual message.

A simple solution is to add lock like in the `SimpleMessageStore`, which is also the approach taken in this pull request.

* Add `LockRegistry` to `AbstractMessageGroupStore`
* Normalize access levels and method name about the lock of `MessageGroupStore`
* Add document about the lock of `AbstractMessageGroupStore`
This commit is contained in:
NaccOll
2024-11-23 13:58:23 -05:00
committed by Artem Bilan
parent 12a643d494
commit 9962ee49a2
14 changed files with 284 additions and 214 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2007-2024 the original author or authors.
* Copyright 2007-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -493,6 +493,15 @@ class RedisMessageGroupStoreTests implements RedisContainerTest {
assertThat(store.messageGroupSize("2")).isEqualTo(1);
}
@Test
public void testMessageGroupCondition() {
String groupId = "X";
Message<String> message = MessageBuilder.withPayload("foo").build();
store.addMessagesToGroup(groupId, message);
store.setGroupCondition(groupId, "testCondition");
assertThat(store.getMessageGroup(groupId).getCondition()).isEqualTo("testCondition");
}
private record Foo(String foo) {
}