vertx deploy vertical after getting reply from event bus

1k views Asked by At

I want to deploy vertical after getting reply from my event bus which is calling mysql module.


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();

After getting reply(true/false) from this i want to deploy module, but before getting reply from this my vertical is getting deployed.

1

There are 1 answers

0
tmarwen On BEST ANSWER

You have to include your deployment method within the body of the response handler so that it gets called once the event bus has sent the message, received a response and inspected the response message body:

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