修改:接收消息 String类型 反序列化失败

This commit is contained in:
lxy
2020-08-22 09:23:46 +08:00
parent c8746b712e
commit 17b28a9124
5 changed files with 28 additions and 15 deletions

View File

@@ -5,6 +5,8 @@ import com.zdemo.redis.RedisProducer;
import org.junit.Test;
import org.redkale.boot.Application;
import java.util.Map;
/**
* 消息发布订阅测试
*/
@@ -31,10 +33,10 @@ public class AppTest {
try {
RedisProducer producer = Application.singleton(RedisProducer.class);
Event<Integer> event = new Event<>();
Event<Map> event = new Event<>();
event.setTopic("c");
event.setKey("abx");
event.setValue(2314);
event.setValue(Map.of("A", "a"));
producer.send(event);

View File

@@ -8,7 +8,7 @@ import org.redkale.util.TypeToken;
import java.util.Collection;
import java.util.List;
public class MyConsumer extends RedisConsumer<Event<Integer>> {
public class MyConsumer extends RedisConsumer<Event<String>> {
public String getGroupid() {
return "group-test"; //quest、user、im、live
@@ -20,13 +20,13 @@ public class MyConsumer extends RedisConsumer<Event<Integer>> {
}
@Override
public TypeToken<Event<Integer>> getTypeToken() {
return new TypeToken<Event<Integer>>() {
public TypeToken<Event<String>> getTypeToken() {
return new TypeToken<Event<String>>() {
};
}
@Override
public void accept(Event<Integer> event) {
public void accept(Event<String> event) {
switch (event.getTopic()) {
case "a" -> System.out.println("我收到了消息 主题A 事件:" + JsonConvert.root().convertTo(event));
case "b" -> System.out.println("我收到了消息 主题B 事件:" + JsonConvert.root().convertTo(event));