Reputation: 2695
I am running a spring boot server integrating vertx inside like below
In my spring boot application class
@Bean
public Vertx vertx() {
return Vertx.vertx();
}
In my spring controller
@RequestMapping("/")
public String home() {
EventBus eventBus = vertx.eventBus();
while (true) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
eventBus.publish("CNotifications", "message sent : {}" + message_counter++);
}
}
How to get a handle of the event bus on the client (angular) side? I have tried angular-vertx module like below
controllers.controller('indexCtrl', function ($scope, vertxBus) {
angular.element(document).ready(function () {
vertxBus.registerHandler("CNotifications", function(message) {
console.log('Received message ' + message);
});
});
});
But the error says no such function registerHandler. Is there another angular wrapper module for vertx that I can use? or can I fix this code above to make it work. I have added these below js in my index.html
<script type="text/javascript" src="lib/vertx/sockjs.min.js"></script>
<script type="text/javascript" src="lib/vertx/vertxbus-3.1.0.js"></script>
<script type="text/javascript" src="lib/vertx/angular-vertx.min.js"></script>
Upvotes: 0
Views: 891
Reputation: 1993
You have asked for several things..
Vert.x in Spring Boot
First of all: If you don't need Spring Boot, you can open the server directly with Vert.x itself.
But if this setup is the requirement: Please have a look at the full working official demo using Spring Boot by Vert.x itself at GitHub.
Remark on element.ready
You have used within a controller an angular.element(document).ready
. That does not make any sense. If the controller has been called (by AJS), the document has been ready for some time obviously. For sure, it does not break your code, but it is not needed.
AngularJS plugin
The author of angular-vertx has cancelled his work on this prototype/project.
If you need a nice wrapper in the AngularJS context, I would suggest a look at my project angular-vertxbus: it provides a reconnectable wrapper and a handy service api with promise support.
Upvotes: 1