Search in sources :

Example 21 with DeliveryOptions

use of io.vertx.core.eventbus.DeliveryOptions in project VX-API-Gateway by EliMirren.

the class ClientVerticle method startAllAPI.

/**
 * 启动所有API
 *
 * @param rct
 */
public void startAllAPI(RoutingContext rct) {
    String appName = rct.request().getParam("appName");
    HttpServerResponse response = rct.response().putHeader(CONTENT_TYPE, CONTENT_VALUE_JSON_UTF8);
    if (StrUtil.isNullOrEmpty(appName)) {
        response.end(ResultFormat.formatAsZero(HTTPStatusCodeMsgEnum.C1400));
    } else {
        LOG.info(MessageFormat.format("[user : {0}] 执行启动应用{1}:所有API..", rct.session().get("userName"), appName));
        // 用于获取所有API的参数
        JsonObject message = new JsonObject().put("appName", appName);
        // 获取所有API
        vertx.eventBus().<JsonArray>send(thisVertxName + VxApiEventBusAddressConstant.FIND_API_ALL, message, data -> {
            if (data.succeeded()) {
                JsonArray body = data.result().body();
                DeliveryOptions option = new DeliveryOptions();
                option.setSendTimeout(200 * 301);
                JsonObject config = new JsonObject();
                config.put("appName", appName);
                config.put("apis", body);
                vertx.eventBus().<String>send(thisVertxName + VxApiEventBusAddressConstant.DEPLOY_API_START_ALL, config, option, reply -> {
                    if (reply.succeeded()) {
                        LOG.info(MessageFormat.format("[user : {0}] 执行启动应用{1}:所有API-->成功", rct.session().get("userName"), appName));
                        response.end(ResultFormat.format(HTTPStatusCodeMsgEnum.C200, reply.result().body()));
                        if (vertx.isClustered()) {
                            vertx.eventBus().publish(VxApiEventBusAddressConstant.DEPLOY_API_START_ALL, config.copy().put("thisVertxName", thisVertxName));
                            LOG.info("广播通知集群环境中 应用:" + appName + ",启动所有API");
                        }
                    } else {
                        LOG.error(MessageFormat.format("[user : {0}] 执行启动所有API-->查看API:{1}-->失败:{2}", rct.session().get("userName"), appName, reply.cause().toString()));
                        response.end(ResultFormat.format(HTTPStatusCodeMsgEnum.C500, reply.cause().toString()));
                    }
                });
            } else {
                LOG.error(MessageFormat.format("[user : {0}] 执行启动所有API-->查看API:{1}-->失败:{2}", rct.session().get("userName"), appName, data.cause().toString()));
                response.end(ResultFormat.format(HTTPStatusCodeMsgEnum.C500, data.cause().toString()));
            }
        });
    }
}
Also used : JsonArray(io.vertx.core.json.JsonArray) HttpServerResponse(io.vertx.core.http.HttpServerResponse) JsonObject(io.vertx.core.json.JsonObject) DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions)

Example 22 with DeliveryOptions

use of io.vertx.core.eventbus.DeliveryOptions in project VX-API-Gateway by EliMirren.

the class CLIVerticle method startAllAPI.

/**
 * 启动所有API
 *
 * @param appName
 *          应用的名称
 */
public void startAllAPI(String appName) {
    if (StrUtil.isNullOrEmpty(appName)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("cli->执行启动网关应用->启动所有API-->失败:应用名称为空");
        }
        return;
    }
    // 获取所有API
    JsonObject message = new JsonObject().put("appName", appName);
    vertx.eventBus().<JsonArray>send(thisVertxName + VxApiEventBusAddressConstant.FIND_API_ALL, message, reply -> {
        if (reply.succeeded()) {
            JsonArray apis = reply.result().body();
            DeliveryOptions option = new DeliveryOptions();
            option.setSendTimeout(200 * 301);
            JsonObject config = new JsonObject();
            config.put("appName", appName);
            config.put("apis", apis);
            String startApiAddress = thisVertxName + VxApiEventBusAddressConstant.DEPLOY_API_START_ALL;
            vertx.eventBus().<String>send(startApiAddress, config, option, res -> {
                if (res.succeeded()) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("cli->执行启动网关应用:" + appName + "->启动所有API-->成功");
                    }
                } else {
                    LOG.error("cli->执行启动网关应用:" + appName + "->启动所有API-->失败:" + reply.cause());
                }
            });
        } else {
            LOG.error("cli->执行启动网关应用:" + appName + "->获取所有API-->失败:" + reply.cause());
        }
    });
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions)

Example 23 with DeliveryOptions

use of io.vertx.core.eventbus.DeliveryOptions in project mod-invoice by folio-org.

the class AbstractHelper method sendEvent.

protected void sendEvent(MessageAddress messageAddress, JsonObject data) {
    DeliveryOptions deliveryOptions = new DeliveryOptions();
    // Add okapi headers
    okapiHeaders.forEach(deliveryOptions::addHeader);
    data.put(LANG, lang);
    ctx.owner().eventBus().send(messageAddress.address, data, deliveryOptions);
}
Also used : DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions)

Example 24 with DeliveryOptions

use of io.vertx.core.eventbus.DeliveryOptions in project vertx-zero by silentbalanceyh.

the class DeployRotate method spinDelivery.

@Override
public DeliveryOptions spinDelivery() {
    final DeliveryOptions options = new DeliveryOptions();
    options.setSendTimeout(delivery.getLong("timeout", options.getSendTimeout()));
    return options;
}
Also used : DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions)

Example 25 with DeliveryOptions

use of io.vertx.core.eventbus.DeliveryOptions in project mod-orders by folio-org.

the class HelperUtils method sendEvent.

public static void sendEvent(MessageAddress messageAddress, JsonObject data, RequestContext requestContext) {
    DeliveryOptions deliveryOptions = new DeliveryOptions();
    // Add okapi headers
    Map<String, String> okapiHeaders = requestContext.getHeaders();
    okapiHeaders.forEach(deliveryOptions::addHeader);
    data.put(LANG, EN);
    requestContext.getContext().owner().eventBus().send(messageAddress.address, data, deliveryOptions);
}
Also used : DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions)

Aggregations

DeliveryOptions (io.vertx.core.eventbus.DeliveryOptions)96 JsonObject (io.vertx.core.json.JsonObject)39 Message (io.vertx.core.eventbus.Message)23 EventBus (io.vertx.core.eventbus.EventBus)21 Test (org.junit.Test)20 JsonArray (io.vertx.core.json.JsonArray)17 CountDownLatch (java.util.concurrent.CountDownLatch)16 Handler (io.vertx.core.Handler)15 AsyncResult (io.vertx.core.AsyncResult)14 Utils.handlerToAsyncHandler (fr.wseduc.webutils.Utils.handlerToAsyncHandler)10 Vertx (io.vertx.core.Vertx)10 Either (fr.wseduc.webutils.Either)9 Context (io.vertx.core.Context)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 Buffer (io.vertx.core.buffer.Buffer)8 MultiMap (io.vertx.core.MultiMap)7 Span (io.vertx.test.faketracer.Span)6 java.util (java.util)6 io.vertx.core (io.vertx.core)5 Future (io.vertx.core.Future)5