1

我正在做一个关于如何使用 Vert.x 事件总线的演示。但是,消息不会发送给消费者。我得到的只是

没有地址 hello 的处理程序

当我调用服务时,这是消费者,这是我正在遵循的确切示例,以及我是如何运行它的。

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

我运行带有集群标志的verticle,如示例中所述,

mvn compile vertx:run -Dvertx.runArgs="-cluster -Djava.net.preferIPv4Stack=true

下面是第一个verticle的日志

[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 compile 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/上调用应用程序,我仍然得到 No handlers for address hello

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

下面是我在两种服务中使用的 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>
4

1 回答 1

0

在与@tsegismont 聊天之后,运行没有 jgroups.xml 文件的应用程序就可以解决问题。

于 2019-05-28T09:55:20.900 回答