Hazelcast Jet和Node.JS客户端序列化问题 [英] Hazelcast Jet and Node.JS client serialization issue
问题描述
我将Jet 0.6作为备份,并安装了hazelcast-nodejs-client 0.8.0的一些Node.JS进程.我试图推动从Node进程映射对象,这恰好反映了Jet端类似对象的反映.但是我不明白如何在Jet方面确保此JS对象将分别进行序列化/反序列化.我有一种感觉,我需要向Jet表示,这个JSON对象是Data POJO,应该使用适当的序列化/反序列化.
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.
在节点侧:
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);
}
);
在Jet方面:公共类数据实现可序列化的{
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;
}
更新:
我设法在调用堆栈中找到了 DefaultSerializer.ts
,它显然负责将JS对象转换为要通过 MapProxy
服务到缓存:
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));
}
}
推荐答案
Node.js和Java端都需要正确的序列化配置.但是 Serializable
是仅Java的接口.因此,Hazelcast Node.js客户端无法使用它.您需要您的对象在两侧实现IdentifiedDataSerializable或Portable.
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标识的数据可序列化示例: https://github.com/hazelcast/hazelcast-code-samples/tree/master/serialization/identified-data-serializable
Java Identified Data Serializable sample: https://github.com/hazelcast/hazelcast-code-samples/tree/master/serialization/identified-data-serializable
这篇关于Hazelcast Jet和Node.JS客户端序列化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!