关于 Vert.x-tcp-eventbus-bridge 的详细用法,Vert.x 的官方文档(官方文档1、官方文档2)都写得很简单,简单得还是让人搞不懂如何使用。
从网上找到了一篇介绍如何使用的文章:Vert.x TCP EventBus Bridge补遗。该项目中的例子源码在 github 上。看了源码之后,发现是一个 groovy项目。于是就将例子用 Java 代码重新写了下。总共有如下几个文件:
1. pom 文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.example</groupId>
<artifactId>vertx-example</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<vertx.version>3.4.2</vertx.version>
<main.class>io.vertx.core.Launcher</main.class>
<main.verticle>io.example.MainVerticle</main.verticle>
<guava.version>20.0</guava.version>
</properties>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
<version>${vertx