Hazelcast Jet and Node.JS client serialization issue

*爱你&永不变心* 提交于 2021-02-10 06:26:13

问题


I am having Jet 0.6 as a backup and some Node.JS process with hazelcast-nodejs-client 0.8.0 installed. I am trying to push to map an object from Node process that is exactly a reflection of similar one on the Jet side. However I don't understand how to make sure on Jet's side this JS object will be serialized/deserialized respectively. I have a feeling I need to indicate to Jet that this JSON object is meant to be Data POJO and proper serialization/deserialization should be used.

On the node side:

var data = {
    id: someObject.did, // long
    time: someObject.time, // long
};
dataMap.put(data.id, data).then(
    function () {
        console.log("Ok");
    },
    function (error) {
        console.error(error);
    }
);

On Jet's side: public class Data implements Serializable {

private long id;
private long time;

public Data(long id, long time) {
    this.id = id;
    this.time = time;
}

public long getId() {
    return id;
}

public long getTime() {
    return time;
}

UPDATE:

I managed to trace down the call stack to a DefaultSerializer.ts that is apparently responsible for converting JS objects into Data instances to be sent over MapProxy service to the cache:

export class JsonSerializer implements Serializer {
    getId(): number {
        return -130;
    }

    read(input: DataInput): any {
        return JSON.parse(input.readUTF());
    }

    write(output: DataOutput, object: any): void {
        output.writeUTF(JSON.stringify(object));
    }
}

回答1:


A proper serialization configuration is needed on both Node.js and Java sides. However Serializable is a Java only interface. Therefore Hazelcast Node.js Client cannot use it. You need your object to implement either IdentifiedDataSerializable or Portable on both sides.

Node.js Identified Data Serializable sample: https://github.com/hazelcast/hazelcast-nodejs-client/blob/master/code_samples/org-website/IdentifiedDataSerializableSample.js

Java Identified Data Serializable sample: https://github.com/hazelcast/hazelcast-code-samples/tree/master/serialization/identified-data-serializable



来源:https://stackoverflow.com/questions/51276479/hazelcast-jet-and-node-js-client-serialization-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!