红联Linux门户
Linux帮助

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

发布时间:2017-08-12 09:12:49来源:红联作者:baihuo
Vert.x 3.5.0.Beta1 发布了。Vert.x 是一个用于下一代异步、可伸缩、并发应用的框架,旨在为JVM提供一个Node.js的替代方案。开发者可以通过它使用JavaScript、Ruby、Groovy、Java、甚至是混合语言来编写应用。
RxJava2

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

除了 Single,Rxified API 还有 Completable 和 Maybe 类型[code]// expose Handler>Completable completable = server.rxClose();

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

// expose Handler> where the result can be nullMaybe ipAddress = dnsClient.rxLookup("www.google.com");
ipAddress.subscribe(
value -> System.out.println("resolved to " + value),
err -> err.printStackTrace(),
() -> System.out.println("does not resolve"));[/code]RxJava 使用 toObservable() 方法来扩展 Vert.x 流,RxJava2 添加了 toFlowable() 方法:[code]// Flowable maps to a ReadStream// back-pressured streamFlowable flowable = asyncFile.toFlowable();// but we still can get an Observable// non back-pressured streamObservable flowable = asyncFile.toObservable();[/code]文档和示例
MQTT Client

在 Vert.x 3.4 中,我们添加了 MQTT 服务器,3.5 使用 MQTT 客户端完成 MQTT 代理:[code]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();
}
});[/code]更新内容:

http://vertx.io/blog/vert-x-3-5-0-beta1/

下载地址:

http://vertx.io/download/

软件详情:https://github.com/vert-x3/vertx-examples/tree/3.5.0.beta1/mqtt-examples

来自:开源中国社区
文章评论

共有 0 条评论