Kasper Jan Mooijman
Kasper Jan Mooijman

Reputation: 186

How to connect to a vertx eventbus using hazelcast in node

I'm creating a cluster of applications that run on my server. I use Hazelcast-cluster in combination with VertX in java. now I would lite to extend the vertx eventbus into an NodeJs applicaion running on the same server.

Hazelcast is running in node and connecting correctly with the hazelcast members running on the JVM

var HazelcastClient = require('hazelcast-client').Client;
var Config = require('hazelcast-client').Config;
var config = new Config.ClientConfig();
config.networkConfig.addresses = [{host: '127.0.0.1', port: '5701'}];
var map = {};
HazelcastClient.newHazelcastClient(config)
    .then(function (hazelcastClient) {
        map = hazelcastClient.getMap("persons");
    });
});

can someone help me with the eventbus part ?!?!

Thanks

Upvotes: 2

Views: 751

Answers (2)

Kasper Jan Mooijman
Kasper Jan Mooijman

Reputation: 186

After some long searching I found the answer to my problem: I had to let go of node and run my javascript application in a JVM provided by VertX itself. Now I can cluster my JS application with JAVA application and use the native eventbus ( without bridge )

For anyone who comes along the same situation, here is my test code :

vertx-server.js:

var Vertx = require("vertx-js/vertx");
var options = {};
Vertx.clusteredVertx(options, function (res, res_err) {
    if (res_err == null) {
        var vertx = res;
        var eventBus = vertx.eventBus();
        console.log("We now have a clustered event bus: " + eventBus);

        eventBus.consumer("system", function (message) {
            console.log("I have received a system message: " + JSON.stringify(message.body()));
            message.reply("ok from javascript");
        });

        eventBus.publish("system", "hoi van Javascript-node");

    } else {
        console.log("Failed: " + res_err);
    }
});

to instal the packages needed : npm install vertx3-full

to run the application : ./node_modules/.bin/vertx run vertx-server.js -cluster

Upvotes: 1

tsegismont
tsegismont

Reputation: 9128

You can't use the Hazelcast Node client to connect a Node application with a Vert.x cluster. You need to setup an event bus bridge use the bridge client in your Node app.

See the EventBus Bridge - Node.JS loader in the examples repo.

Upvotes: 0

Related Questions