从事件总线获得回复后,vertx 垂直部署

vertx deploy vertical after getting reply from event bus

我想在收到调用 mysql 模块的事件总线的回复后进行垂直部署。


String query = "select * from fca_config WHERE name='siteFaultCollectionStatus'";
JsonObject selectQuery = new JsonObject();
selectQuery.putString(OPERATION.ACTION.Value(), OPERATION.RAW.Value());
selectQuery.putString(OPERATION.COMMAND.Value(), query);
List<String> list = new ArrayList<String>();
list.add("siteFaultCollectionStatus");

System.out.println(selectQuery);

EventBus eb = vertx.eventBus();
eb.send("database.mysql", selectQuery, new Handler<Message<JsonObject>>() {
  public void handle(Message<JsonObject> result) {
      String results = result.body().getArray("results").toString();
      String arrs[]=results.split(",");
    System.out.println("I received a reply before the timeout of 5 seconds"+arrs[1]);
    res=arrs[1];
    }
});
if(res.equals("true")){
   deployVerticles();

收到回复(true/false)后,我想部署模块,但在收到回复之前,我的垂直领域正在部署。

您必须将部署方法包含在响应处理程序的主体中,以便在事件总线发送消息、收到响应并检查响应消息主体后调用它:

// ...
JsonObject selectQuery /* the query initialization goes here */;
// ...
vertx.eventBus().send(
  "database.mysql", 
  selectQuery, 
  new Handler<Message<JsonObject>>() {
    public void handle(Message<JsonObject> result) {
      String results = result.body().getArray("results").toString();
      String arrs[]=results.split(",");
      System.out.println("I received a reply before the timeout of 5 seconds"+arrs[1]);
      res = arrs[1];
      if(res.equals("true")) {
        deployVerticles(); // Triggering verticle deployment goes within your response handler
      }
    }
  }
);