关于 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

本文档介绍了如何使用Java实现Vert.x-tcp-eventbus-bridge的示例,包括pom配置、MainVerticle、TcpServerVerticle和TcpClientVerticle四个关键文件的详细说明。在理解官方文档的基础上,通过重写Groovy示例转为Java代码,阐述了如何不依赖Vert.x库直接利用Java TCP进行通信的方法。
最低0.47元/天 解锁文章
757





