使用Vert.x事件总线时,没有用于地址“演示”的处理程序

时间:2019-05-24 10:45:59

标签: vert.x vertx-verticle vertx-eventbus

我正在演示如何使用Vert.x事件总线。但是,消息不会发送给使用者。我只有

  

没有地址问候句柄

当我调用该服务时,这是消费者,这是我要遵循的确切示例以及运行方式。

public class HelloMicroservice extends AbstractVerticle {

    @Override
    public void start() {
        vertx.eventBus().<String>consumer("hello", message -> {
            JsonObject json = new JsonObject()
                    .put("served-by", this.toString());
            if (message.body().isEmpty()) {
                message.reply(json.put("message", "hello"));
            } else {
                message.reply(json.put("message", "hello " + message.body()));
            }
        });
    }
}

我像这样的示例中所描述的那样,使用簇标志运行垂直线,

  

mvn编译vertx:run -Dvertx.runArgs =“-cluster -Djava.net.preferIPv4Stack = true

下面是第一个顶点的日志

[INFO] Launching Vert.x Application
[INFO] Vert.x application redeploy enabled
[INFO] No plugin execution collected. The vertx:initialize goal has not been run beforehand. Only handling resources and java compilation
[INFO] Observing path:/Users/isaack/reactivejava_ws/message_driven_ms/src/main
[INFO] May 24, 2019 1:31:42 PM io.vertx.core.impl.launcher.commands.Watcher
[INFO] INFO: Watched paths: [/Users/isaack/reactivejava_ws/message_driven_ms/target/classes]
[INFO] May 24, 2019 1:31:42 PM io.vertx.core.impl.launcher.commands.Watcher
[INFO] INFO: Starting the vert.x application in redeploy mode
[INFO] Starting vert.x application...
[INFO] bd066fa5-6786-45dc-9044-b08adbf80cb9-redeploy
[INFO] May 24, 2019 1:31:43 PM io.vertx.core.impl.launcher.commands.RunCommand
[INFO] INFO: Starting clustering...
[INFO] May 24, 2019 1:31:43 PM io.vertx.core.impl.launcher.commands.RunCommand
[INFO] INFO: No cluster-host specified so using address 172.16.7.108
[INFO] May 24, 2019 1:31:44 PM org.infinispan.remoting.transport.jgroups.JGroupsTransport start
[INFO] INFO: ISPN000078: Starting JGroups channel ISPN
[INFO] May 24, 2019 1:31:49 PM org.infinispan.remoting.transport.jgroups.JGroupsTransport viewAccepted
[INFO] INFO: ISPN000094: Received new cluster view for channel ISPN: [Isaacs-MacBook-Pro-2-55471|0] (1) [Isaacs-MacBook-Pro-2-55471]
[INFO] May 24, 2019 1:31:49 PM org.infinispan.remoting.transport.jgroups.JGroupsTransport startJGroupsChannelIfNeeded
[INFO] INFO: ISPN000079: Channel ISPN local address is Isaacs-MacBook-Pro-2-55471, physical addresses are [127.0.0.1:7801]
[INFO] May 24, 2019 1:31:49 PM org.infinispan.factories.GlobalComponentRegistry start
[INFO] INFO: ISPN000128: Infinispan version: Infinispan 'Ruppaner' 9.0.0.CR2
[INFO] May 24, 2019 1:31:49 PM org.infinispan.expiration.impl.ExpirationManagerImpl start
[INFO] INFO: ISPN000025: wakeUpInterval is <= 0, not starting expired purge thread
[INFO] May 24, 2019 1:31:49 PM org.infinispan.expiration.impl.ExpirationManagerImpl start
[INFO] INFO: ISPN000025: wakeUpInterval is <= 0, not starting expired purge thread
[INFO] May 24, 2019 1:31:50 PM io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer
[INFO] INFO: Succeeded in deploying verticle

这是向消费者发送一些消息的第二个Verticle,它是一个在本地单独运行的不同项目。

 public class BaseMicroservice extends AbstractVerticle {

    @Override
    public void start() {
        vertx.createHttpServer()
                .requestHandler(
                        req -> {
                            Single<JsonObject> obs1 = vertx.eventBus()
                                    .<JsonObject>rxSend("hello", "Luke")
                                    .map(Message::body);
                            Single<JsonObject> obs2 = vertx.eventBus()
                                    .<JsonObject>rxSend("hello", "Leia")
                                    .map(Message::body);
                            Single.zip(obs1, obs2, (luke, leia) ->
                                            new JsonObject()
                                                    .put("Luke", luke.getString("message")
                                                            + " from " + luke.getString("served-by"))
                                                    .put("Leia", leia.getString("message")
                                                            + " from " + leia.getString("served-by"))
                                    ).subscribe(
                                            x -> req.response().end(x.encodePrettily()),
                                            t -> req.response().setStatusCode(500).end(t.getMessage())
                                    );
                        })
                .listen(8082);
    }

}

我正在使用以下命令运行。

  

mvn编译vertx:run -Dvertx.runArgs =“-cluster   -Djava.net.preferIPv4Stack = true“

[INFO] Launching Vert.x Application
[INFO] Vert.x application redeploy enabled
[INFO] No plugin execution collected. The vertx:initialize goal has not been run beforehand. Only handling resources and java compilation
[INFO] Observing path:/Users/isaack/reactivejava_ws/msg_drvn_consumer/src/main
[INFO] May 24, 2019 1:42:20 PM io.vertx.core.impl.launcher.commands.Watcher
[INFO] INFO: Watched paths: [/Users/isaack/reactivejava_ws/msg_drvn_consumer/target/classes]
[INFO] May 24, 2019 1:42:20 PM io.vertx.core.impl.launcher.commands.Watcher
[INFO] INFO: Starting the vert.x application in redeploy mode
[INFO] Starting vert.x application...
[INFO] 2b5bd27b-b5f4-4a2b-a64f-7375f7296cc0-redeploy
[INFO] May 24, 2019 1:42:20 PM io.vertx.core.impl.launcher.commands.RunCommand
[INFO] INFO: Starting clustering...
[INFO] May 24, 2019 1:42:20 PM io.vertx.core.impl.launcher.commands.RunCommand
[INFO] INFO: No cluster-host specified so using address 172.16.7.108
[INFO] May 24, 2019 1:42:21 PM org.infinispan.remoting.transport.jgroups.JGroupsTransport start
[INFO] INFO: ISPN000078: Starting JGroups channel ISPN
[INFO] May 24, 2019 1:42:21 PM org.infinispan.remoting.transport.jgroups.JGroupsTransport buildChannel
[INFO] WARN: ISPN000304: More than one configuration file with specified name on classpath. The first one will be used:
[INFO]  [file:/Users/isaack/reactivejava_ws/msg_drvn_consumer/src/main/resources/jgroups.xml, file:/Users/isaack/reactivejava_ws/msg_drvn_consumer/target/classes/jgroups.xml, jar:file:/Users/isaack/.m2/repository/io/vertx/vertx-infinispan/3.4.0/vertx-infinispan-3.4.0.jar!/jgroups.xml]
[INFO] May 24, 2019 1:42:27 PM org.infinispan.remoting.transport.jgroups.JGroupsTransport viewAccepted
[INFO] INFO: ISPN000094: Received new cluster view for channel ISPN: [Isaacs-MacBook-Pro-2-48763|0] (1) [Isaacs-MacBook-Pro-2-48763]
[INFO] May 24, 2019 1:42:27 PM org.infinispan.remoting.transport.jgroups.JGroupsTransport startJGroupsChannelIfNeeded
[INFO] INFO: ISPN000079: Channel ISPN local address is Isaacs-MacBook-Pro-2-48763, physical addresses are [127.0.0.1:7800]
[INFO] May 24, 2019 1:42:27 PM org.infinispan.factories.GlobalComponentRegistry start
[INFO] INFO: ISPN000128: Infinispan version: Infinispan 'Ruppaner' 9.0.0.CR2
[INFO] May 24, 2019 1:42:27 PM org.infinispan.expiration.impl.ExpirationManagerImpl start
[INFO] INFO: ISPN000025: wakeUpInterval is <= 0, not starting expired purge thread
[INFO] May 24, 2019 1:42:27 PM org.infinispan.expiration.impl.ExpirationManagerImpl start
[INFO] INFO: ISPN000025: wakeUpInterval is <= 0, not starting expired purge thread
[INFO] May 24, 2019 1:42:28 PM io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer
[INFO] INFO: Succeeded in deploying verticle

尝试在http://localhost:8082/上调用该应用程序,仍然可以 没有地址问候语处理程序

我已经尝试过this,但是我已经添加了集群标志并且它不起作用。谢谢。

下面是我在两个服务中都用作响应的jgroups.xml注释,仍然非常感谢任何帮助。它在我的资源文件夹中

<?xml version="1.0" encoding="UTF-8"?>
<!--

 This jgroup configuration discovers only nodes running on the local machine using the 127.0.0.1 local address.
 It does not use multicast, but unicast.

-->
<config xmlns="urn:org:jgroups"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups-4.0.xsd">
  <TCP bind_addr="127.0.0.1"
       bind_port="7800"
  />
  <TCPPING port_range="5"/>
  <MERGE3 min_interval="10000"
          max_interval="30000"
  />
  <FD_SOCK/>
  <FD_ALL timeout="60000"
          interval="15000"
          timeout_check_interval="5000"
  />
  <VERIFY_SUSPECT timeout="5000"/>
  <pbcast.NAKACK2 use_mcast_xmit="false"
                  xmit_interval="1000"
                  xmit_table_num_rows="50"
                  xmit_table_msgs_per_row="1024"
                  xmit_table_max_compaction_time="30000"
                  resend_last_seqno="true"
  />
  <UNICAST3 xmit_interval="500"
            xmit_table_num_rows="50"
            xmit_table_msgs_per_row="1024"
            xmit_table_max_compaction_time="30000"
            conn_expiry_timeout="0"
  />
  <pbcast.STABLE stability_delay="500"
                 desired_avg_gossip="5000"
                 max_bytes="1M"
  />
  <pbcast.GMS print_local_addr="false"
              join_timeout="${jgroups.join_timeout:5000}"
  />
  <MFC max_credits="2m"
       min_threshold="0.40"
  />
  <CENTRAL_LOCK use_thread_id_for_lock_owner="false" bypass_bundling="true"/>
  <COUNTER bypass_bundling="true"/>
</config>

1 个答案:

答案 0 :(得分:0)

与@tsegismont聊天之后,无需jgroups.xml文件即可运行应用程序。