I have been struggling to complete the last 4 days to implement a push notification in the vert.x structure using java (on the server side) and javascript (on the client side). I studied an example from this link .
I canβt understand what the meaning of the prefix is in the bottom line of the code. How do I put my custom message in a json array so that it is sent to the client as a notification.
sockJSServer.bridge(new JsonObject().putString("prefix", "/eventbus"), permitted, permitted);
And I also canβt implement the client part according to my need. My requirement is to get data from the database, and vert.x server to publish this data in the amount of n clients. What will be the prerequisite for this whole scenario?
The above link has index.html. I debugged this in the browser. It successfully connects the server. Another point: what is the value of "/ eventbus" in index.html (line number 108)
eb = new vertx.EventBus("http://localhost:8080/eventbus");
After successfully connecting to the server. Does each client have to subscribe to the server to receive a notification from the server? I want each client to receive a notification without client intervention.
Now, the last point is below the code, what is the address? This is a client IP address or server or any other thing.
function publish(address, message) { if (eb) { var json = {text: message}; eb.publish(address, json); $('#sent').append($("<code>").text("Address:" + address + " Message:" + message)); $('#sent').append($("</code><br>")); } } function subscribe(address) { if (eb) { eb.registerHandler(address, function(msg, replyTo) { $('#received').append("Address:" + address + " Message:" + msg.text + "<br>"); }); $('#subscribed').append($("<code>").text("Address:" + address)); $('#subscribed').append($("</code><br>")); } }
Any help would be noticeable.
source share