Search in sources :

Example 1 with IpcType

use of io.vertx.up.eon.em.IpcType 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)

Example 2 with IpcType

use of io.vertx.up.eon.em.IpcType in project vertx-zero by silentbalanceyh.

the class TunnelClient method send.

public Future<Envelop> send(final Envelop envelop) {
    // 1. Extract address
    final String address = this.getValue("to");
    final IpcType type = this.getValue("type");
    // 2. Record extract
    final Record record = this.findTarget();
    // 3. Convert IpcData
    final IpcData data = new IpcData();
    data.setType(type);
    data.setAddress(address);
    // 4. In data
    DataEncap.in(data, record);
    DataEncap.in(data, envelop);
    // 5. Stub
    final Spear stub = STUBS.getOrDefault(type, Instance.singleton(UnitySpear.class));
    return stub.send(this.vertx, data);
}
Also used : IpcType(io.vertx.up.eon.em.IpcType) Record(io.vertx.servicediscovery.Record) IpcData(io.vertx.up.atom.flux.IpcData)

Aggregations

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