Search in sources :

Example 1 with IpcData

use of io.vertx.up.atom.flux.IpcData in project vertx-zero by silentbalanceyh.

the class DataEncap method consume.

/**
 * Middle process
 *
 * @param request
 * @param type
 */
public static IpcData consume(final IpcRequest request, final IpcType type) {
    final IpcData ipcData = new IpcData();
    final IpcEnvelop envelop = request.getEnvelop();
    final String data = envelop.getBody();
    final JsonObject json = new JsonObject(data);
    // Address convert
    if (json.containsKey("address")) {
        ipcData.setAddress(json.getString("address"));
        json.remove("address");
    }
    ipcData.setData(Buffer.buffer(data));
    ipcData.setType(type);
    return ipcData;
}
Also used : JsonObject(io.vertx.core.json.JsonObject) IpcEnvelop(io.vertx.tp.ipc.eon.IpcEnvelop) IpcData(io.vertx.up.atom.flux.IpcData)

Example 2 with IpcData

use of io.vertx.up.atom.flux.IpcData in project vertx-zero by silentbalanceyh.

the class UnityTunnel method build.

private IpcData build(final Envelop community, final Envelop envelop) {
    // Headers and user could not be modified
    if (null != envelop) {
        community.setHeaders(envelop.headers());
        community.setUser(envelop.user());
    }
    // IpcResponse -> Output Envelop
    final IpcData responseData = new IpcData();
    responseData.setType(IpcType.UNITY);
    DataEncap.in(responseData, community);
    return responseData;
}
Also used : IpcData(io.vertx.up.atom.flux.IpcData)

Example 3 with IpcData

use of io.vertx.up.atom.flux.IpcData 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 4 with IpcData

use of io.vertx.up.atom.flux.IpcData in project vertx-zero by silentbalanceyh.

the class UnityTunnel method init.

@Override
public BindableService init(final Vertx vertx) {
    return new UnityServiceGrpc.UnityServiceVertxImplBase() {

        @Override
        public void unityCall(final IpcRequest request, final Future<IpcResponse> future) {
            // IpcData building
            final IpcData data = DataEncap.consume(request, IpcType.UNITY);
            // Method called with message handler
            final Envelop envelop = DataEncap.consume(data);
            // Method handle
            final Method method = IPCS.get(data.getAddress());
            // Work mode
            if (null == method) {
                // No Rpc Handler here
                final Envelop community = Envelop.failure(new _501RpcMethodMissingException(this.getClass(), data.getAddress()));
                // Build IpcData
                final IpcData responseData = UnityTunnel.this.build(community, envelop);
                future.complete(DataEncap.out(responseData));
            } else {
                // Execute Transit
                final Transit transit = UnityTunnel.this.getTransit(method, vertx);
                // Execute Transit
                final Future<Envelop> result = transit.async(envelop);
                result.setHandler(res -> {
                    final IpcData responseData = UnityTunnel.this.build(res.result(), envelop);
                    future.complete(DataEncap.out(responseData));
                });
            }
        }
    };
}
Also used : Envelop(io.vertx.up.atom.Envelop) Future(io.vertx.core.Future) Method(java.lang.reflect.Method) io.vertx.up.exception._501RpcMethodMissingException(io.vertx.up.exception._501RpcMethodMissingException) Transit(io.vertx.up.micro.ipc.tower.Transit) NodeTransit(io.vertx.up.micro.ipc.tower.NodeTransit) FinalTransit(io.vertx.up.micro.ipc.tower.FinalTransit) IpcRequest(io.vertx.tp.ipc.eon.IpcRequest) IpcData(io.vertx.up.atom.flux.IpcData)

Example 5 with IpcData

use of io.vertx.up.atom.flux.IpcData 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

IpcData (io.vertx.up.atom.flux.IpcData)5 JsonObject (io.vertx.core.json.JsonObject)2 Record (io.vertx.servicediscovery.Record)2 IpcType (io.vertx.up.eon.em.IpcType)2 Future (io.vertx.core.Future)1 IpcEnvelop (io.vertx.tp.ipc.eon.IpcEnvelop)1 IpcRequest (io.vertx.tp.ipc.eon.IpcRequest)1 Envelop (io.vertx.up.atom.Envelop)1 io.vertx.up.exception._501RpcMethodMissingException (io.vertx.up.exception._501RpcMethodMissingException)1 FinalTransit (io.vertx.up.micro.ipc.tower.FinalTransit)1 NodeTransit (io.vertx.up.micro.ipc.tower.NodeTransit)1 Transit (io.vertx.up.micro.ipc.tower.Transit)1 RpcStub (io.vertx.up.plugin.rpc.client.RpcStub)1 Method (java.lang.reflect.Method)1