简体   繁体   中英

Redis Lettuce Publish

I'm working on JDK 1.8 and I'm not able to figure out why " publish " is not working. The Redis " set " command is working for the data.

<dependency>
    <groupId>io.lettuce</groupId>
    <artifactId>lettuce-core</artifactId>
    <version>5.0.1.RELEASE</version>
</dependency> 

Code Snippet:

RedisClient redisClient = RedisClient.create(redisURI);
connection = redisClient.connect();
String l_message = l_eventObject.toString();
connection.sync().publish(l_namespace, l_message);
connection.flushCommands(); // added this to see if this works

Debug output from log:

01:25:44.826 [Thread-3] DEBUG io.lettuce.core.RedisChannelHandler - dispatching command AsyncCommand [type=PUBLISH, output=IntegerOutput [output=null, error='null'], commandType=io.lettuce.core.protocol.Command]

01:25:44.826 [Thread-3] DEBUG io.lettuce.core.protocol.DefaultEndpoint - [channel=0xb75e3dc8, /10.1.1.202:59522 -> /10.1.1.44:6379, epid=0x1] write() writeAndFlush command AsyncCommand [type=PUBLISH, output=IntegerOutput [output=null, error='null'], commandType=io.lettuce.core.protocol.Command]

01:25:44.827 [Thread-3] DEBUG io.lettuce.core.protocol.DefaultEndpoint - [channel=0xb75e3dc8, /10.1.1.202:59522 -> /10.1.1.44:6379, epid=0x1] write() done

01:25:44.827 [lettuce-nioEventLoop-4-1] DEBUG io.lettuce.core.protocol.CommandHandler - [channel=0xb75e3dc8, /10.1.1.202:59522 -> /10.1.1.44:6379, chid=0x1] write(ctx, AsyncCommand [type=PUBLISH, output=IntegerOutput [output=null, error='null'], commandType=io.lettuce.core.protocol.Command], promise)

01:25:44.829 [lettuce-nioEventLoop-4-1] DEBUG io.lettuce.core.protocol.CommandEncoder - [channel=0xb75e3dc8, /10.1.1.202:59522 -> /10.1.1.44:6379] writing command AsyncCommand [type=PUBLISH, output=IntegerOutput [output=null, error='null'], commandType=io.lettuce.core.protocol.Command]

01:25:44.830 [lettuce-nioEventLoop-4-1] DEBUG io.lettuce.core.protocol.CommandHandler - [channel=0xb75e3dc8, /10.1.1.202:59522 -> /10.1.1.44:6379, chid=0x1] Received: 4 bytes, 1 commands in the stack

01:25:44.831 [lettuce-nioEventLoop-4-1] DEBUG io.lettuce.core.protocol.CommandHandler - [channel=0xb75e3dc8, /10.1.1.202:59522 -> /10.1.1.44:6379, chid=0x1] Stack contains: 1 commands

01:25:44.831 [lettuce-nioEventLoop-4-1] DEBUG io.lettuce.core.protocol.RedisStateMachine - Decode AsyncCommand [type=PUBLISH, output=IntegerOutput [output=null, error='null'], commandType=io.lettuce.core.protocol.Command]

01:25:44.831 [lettuce-nioEventLoop-4-1] DEBUG io.lettuce.core.protocol.RedisStateMachine - Decoded AsyncCommand [type=PUBLISH, output=IntegerOutput [output=0, error='null'], commandType=io.lettuce.core.protocol.Command], empty stack: true

01:25:44.831 [Thread-3] DEBUG io.lettuce.core.protocol.DefaultEndpoint - [channel=0xb75e3dc8, /10.1.1.202:59522 -> /10.1.1.44:6379, epid=0x1] flushCommands()

01:25:44.831 [Thread-3] DEBUG io.lettuce.core.protocol.DefaultEndpoint - [channel=0xb75e3dc8, /10.1.1.202:59522 -> /10.1.1.44:6379, epid=0x1] flushCommands() Flushing 0 commands

Possible solution:

async.multi();
async.publish(l_namespace, l_message);
async.set(l_key, l_message); // for late subscribers to catch up
async.exec();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM