Hello everybody,
I am trying to implement a very simple case where I can send a simple string to my Angular client from my Vertx backend. This is my first experience with it, so please bear with me.
To get started I did something on these bases.
//Server side Vert.x app
//////Sockjs
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
SockJSBridgeOptions options = new SockJSBridgeOptions()
.addInboundPermitted(new PermittedOptions().setAddress("/client.register"))
.addOutboundPermitted(new PermittedOptions().setAddress("service.ui-message"));
Router subRouter = sockJSHandler.bridge(options, event -> {
System.out.println("A websocket event occurred: " + event.type() + "; " + event.getRawMessage());
LOG.error("INSODE subRouter!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"+event.getRawMessage());
LOG.error("event.type()!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"+event.type());
if (event.type() == BridgeEventType.SOCKET_CREATED) {
LOG.error("A socket was created!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
// This signals that it's ok to process the event
event.complete(true);
});
router.mountSubRouter("/eventbus", subRouter);
vertx.eventBus().publish("service.ui-message", "HELLO FROM ME");
addCorsMappings(subRouter);
//////
and on the Angular client side I have this code
getPrintJobProgress()
{
console.log("ebbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: ", eb);
eb.onopen = () => {
// set a handler to receive a message
eb.registerHandler('service.ui-message', (error, message) => {
console.log('received a message: ' + JSON.stringify(message));
});
// send a message
eb.send('service.ui-message', {name: 'tim', age: 587});
}
}
But nothing is happening in my server and client side.
I also used Postman to see when happens when I go to the URL localhost:1234/eventbus and I get response saying -- Welcome to SockJS!
I referred to the doc on the vertx site but cannot move forward.
Thanks for any help
Zolf