Я пытаюсь реализовать решение NoSql с Hazelcast-клиентом (Node Js) с использованием предикатов.
Я создаю карту пользователей, как показано ниже:
function generateUsers(users) {
return users.put('Rod', new User('Rod', 19, true)).then(function () {
var usertemp={
username: "Jane",
age: 20,
active: true
};
//return users.put('Jane', new User('Jane', 20, true));
return users.put('Jane', usertemp);
}).then(function () {
var usertemp={
username: "Freddy",
age: 23,
active: true
};
return users.put('Freddy', usertemp);
}).then(function(){
var usertemp={
username: "test",
age: 20,
active: false
};
//var usertemp2= new User('Test',20,true);
users.put('test',usertemp);
console.log("after put");
console.log("Userdata:"+users);
return users;
});
}
И когда я пытаюсь запросить запись в карте, используя предикат, она выдает исключение, ниже приведен код, который я использую для запроса карты с помощью предиката
var JsonSerializer = /** @class */ (function () {
function JsonSerializer() {
}
JsonSerializer.prototype.getId = function () {
return 1;
};
JsonSerializer.prototype.read = function (input) {
return JSON.parse(input.readUTF());
};
JsonSerializer.prototype.write = function (output, object) {
output.writeUTF(JSON.stringify(object));
};
return JsonSerializer;
}());
var cfg = new Config.ClientConfig();
cfg.serializationConfig.customSerializers =[new JsonSerializer(),];
cfg.serializationConfig.portableFactories[1] = new PortableFactory();
// Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
Client.newHazelcastClient(cfg).then(function (hz) {
// Get a Distributed Map called "users"
var users = hz.getMap('users');
// Add some users to the Distributed Map
return generateUsers(users).then(function () {
// Create a Predicate
var criteriaQuery = Predicates.and(
Predicates.truePredicate('active', true),
Predicates.isBetween('age', 18, 21)
);
// Get result collections using the the Predicate
console.log("before valuesWithPredicate");
return users.valuesWithPredicate(criteriaQuery);
}).then(function (values) {
// Print out the results
console.log(values.toArray());
// Shutdown this Hazelcast Client
hz.shutdown();
})
});
Ниже приведено исключение:
Unhandled rejection Error: There is no suitable de-serializer for type -130. This exception is likely to be caused by differences in the serialization configuration between members or between clients and members.
> NOTE: I've Tried adding customSerializer JsonSerializer in HazelcastClient config
Edit1: я пропустил консоль сервера Hazlecast, похоже, нам нужно настроить аналог Serializer на сервере Hazlecast, ниже исключение
<pre>
SEVERE: [10.8.162.33]:5701 [dev] [3.10.5] There is no suitable de-serializer for type -130. This exception is likely to be caused by differences in the serialization configuration between members or between clients and members.
com.hazelcast.nio.serialization.HazelcastSerializationException: There is no suitable de-serializer for type -130. This exception is likely to be caused by differences in the serialization configuration between members or between clients and members.
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.newHazelcastSerializationException(AbstractSerializationService.java:238)
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:182)
at com.hazelcast.query.impl.CachedQueryEntry.getValue(CachedQueryEntry.java:75)
at com.hazelcast.query.impl.CachedQueryEntry.getTargetObject(CachedQueryEntry.java:108)
at com.hazelcast.query.impl.QueryableEntry.extractAttributeValue(QueryableEntry.java:81)
at com.hazelcast.query.impl.QueryableEntry.getAttributeValue(QueryableEntry.java:48)
at com.hazelcast.query.impl.predicates.AbstractPredicate.readAttributeValue(AbstractPredicate.java:132)
at com.hazelcast.query.impl.predicates.AbstractPredicate.apply(AbstractPredicate.java:57)
at com.hazelcast.query.impl.predicates.AndPredicate.apply(AndPredicate.java:136)
at com.hazelcast.map.impl.query.PartitionScanRunner.run(PartitionScanRunner.java:97)
at com.hazelcast.map.impl.query.CallerRunsPartitionScanExecutor.execute(CallerRunsPartitionScanExecutor.java:42)
at com.hazelcast.map.impl.query.QueryRunner.runPartitionScanQueryOnGivenOwnedPartition(QueryRunner.java:172)
at com.hazelcast.map.impl.query.QueryPartitionOperation.run(QueryPartitionOperation.java:45)
at com.hazelcast.spi.Operation.call(Operation.java:148)
at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:202)
at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:191)
at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:120)
at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:100)
Но, к сожалению, я не могу найти аналогичный JSONSerializer на стороне сервера для настройки в hazlecast.xml