vertx 命令行集群啟動


window 測試   總結

 

去官網下載 vert.x-3.5.0-full.zip http://vertx.io/

 

解壓出來的 lib問價夾里得有  vertx-hazelcast-3.5.0.jar(沒有自己下個放入)

 

將 bin文件夾放入 path環境變量

 

寫2個簡單  verticle  如

接受請求的  和  業務處理的

 1 import io.vertx.core.AbstractVerticle;
 2 import io.vertx.core.http.HttpMethod;
 3 import io.vertx.core.http.HttpServer;
 4 
 5 public class AuthVerticle extends AbstractVerticle {
 6     
 7   @Override
 8   public void start() throws Exception {
 9     super.start();
10     HttpServer server = vertx.createHttpServer();
11     server.requestHandler(req -> {
12       if (req.method() == HttpMethod.GET) {
13         req.response().setChunked(true);
14         if (req.path().equals("/hello")) {
15           vertx.eventBus().<String>send(GoNextVerticle.XWHB_AUTH_GO, "之后用於傳輸的數據", result -> {
16             if (result.succeeded()) {
17               req.response().setStatusCode(200).write(result.result().body()).end();
18             } else {
19               req.response().setStatusCode(500).write(result.cause().toString()).end();
20             }
21           });
22         } else {
23              req.response().setStatusCode(405).end();
24         }
25       } else {
26         req.response().setStatusCode(405).end();
27       }
28     });
29     server.listen(9090);
30   }
31 }
public class GoNextVerticle extends AbstractVerticle {

  public static final String XWHB_AUTH_GO = "go";
  
  private Handler<Message<String>> DoSomeThingHandler() {      
    return msg -> {
        msg.reply("hello");
    };
  }

  @Override
  public void start() throws Exception {
    super.start();
    vertx.eventBus().<String>consumer(XWHB_AUTH_GO).handler(DoSomeThingHandler());
  }

}

 

打個fat包   別用有帶這個的  如

<!-- the main verticle class name -->
<main.class>com.xwhb.auth.Runner</main.class>

pom文件里也別帶

<dependency>
  <groupId>io.vertx</groupId>
  <artifactId>vertx-hazelcast</artifactId>
  <version>xxx</version>
</dependency>

以下發布集群方式貌似是廣播方式   只能在同網段 

發布這個到集群  這個AuthVeticle就只發布一個(沒有設置 --instances 着默認一個)                                        

vertx run com.xwhb.httpdemonet.verticles.AuthVerticle

-cp xwhb-httpdemonet-1.0-SNAPSHOT-fat.jar

                    在集群中暴露的端口 

--cluster --cluster-host 192.168.1.6 --cluster-port 9091

        本機ip,別用localhost     

                                        

再找同網段的另一台機器(假如是4核)發布GoNextVerticle 發布4個  (利用好4個核)

vertx run com.xwhb.httpdemonet.verticles.GoNextVerticle -cp xwhb-httpdemonet-1.0-SNAPSHOT-fat.jar  --cluster --cluster-host 192.168.1.15 --cluster-port 9092  --instances 4

 

瀏覽器訪問   http://127.0.0.1:9090/hello

 

內容暫時這樣   之后再改 可能有錯誤 開放評論

順便放個demo    鏈接:https://pan.baidu.com/s/1pKGwSCN 密碼:sutj


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM