Jedis 不支持返回 PendingMessagesSummary
Jedis does not support returning PendingMessagesSummary
当我用 Java 11 启动 spring 应用程序写入时,显示如下错误:
[12:36:01:729] [ERROR] - com.dolphin.soa.post.common.mq.PendingMessageConsume.pendingMessage(PendingMessageConsume.java:36) - handle pending message with an error
java.lang.UnsupportedOperationException: Jedis does not support returning PendingMessagesSummary.
at org.springframework.data.redis.connection.jedis.JedisStreamCommands.xPending(JedisStreamCommands.java:279) ~[spring-data-redis-2.6.4.jar!/:2.6.4]
at org.springframework.data.redis.connection.DefaultedRedisConnection.xPending(DefaultedRedisConnection.java:567) ~[spring-data-redis-2.6.4.jar!/:2.6.4]
at org.springframework.data.redis.connection.DefaultStringRedisConnection.xPending(DefaultStringRedisConnection.java:4758) ~[spring-data-redis-2.6.4.jar!/:2.6.4]
at org.springframework.data.redis.core.DefaultStreamOperations.lambda$pending(DefaultStreamOperations.java:250) ~[spring-data-redis-2.6.4.jar!/:2.6.4]
at org.springframework.data.redis.core.DefaultStreamOperations$$Lambda68/0x00000000640b3c40.doInRedis(Unknown Source) ~[?:?]
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:223) ~[spring-data-redis-2.6.4.jar!/:2.6.4]
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:190) ~[spring-data-redis-2.6.4.jar!/:2.6.4]
at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:97) ~[spring-data-redis-2.6.4.jar!/:2.6.4]
at org.springframework.data.redis.core.DefaultStreamOperations.pending(DefaultStreamOperations.java:250) ~[spring-data-redis-2.6.4.jar!/:2.6.4]
at com.dolphin.soa.post.common.mq.PendingMessageConsume.handlePendingMessage(PendingMessageConsume.java:42) ~[classes!/:?]
at com.dolphin.soa.post.common.mq.PendingMessageConsume.pendingMessage(PendingMessageConsume.java:34) [classes!/:?]
at jdk.internal.reflect.GeneratedMethodAccessor210.invoke(Unknown Source) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
我已经把Jedis版本升级到最新的4.2.3了,为什么还是不支持Redis pending命令?我已经读过《绝地武士》issue。 Jedis 3.6.0都已经添加了pending支持,为什么还告诉我不支持?这是 Jedis 依赖项的项目:
➜ dolphin-post git:(master) ✗ ./gradlew :dolphin-post:dolphin-post-service:dependencies --configuration runtimeClasspath|grep -v "(*)"|grep -C 10 "jedis"
| | | \--- org.springframework:spring-webmvc:5.3.19
| | +--- org.springframework.boot:spring-boot-starter-data-redis -> 2.6.7
| | | \--- org.springframework.data:spring-data-redis:2.6.4
| | | +--- org.springframework.data:spring-data-keyvalue:2.6.4
| | | | +--- org.springframework.data:spring-data-commons:2.6.4
| | | | | \--- org.slf4j:slf4j-api:1.7.32 -> 1.7.36
| | | | +--- org.springframework:spring-tx:5.3.19
| | | | \--- org.slf4j:slf4j-api:1.7.32 -> 1.7.36
| | | +--- org.springframework:spring-oxm:5.3.19
| | | \--- org.slf4j:slf4j-api:1.7.32 -> 1.7.36
| | +--- redis.clients:jedis:4.2.3 -> 3.7.1
| | | +--- org.slf4j:slf4j-api:1.7.30 -> 1.7.36
| | | \--- org.apache.commons:commons-pool2:2.10.0 -> 2.11.1
| | +--- org.springframework.session:spring-session-data-redis -> 2.6.3
| | | +--- org.springframework.session:spring-session-core:2.6.3
| | | | \--- org.springframework:spring-jcl:5.3.19
| | +--- org.springframework.boot:spring-boot-starter-aop -> 2.6.7
| | | \--- org.aspectj:aspectjweaver:1.9.7
| | +--- org.springframework.boot:spring-boot-starter-test -> 2.6.7
| | | +--- org.springframework.boot:spring-boot-test:2.6.7
| | | +--- org.springframework.boot:spring-boot-test-autoconfigure:2.6.7
这是我的 java 代码,如下所示:
void handlePendingMessage(){
StreamOperations<String, String, String> streamOperations = this.stringRedisTemplate.opsForStream();
PendingMessagesSummary pendingMessagesSummary = streamOperations.pending(consumer,groupName);
Long totalPendingMessageCount = pendingMessagesSummary.getTotalPendingMessages();
String groupName = pendingMessagesSummary.getGroupName();
List<MapRecord<String, String, String>> retVal = streamOperations.read(Consumer.from(groupName, "my_consumer1"), StreamOffset.create(consumer, ReadOffset.from("0")));
for (MapRecord<String, String, String> record : retVal ) {
//streamOperations.acknowledge(groupName, record);
}
}
我应该怎么做才能让它支持PendingMessagesSummary
?
您没有直接使用 Jedis。您正在通过 spring-data-redis.
使用它
虽然Jedis已经加入了PendingMessagesSummary的支持,但是spring-data-redis还没有包含对Jedis的支持。这就是您收到错误的原因。
当我用 Java 11 启动 spring 应用程序写入时,显示如下错误:
[12:36:01:729] [ERROR] - com.dolphin.soa.post.common.mq.PendingMessageConsume.pendingMessage(PendingMessageConsume.java:36) - handle pending message with an error
java.lang.UnsupportedOperationException: Jedis does not support returning PendingMessagesSummary.
at org.springframework.data.redis.connection.jedis.JedisStreamCommands.xPending(JedisStreamCommands.java:279) ~[spring-data-redis-2.6.4.jar!/:2.6.4]
at org.springframework.data.redis.connection.DefaultedRedisConnection.xPending(DefaultedRedisConnection.java:567) ~[spring-data-redis-2.6.4.jar!/:2.6.4]
at org.springframework.data.redis.connection.DefaultStringRedisConnection.xPending(DefaultStringRedisConnection.java:4758) ~[spring-data-redis-2.6.4.jar!/:2.6.4]
at org.springframework.data.redis.core.DefaultStreamOperations.lambda$pending(DefaultStreamOperations.java:250) ~[spring-data-redis-2.6.4.jar!/:2.6.4]
at org.springframework.data.redis.core.DefaultStreamOperations$$Lambda68/0x00000000640b3c40.doInRedis(Unknown Source) ~[?:?]
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:223) ~[spring-data-redis-2.6.4.jar!/:2.6.4]
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:190) ~[spring-data-redis-2.6.4.jar!/:2.6.4]
at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:97) ~[spring-data-redis-2.6.4.jar!/:2.6.4]
at org.springframework.data.redis.core.DefaultStreamOperations.pending(DefaultStreamOperations.java:250) ~[spring-data-redis-2.6.4.jar!/:2.6.4]
at com.dolphin.soa.post.common.mq.PendingMessageConsume.handlePendingMessage(PendingMessageConsume.java:42) ~[classes!/:?]
at com.dolphin.soa.post.common.mq.PendingMessageConsume.pendingMessage(PendingMessageConsume.java:34) [classes!/:?]
at jdk.internal.reflect.GeneratedMethodAccessor210.invoke(Unknown Source) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
我已经把Jedis版本升级到最新的4.2.3了,为什么还是不支持Redis pending命令?我已经读过《绝地武士》issue。 Jedis 3.6.0都已经添加了pending支持,为什么还告诉我不支持?这是 Jedis 依赖项的项目:
➜ dolphin-post git:(master) ✗ ./gradlew :dolphin-post:dolphin-post-service:dependencies --configuration runtimeClasspath|grep -v "(*)"|grep -C 10 "jedis"
| | | \--- org.springframework:spring-webmvc:5.3.19
| | +--- org.springframework.boot:spring-boot-starter-data-redis -> 2.6.7
| | | \--- org.springframework.data:spring-data-redis:2.6.4
| | | +--- org.springframework.data:spring-data-keyvalue:2.6.4
| | | | +--- org.springframework.data:spring-data-commons:2.6.4
| | | | | \--- org.slf4j:slf4j-api:1.7.32 -> 1.7.36
| | | | +--- org.springframework:spring-tx:5.3.19
| | | | \--- org.slf4j:slf4j-api:1.7.32 -> 1.7.36
| | | +--- org.springframework:spring-oxm:5.3.19
| | | \--- org.slf4j:slf4j-api:1.7.32 -> 1.7.36
| | +--- redis.clients:jedis:4.2.3 -> 3.7.1
| | | +--- org.slf4j:slf4j-api:1.7.30 -> 1.7.36
| | | \--- org.apache.commons:commons-pool2:2.10.0 -> 2.11.1
| | +--- org.springframework.session:spring-session-data-redis -> 2.6.3
| | | +--- org.springframework.session:spring-session-core:2.6.3
| | | | \--- org.springframework:spring-jcl:5.3.19
| | +--- org.springframework.boot:spring-boot-starter-aop -> 2.6.7
| | | \--- org.aspectj:aspectjweaver:1.9.7
| | +--- org.springframework.boot:spring-boot-starter-test -> 2.6.7
| | | +--- org.springframework.boot:spring-boot-test:2.6.7
| | | +--- org.springframework.boot:spring-boot-test-autoconfigure:2.6.7
这是我的 java 代码,如下所示:
void handlePendingMessage(){
StreamOperations<String, String, String> streamOperations = this.stringRedisTemplate.opsForStream();
PendingMessagesSummary pendingMessagesSummary = streamOperations.pending(consumer,groupName);
Long totalPendingMessageCount = pendingMessagesSummary.getTotalPendingMessages();
String groupName = pendingMessagesSummary.getGroupName();
List<MapRecord<String, String, String>> retVal = streamOperations.read(Consumer.from(groupName, "my_consumer1"), StreamOffset.create(consumer, ReadOffset.from("0")));
for (MapRecord<String, String, String> record : retVal ) {
//streamOperations.acknowledge(groupName, record);
}
}
我应该怎么做才能让它支持PendingMessagesSummary
?
您没有直接使用 Jedis。您正在通过 spring-data-redis.
使用它虽然Jedis已经加入了PendingMessagesSummary的支持,但是spring-data-redis还没有包含对Jedis的支持。这就是您收到错误的原因。