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();
}
}); 这里查看示例 更新内容: 下载地址: |