opensolon / solon

🔥 Java "new" application development Framework: Restrained, concise, EFFICIENT, OPEN, ECOLOGICAL!! 300% higher concurrency 50% memory savings Startup is 10 times faster. Packing 90% smaller; Compatible with java8 ~ java22.
https://solon.noear.org
Apache License 2.0
2.22k stars 221 forks source link

solon 的 Jredis 发布/订阅 功能失效 #241

Closed zengyufei closed 6 months ago

zengyufei commented 6 months ago

测试demo源码下载地址

https://github.com/zengyufei/solon-demo-fenci

项目启动需要本地redis,或修改 word.local.conf 关于redis的配置

先上正常期望成功值,游览器 Ctrl+F 搜索到3个,正常

正常1 正常2 正常3

开启 solon Jredis 依赖后表现,游览器 Ctrl+F 搜索不到,排查是jredis订阅功能失效,发布正常

失败1 失败2 失败3 失败4

测试demo源码下载地址

https://github.com/zengyufei/solon-demo-fenci

项目启动需要本地redis,或修改 word.local.conf 关于redis的配置

noear commented 6 months ago

谢谢反馈!

CY-1 commented 6 months ago

我测试了 情况如下:

  1. 不依赖solon.cache.jedis 依赖jedis 且jedis版本号为2.9.0 正常
  2. 不依赖solon.cache.jedis 依赖jedis 且jedis版本号为5.0.2 不正常
  3. 不依赖jedis 依赖solon.cache.jedis 则会引入依赖redisx:1.6.2。redisx会导致引入jedis:5.0.2 不正常

目前解决方案时修改solon-parent的pom文件redisx.version为1.4.7

关于为什么redisx1.6.2不行 有待考察

noear commented 6 months ago

或者与 jedis 的版本有关,现在 redisx 用的就是 jedis 5.0.2。我去研究下

noear commented 6 months ago

我测试了一下。。。没有问题呀,都正常的。这是我的测试代码(如果同时有 jedis 依赖的话,要注意外冲突):

@Test
public void test_bus() throws Exception {
    int count = 10;
    CountDownLatch countDownLatch = new CountDownLatch(count);

    //--- bus 使用
    RedisBus bus = client.getBus();

    //发消息 (如果没有订阅者,好像消息会白发)
    Thread thread = new Thread(() -> {
        //订阅消息(这个函数会卡住线程)
        bus.subscribe((topic, message) -> {
            System.out.println(topic + " = " + message);
            countDownLatch.countDown();
        }, "topic:test");
    });

    thread.start();
    Thread.sleep(100);

    for (int i = 0; i < count; i++) {
        bus.publish("topic:test", "event-" + System.currentTimeMillis());
    }

    countDownLatch.await(2, TimeUnit.SECONDS);

    assert countDownLatch.getCount() == 0;
}
CY-1 commented 6 months ago

4.2.3

是的 他引入的org.apdplat.word这个项目的使用的redis发布订阅功能 如果引入的jedis是5.0.2或者5.0.0都不行。4.2.3则可以。

所以具体是org.apdplat.word的兼容高版本jedis(word使用的是2.5.1)有问题 还是说jedis的兼容问题有问题有待考察

CY-1 commented 6 months ago

我测试了一下。。。没有问题呀,都正常的。这是我的测试代码(如果同时有 jedis 依赖的话,要注意外冲突):

@Test
public void test_bus() throws Exception {
    int count = 10;
    CountDownLatch countDownLatch = new CountDownLatch(count);

    //--- bus 使用
    RedisBus bus = client.getBus();

    //发消息 (如果没有订阅者,好像消息会白发)
    Thread thread = new Thread(() -> {
        //订阅消息(这个函数会卡住线程)
        bus.subscribe((topic, message) -> {
            System.out.println(topic + " = " + message);
            countDownLatch.countDown();
        }, "topic:test");
    });

    thread.start();
    Thread.sleep(100);

    for (int i = 0; i < count; i++) {
        bus.publish("topic:test", "event-" + System.currentTimeMillis());
    }

    countDownLatch.await(2, TimeUnit.SECONDS);

    assert countDownLatch.getCount() == 0;
}

是的 如果自己测试时可以 但这个项目不行 必须要更换依赖的jedis

noear commented 6 months ago

这个,应该就是 版本依赖的冲突问题了。。。。A 包,依赖了 jedis a 版本;B 包,依赖了 jedis b 版本。。。当同时引入 A 和 B 包时,就冲突了(a 与 b 版本不兼容)。。。。算是特殊情况

noear commented 6 months ago

那我关掉了

zengyufei commented 6 months ago

ok,感谢两位!