我有 Jet 0.6 作为备份,还有一些安装了 hazelcast-nodejs-client 0.8.0 的 Node.JS 进程。我正在尝试推动从 Node 进程映射一个对象,该对象恰好反映了 Jet 端的类似对象。但是我不明白如何确保在 Jet 方面这个 JS 对象将分别被序列化/反序列化。我有一种感觉,我需要向 Jet 表明这个 JSON 对象应该是 Data POJO,并且应该使用正确的序列化/反序列化。
在节点端:
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 方面:
公共类数据实现可序列化{
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:
我设法追踪调用堆栈到DefaultSerializer.ts
显然负责将 JS 对象转换为Data
要发送的实例MapProxy
缓存服务:
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。
Node.js 识别数据可序列化示例:https://github.com/hazelcast/hazelcast-nodejs-client/blob/master/code_samples/org-website/IdentifiedDataSerializedSample.js 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 https://github.com/hazelcast/hazelcast-code-samples/tree/master/serialization/identified-data-serializable
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)