Search in sources :

Example 1 with RpcStub

use of io.vertx.up.plugin.rpc.client.RpcStub in project vertx-zero by silentbalanceyh.

the class RpcClientImpl method connect.

@Override
public RpcClient connect(final JsonObject config, final JsonObject data, final Handler<AsyncResult<JsonObject>> handler) {
    final Record record = RpcHelper.getRecord(config);
    // Service Configuration
    final String name = config.getString(Key.NAME);
    final String address = config.getString(Key.ADDR);
    final JsonObject normalized = RpcHelper.normalize(name, config, record);
    this.holder = this.lookupHolder(this.vertx, name, normalized);
    // Get Channel
    final IpcType type = Ut.toEnum(IpcType.class, config.getString(Key.TYPE));
    final RpcStub stub = this.getStub(type);
    // Future result return to client.
    final IpcData request = new IpcData();
    request.setType(type);
    request.setAddress(address);
    // The same operation for request.
    DataEncap.in(request, record);
    DataEncap.in(request, Envelop.success(data));
    LOGGER.info(Info.CLIENT_TRAFFIC, request.toString());
    final Future<JsonObject> future = stub.traffic(request);
    future.setHandler(res -> handler.handle(Future.succeededFuture(res.result())));
    return this;
}
Also used : IpcType(io.vertx.up.eon.em.IpcType) JsonObject(io.vertx.core.json.JsonObject) Record(io.vertx.servicediscovery.Record) RpcStub(io.vertx.up.plugin.rpc.client.RpcStub) IpcData(io.vertx.up.atom.flux.IpcData)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)1 Record (io.vertx.servicediscovery.Record)1 IpcData (io.vertx.up.atom.flux.IpcData)1 IpcType (io.vertx.up.eon.em.IpcType)1 RpcStub (io.vertx.up.plugin.rpc.client.RpcStub)1