Java node.js hazelcast客户端因新事件而崩溃
我使用以下演示:构建hzc集群。我删除了子/父演示类,并添加了我自己的MachineData类。写和读工作正常,但在我的服务中,我希望得到通知,当新消息事件发生时,我总是会收到以下错误,服务将退出:Java node.js hazelcast客户端因新事件而崩溃,java,node.js,hazelcast,Java,Node.js,Hazelcast,我使用以下演示:构建hzc集群。我删除了子/父演示类,并添加了我自己的MachineData类。写和读工作正常,但在我的服务中,我希望得到通知,当新消息事件发生时,我总是会收到以下错误,服务将退出: [...]/node_modules/hazelcast-client/lib/serialization/SerializationService.js:80 return serializer.read(dataInput);
[...]/node_modules/hazelcast-client/lib/serialization/SerializationService.js:80
return serializer.read(dataInput);
^
TypeError: Cannot read property 'read' of undefined
在我的node.js服务中,我使用以下代码:
async onModuleInit(): Promise<void> {
try {
const gateway = this.hzcGateway;
const client = await Client.newHazelcastClient();
let map: IMap<any, any> = await client.getMap('xtp.impl.model.MachineData');
const listener: EntryListener<any, any> = {
added(entryEvent: EntryEvent<any, any>) {
try {
console.log('Item added:', entryEvent.value);
gateway.informClients(JSON.parse(entryEvent.value));
} catch (error) {
console.error(error);
}
},
removed(entryEvent: EntryEvent<any, any>) {
console.log('itemRemoved:', entryEvent);
}
};
const registrationId = await map.addEntryListener(listener, undefined, true);
console.log('RegistrationId => (', registrationId, ')');
} catch (err) {
console.error('Error occurred:', err);
}
}
Node.js“MachineDataEvent”-类:
JAVA部分:
public class MachineDataEvent implements IdentifiedDataSerializable {
public Integer id;
public String jobId;
public String jobName;
[...]
public MachineDataEvent() {
}
MachineDataEvent(
Integer id,
String jobId,
String jobName,
[...]
) {
this.id = id;
this.jobId = jobId;
this.jobName = jobName;
[...]
}
@Override
public void readData(ObjectDataInput in) throws IOException {
this.id = in.readInt();
this.jobId = in.readUTF();
this.jobName = in.readUTF();
[...]
}
@Override
public void writeData(ObjectDataOutput out) throws IOException {
out.writeInt(id);
out.writeUTF(jobId);
out.writeUTF(jobName);
out.writeUTF(jobPart);
[...]
}
@Override
public int getFactoryId() {
return 1000;
}
public int getClassId() {
return 100;
}
@Override
public int getId() {
return this.id;
}
不幸的是,错误仍然存在,我不知道这是否是解决错误的正确方法。我正在使用节点“hazelcast客户端”:“^3.12.3”。。。
问候
export class MachineDataEvent {
id: number;
jobId: string;
jobName: string;
[...]
factoryId: number;
classId: number;
constructor(
id?: number,
jobId?: string,
jobName?: string,
[...]
) {
this.id = id;
this.jobId = jobId;
this.jobName = jobName;
[...]
this.factoryId = 1000;
this.classId = 100;
}
getFactoryId() {
return this.factoryId;
}
getClassId() {
return this.classId;
}
writeData(dataOutput) {
dataOutput.writeInt(this.id);
dataOutput.writeUTF(this.jobId);
dataOutput.writeUTF(this.jobName);
[...]
}
readData(dataInput) {
this.id = dataInput.readInt();
this.jobId = dataInput.readUTF();
this.jobName = dataInput.readUTF();
[...]
}
}
public class MachineDataEvent implements IdentifiedDataSerializable {
public Integer id;
public String jobId;
public String jobName;
[...]
public MachineDataEvent() {
}
MachineDataEvent(
Integer id,
String jobId,
String jobName,
[...]
) {
this.id = id;
this.jobId = jobId;
this.jobName = jobName;
[...]
}
@Override
public void readData(ObjectDataInput in) throws IOException {
this.id = in.readInt();
this.jobId = in.readUTF();
this.jobName = in.readUTF();
[...]
}
@Override
public void writeData(ObjectDataOutput out) throws IOException {
out.writeInt(id);
out.writeUTF(jobId);
out.writeUTF(jobName);
out.writeUTF(jobPart);
[...]
}
@Override
public int getFactoryId() {
return 1000;
}
public int getClassId() {
return 100;
}
@Override
public int getId() {
return this.id;
}