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

时间:2015-06-05 07:14:27

标签: java mysql vert.x

我希望在从调用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();

从此获得回复(真/假)之后我想部署模块,但在收到回复之前,我的垂直部署正在部署。

1 个答案:

答案 0 :(得分:0)

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

// ...
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
      }
    }
  }
);