serialization - Hazelcast 3.6.1 "There is no suitable de-serializer for type"异常

标签 serialization client hazelcast kryo

我正在使用 Hazelcast 3.6.1 从 map 中读取。存储在 map 中的对象类称为 附表 .

我已经像这样在客户端配置了一个自定义序列化程序。

ClientConfig config = new ClientConfig();
SerializationConfig sc = config.getSerializationConfig();
sc.addSerializerConfig(add(new ScheduleSerializer(), Schedule.class));
...
private SerializerConfig add(Serializer serializer, Class<? extends Serializable> clazz) {
    SerializerConfig sc = new SerializerConfig();
    sc.setImplementation(serializer).setTypeClass(clazz);
    return sc;
}

map 是这样创建的
private final IMap<String, Schedule> map = client.getMap("schedule");

如果我使用 schedule id 作为键从 map 中获取,则 map 返回 正确 值(value),例如
return map.get("zx81");

如果我尝试使用 SQL 谓词,例如
return new ArrayList<>(map.values(new SqlPredicate("statusActive")));

然后我收到以下错误
Exception in thread "main" com.hazelcast.nio.serialization.HazelcastSerializationException: There is no suitable de-serializer for type 2. This exception is likely to be caused by differences in the serialization configuration between members or between clients and members.

自定义序列化器使用 Kryo 进行序列化(基于此博客 http://blog.hazelcast.com/comparing-serialization-methods/)
public class ScheduleSerializer extends CommonSerializer<Schedule> {

    @Override
    public int getTypeId() {
        return 2;
    }

    @Override
    protected Class<Schedule> getClassToSerialize() {
        return Schedule.class;
    }

}

CommonSerializer 定义为
public abstract class CommonSerializer<T> implements StreamSerializer<T> {

    protected abstract Class<T> getClassToSerialize();

    @Override
    public void write(ObjectDataOutput objectDataOutput, T object) {
        Output output = new Output((OutputStream) objectDataOutput);
        Kryo kryo = KryoInstances.get();
        kryo.writeObject(output, object);
        output.flush(); // do not close!
        KryoInstances.release(kryo);
    }

    @Override
    public T read(ObjectDataInput objectDataInput) {
        Input input = new Input((InputStream) objectDataInput);
        Kryo kryo = KryoInstances.get();
        T result = kryo.readObject(input, getClassToSerialize());
        input.close();
        KryoInstances.release(kryo);
        return result;
    }

    @Override
    public void destroy() {
        // empty
    }
}

我需要在 上做任何配置吗?服务器端 ?我认为客户端配置就足够了。

我正在使用 Hazelcast 客户端 3.6.1 并运行一个节点/成员。

最佳答案

查询要求节点了解类,因为必须反序列化字节流才能访问属性并查询它们。这意味着当您想查询对象时,您还必须在服务器端部署模型类(和序列化程序)。

而当您使用基于键的访问时,我们不需要查看值(在我们比较键的字节数组时也不需要查看键),只需发送结果即可。这样,模型类和序列化程序都不必在 Hazelcast 节点上可用。

我希望这是有道理的。

关于serialization - Hazelcast 3.6.1 "There is no suitable de-serializer for type"异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36365432/

相关文章:

java - 持久 TCP 连接客户端/服务器

java - 客户端之间无法通信

android - 替换已弃用的 DefaultHttpClient

spring-boot - 无法使用键 'dataSource'注册MBean [HikariDataSource(HikariPool-0)]

hazelcast - 本地 map 统计中 getHits() 和 getGetOperationCount() 有什么区别?

php - 使用属性序列化 XML 文档

java - 如何使用 GSON 反序列化 Map<String, Object>

tcp - Vertx Eventbus 发送节点间失败

java.io.NotSerializableException 和实现 Serializable

java - 没有明显原因的可选数据异常