Я довольно новичок в Vertx, но мне очень интересно проверить его интеграцию с Spring. Я использовал Spring boot для увеличения проекта и развернул две вершины. Я хочу, чтобы они связывались друг с другом с помощью шины событий, но не сработали. Это то, что я сделал:Диспетчерская шина Vertx не может отправлять сообщения на разные verticle
В главном приложении:
@SpringBootApplication общественного класса MySpringVertxApplication { @Autowired MyRestAPIServer myRestAPIServer; @Autowired MyRestAPiverticle MyRestAPiverticle;
public static void main(String[] args) { SpringApplication.run(MySpringVertxApplication.class, args); } @PostConstruct public void deployVerticles(){ System.out.println("deploying..."); Vertx.vertx().deployVerticle(MyRestAPIVerticle); Vertx.vertx().deployVerticle(myRestAPIServer); }
}
В APIVerticle:
@Component общественный класс MyRestAPIVerticle простирается AbstractVerticle {
public static final String ALL_ACCOUNT_LISTING = "com.example.ALL_ACCOUNT_LISTING"; @Autowired AccountService accountService; EventBus eventBus; @Override public void start() throws Exception { super.start(); eventBus = vertx.eventBus(); MessageConsumer<String> consumer = eventBus.consumer(MyRestAPIVerticle.ALL_ACCOUNT_LISTING); consumer.handler(message -> { System.out.println("I have received a message: " + message.body()); message.reply("Pretty Good"); }); consumer.completionHandler(res -> { if (res.succeeded()) { System.out.println("The handler registration has reached all nodes"); } else { System.out.println("Registration failed!"); } }); }
}
Наконец ServerVerticle:
@Service общественного класса MyRestAPIServer расширяет AbstractVerticle {
HttpServer server; HttpServerResponse response; EventBus eventBus; @Override public void start() throws Exception { server = vertx.createHttpServer(); Router router = Router.router(vertx); eventBus = vertx.eventBus(); router.route("/page1").handler(rc -> { response = rc.response(); response.setChunked(true); eventBus.send(MyRestAPIVerticle.ALL_ACCOUNT_LISTING, "Yay! Someone kicked a ball", ar->{ if(ar.succeeded()){ System.out.println("Response is :"+ar.result().body()); } } ); }); server.requestHandler(router::accept).listen(9999);
}
Но после того, как я начал, и посещение/page1, сообщение не может быть отправлено из ServerVerticle в APIVerticle в все. Если я перемещаю потребитель шины данных в ту же самую прямую, что и «Отправитель», событие может быть получено.
Неправильно ли здесь что-то не так, отправляя сообщение между двумя вертикалями? Как я могу заставить его работать?
Заранее спасибо.