1. XenForo 1.5.14 中文版——支持中文搜索!现已发布!查看详情
  2. Xenforo 爱好者讨论群:215909318 XenForo专区

新闻 Vert.x 3.5.0.Beta1 发布,基于 JVM 的 Node 替代者 下载

Discussion in '软件资讯' started by 漂亮的石头, 2017-08-12.

  1. 漂亮的石头

    漂亮的石头 版主 Staff Member

    Joined:
    2012-02-10
    Messages:
    488,019
    Likes Received:
    47
    Vert.x 3.5.0.Beta1 发布了。Vert.x 是一个用于下一代异步、可伸缩、并发应用的框架,旨在为JVM提供一个Node.js的替代方案。开发者可以通过它使用JavaScript、Ruby、Groovy、Java、甚至是混合语言来编写应用。

    RxJava2


    首先,此版本提供了 RxJava2 API,支持其全系列类型。

    除了 Single,Rxified API 还有 Completable 和 Maybe 类型

    // expose Handler<AsyncResult<Void>>Completable completable = server.rxClose();

    completable.subscribe(() -> System.out.println("closed"));

    // expose Handler<AsyncResult<String>> where the result can be nullMaybe<String> ipAddress = dnsClient.rxLookup("www.google.com");
    ipAddress.subscribe(
    value -> System.out.println("resolved to " + value),
    err -> err.printStackTrace(),
    () -> System.out.println("does not resolve"));

    RxJava 使用 toObservable() 方法来扩展 Vert.x 流,RxJava2 添加了 toFlowable() 方法:

    // Flowable maps to a ReadStream<Buffer>// back-pressured streamFlowable flowable = asyncFile.toFlowable();// but we still can get an Observable<Buffer>// non back-pressured streamObservable flowable = asyncFile.toObservable();

    文档示例

    MQTT Client


    在 Vert.x 3.4 中,我们添加了 MQTT 服务器,3.5 使用 MQTT 客户端完成 MQTT 代理:

    MqttClient mqttClient = MqttClient.create(vertx, new MqttClientOptions()
    .setPort(BROKER_PORT)
    .setHost(BROKER_HOST)).connect(ar -> if (ar.succeeded()) {
    System.out.println("Connected to a server");

    mqttClient.publish(
    MQTT_TOPIC,
    Buffer.buffer(MQTT_MESSAGE),
    MqttQoS.AT_MOST_ONCE, false, false,
    s -> mqttClient.disconnect(d -> System.out.println("Disconnected from server")));
    } else {
    System.out.println("Failed to connect to a server");
    ar.cause().printStackTrace();
    }
    });

    这里查看示例

    更新内容:


    下载地址:

    Vert.x 3.5.0.Beta1 发布,基于 JVM 的 Node 替代者下载地址
     
Loading...