Hazelcast Node.js client 4.0 is now available! Let’s see what are the main changes in this new release.
Node.js client now uses Hazelcast Open Binary Client Protocol 2.0, which has a number of enhancements and serialization improvements when compared with 1.x. For the end-user, it means that the client now supports IMDG 4.0+. Also, note that you cannot use a 4.0 client with IMDG 3.x members.
In Hazelcast 3.x, clients were implicitly assigned to an owner member responsible for cleaning up their resources after they leave the cluster. Ownership information had to be replicated to the whole cluster when a client joined the cluster. The “owner member” concept is now removed and Node.js client 4.0 acts as an ownerless client, which is a simpler solution for the problem allowing to remove the extra step.
Programmatic configuration in client 4.0 has become simpler and does not require boilerplate code anymore. The configuration itself is now represented with a plain JavaScript object.
Programmatic configuration (old way):
const { Client, Config } = require('hazelcast-client');
// Create a configuration object
const clientConfig = new Config.ClientConfig();
// Customize the client configuration
clientConfig.clusterName = 'cluster-name';
clientConfig.networkConfig.addresses.push('10.90.0.2:5701');
clientConfig.networkConfig.addresses.push('10.90.0.3:5701');
clientConfig.listeners.addLifecycleListener(function (state) {
console.log('Lifecycle Event >>> ' + state);
});
// Initialize the client with the given configuration
const client = await Client.newHazelcastClient(clientConfig);
Programmatic configuration (new way):
// No need to require Config anymore
const { Client } = require('hazelcast-client');
// Initialize the client with the configuration object (POJO)
const client = await Client.newHazelcastClient({
clusterName: 'cluster-name',
network: {
clusterMembers: [
'10.90.0.2:5701',
'10.90.0.3:5701'
]
},
lifecycleListeners: [
(state) => {
console.log('Lifecycle Event >>> ' + state);
}
]
});
The “shape” of the configuration is kept close to the old declarative configuration API and to the Java client’s YAML/XML configuration. So, the user experience is the same across other Hazelcast clients, but it is also native to JavaScript and Node.js runtime.
The old declarative configuration API was removed as it does not make a lot of sense now, considering these changes.
The 4.0 release also brings a number of changes aimed to make the API more idiomatic for JavaScript and familiar to Node.js developers.
#node #javascript #programming #developer