2016-09-30 39 views
1

我有兩個Verticle說「A」和「B」。兩者都在不同的JVM實例中運行。 現在,A發送消息給B「操作成功,您可以取消部署自己」。當B得到這個消息時,它應該自行解除部署。Vertex 3:取消部署在不同JVM實例中運行的Verticle

我試過兩個選擇: 1. vertx.close(); (a)如果Verticle B在不同的命令提示符下打開。 (b)如果Verticle B在其他命令提示符下未打開。 2. vertx.undeploy(deploymentID(),); Verticle B打開爲不同的cmd提示符以及相同的cmd提示符(Verticle cmd提示...在後臺運行)

在1 - >(a)中,Verticle B已關閉,但cmd提示符仍處於打開狀態。 在1 - >(b)中,Verticle B未關閉,JVM也在運行。 在第二種情況下,我得到了以下錯誤消息:

java.lang.IllegalStateException: Unknown deployment 
     at io.vertx.core.impl.DeploymentManager.undeployVerticle(DeploymentManager.java:203) 
     at io.vertx.core.impl.VertxImpl.undeploy(VertxImpl.java:587) 
     at x.y.z.AVerticle.lambda$null$1(AVerticle.java:118) 
     at io.vertx.core.eventbus.impl.EventBusImpl.lambda$convertHandler$1(EventBusImpl.java:334) 
     at io.vertx.core.eventbus.impl.HandlerRegistration.deliver(HandlerRegistration.java:213) 
     at io.vertx.core.eventbus.impl.HandlerRegistration.handle(HandlerRegistration.java:192) 
     at io.vertx.core.eventbus.impl.EventBusImpl.lambda$deliverToHandler$3(EventBusImpl.java:503) 
     at io.vertx.core.impl.ContextImpl.lambda$wrapTask$3(ContextImpl.java:359) 
     at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:339) 
     at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:393) 
     at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742) 
     at java.lang.Thread.run(Unknown Source) 

任何人知道如何做到這一點? 謝謝:)

+0

不確定這是什麼用例。從事件總線收到消息時,您可以簡單地停用Verticle。用狀態的布爾型字段。 – tsegismont

回答

2

我做了一個類似案例的例子,其中的要求是取消部署,然後終止jvm。

https://github.com/floriankammermann/vertx-examples/tree/master/self-terminating 您也可以使用此代碼。您只需刪除https://github.com/floriankammermann/vertx-examples/blob/master/self-terminating/src/main/java/org/swisspush/vertx/examples/SelfTerminated.java中的System.exit(0);

此處的一個限制是,您已經以編程方式部署了Verticle。

在您的情況下,必須通過分佈式事件總線連接Vertica A和B(可以互相發送消息)。 verticle doSomething.js是你的案例中的verticle B.無論在哪裏部署Verticle A都無關緊要。 Verticle A必須做的唯一事情是發送/發佈消息到地址「已完成」。這將取消部署Verticle B.

+0

感謝您的回覆。 但在我的要求中,兩個垂直都是獨立的,所以我不能以編程方式部署它,如你所示。 –

+0

這應該不成問題。我擴大了我的答案,你可以看到它的工作原理。 – haschibaschi

相關問題