List of usage examples for io.vertx.core.json JsonObject getString
public String getString(String key, String def)
From source file:com.cyngn.kafka.consume.SimpleConsumer.java
License:Apache License
private Properties populateKafkaConfig(JsonObject config) { Properties consumerConfig = new Properties(); consumerConfig.put(ConfigConstants.ZK_CONNECT, config.getString(ConfigConstants.ZK_CONNECT, "localhost:2181")); consumerConfig.put(ConfigConstants.BACKOFF_INCREMENT_MS, config.getString(ConfigConstants.BACKOFF_INCREMENT_MS, "100")); consumerConfig.put(ConfigConstants.AUTO_OFFSET_RESET, config.getString(ConfigConstants.AUTO_OFFSET_RESET, "smallest")); consumerConfig.put(ConfigConstants.BOOTSTRAP_SERVERS, getRequiredConfig(ConfigConstants.BOOTSTRAP_SERVERS)); consumerConfig.put(ConfigConstants.KEY_DESERIALIZER_CLASS, config .getString(ConfigConstants.KEY_DESERIALIZER_CLASS, ConfigConstants.DEFAULT_DESERIALIZER_CLASS)); consumerConfig.put(ConfigConstants.VALUE_DESERIALIZER_CLASS, config .getString(ConfigConstants.VALUE_DESERIALIZER_CLASS, ConfigConstants.DEFAULT_DESERIALIZER_CLASS)); consumerConfig.put(ConfigConstants.GROUP_ID, getRequiredConfig(ConfigConstants.GROUP_ID)); return consumerConfig; }
From source file:com.cyngn.kafka.MessageConsumer.java
License:Apache License
private Properties populateKafkaConfig(JsonObject config) { Properties consumerConfig = new Properties(); consumerConfig.put(ConfigConstants.ZK_CONNECT, config.getString(ConfigConstants.ZK_CONNECT, "localhost:2181")); consumerConfig.put(ConfigConstants.BACKOFF_INCREMENT_MS, config.getString(ConfigConstants.BACKOFF_INCREMENT_MS, "100")); consumerConfig.put(ConfigConstants.BACKOFF_INCREMENT_MS, config.getString(ConfigConstants.AUTO_OFFSET_RESET, "smallest")); consumerConfig.put(ConfigConstants.GROUP_ID, getRequiredConfig(ConfigConstants.GROUP_ID)); return consumerConfig; }
From source file:com.cyngn.vertx.bosun.BosunReporter.java
License:Apache License
@Override public void start(final Future<Void> startedResult) { // setup the default config values JsonObject config = context.config(); hosts = config.getJsonArray("hosts", new JsonArray("[{ \"host\" : \"localhost\", \"port\" : 8070}]")); address = config.getString("address", DEFAULT_ADDRESS); maxTags = config.getInteger("max_tags", OPENTSDB_DEFAULT_MAX_TAGS); maxIndexCacheSize = config.getInteger("max_index_cache_size", DEFAULT_UNIQUE_METRICS_INDEXED); indexExpiryInMinutes = config.getInteger("index_expiry_minutes", DEFAULT_INDEX_EXPIRY_MINUTES); timeout = config.getInteger("default_timeout_ms", DEFAULT_TIMEOUT_MS); metricsIndexed = new AtomicInteger(0); metricsPut = new AtomicInteger(0); metricsErrors = new AtomicInteger(0); eventBus = vertx.eventBus();/*from w ww.j a va 2 s . c o m*/ // create the list of workers connections = new ArrayList<>(hosts.size()); initializeConnections(startedResult); createMessageHandlers(); outputConfig(); // initialize the in memory index cache distinctMetrics = CacheBuilder.newBuilder().maximumSize(maxIndexCacheSize) .expireAfterWrite(DEFAULT_INDEX_EXPIRY_MINUTES, TimeUnit.MINUTES) .build(new CacheLoader<String, Boolean>() { public Boolean load(String key) throws Exception { return true; } }); // start listening for incoming messages eventBus.consumer(address, this); initStatsReporting(); }
From source file:com.cyngn.vertx.opentsdb.service.MetricsParser.java
License:Apache License
/** * Given a event bus message take the metric data from it and create an OpenTsDb string to send to OpenTsDb * * @param message the event bus message/*from w w w.j ava2s. c o m*/ * @param metric the metric object * @return the metric string or null if it is invalid */ @SuppressWarnings("unchecked") public String createMetricString(Message message, JsonObject metric) { String metricName = metric.getString(NAME_FIELD, ""); if (StringUtils.isEmpty(metricName)) { errorHandler.accept(message, "All metrics need a 'name' field"); return null; } String metricValue = metric.getString(VALUE_FIELD, ""); if (metricValue.length() == 0) { errorHandler.accept(message, "All metrics need a 'value' field"); return null; } String tags = getTagString(metric.getJsonObject(TAGS_FIELD)); // this is an OpenTsDB requirement if (StringUtils.isEmpty(tags.trim())) { errorHandler.accept(message, "You must specify at least one tag"); return null; } return getMetricString(metricName, metricValue, tags); }
From source file:com.deblox.server.Server.java
License:Apache License
@Override public void start(Future<Void> startFuture) { logger.info("starting with config: " + config().toString()); Router router = Router.router(vertx); // Allow events for the designated addresses in/out of the event bus bridge BridgeOptions opts = new BridgeOptions().addInboundPermitted(new PermittedOptions()) .addOutboundPermitted(new PermittedOptions()); // Create the event bus bridge and add it to the router. SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler); // broadcast some arbitary message router.post("/api/event").handler(ctx -> { ctx.response().putHeader("content-type", "text/json"); // curl -H "Content-Type: application/json" -X POST -d '{"topic":"release-event", "data":"something"}' localhost:8080/api/event ctx.request().bodyHandler(req -> { try { JsonObject msg = new JsonObject(req.toString()); logger.info(msg);// w w w . j av a 2s. com eb.send(msg.getString("topic", "unknown"), msg.getJsonObject("data"), resp -> { ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, "application/json") .end(resp.result().body().toString()); }); } catch (Exception ex) { logger.error(ex.getMessage()); ctx.fail(500); } }); }); // Serve the static pages router.route().handler(StaticHandler.create().setCachingEnabled(false) .setWebRoot(config().getString("webroot", "webroot")).setDirectoryListing(false)); // the server itself vertx.createHttpServer().requestHandler(router::accept).listen(config().getInteger("port", 8080)); // need a bus! eb = vertx.eventBus(); // send back deployment complete startFuture.complete(); }
From source file:com.github.jackygurui.vertxredissonrepository.provider.RedissonProvider.java
License:Apache License
public static Redisson create(JsonObject jo) { Config redisConfig = new Config(); redisConfig.useSingleServer().setAddress(jo.getString("serverAddress", "localhost:6379")); return (Redisson) Redisson.create(redisConfig); }
From source file:com.glencoesoftware.omero.ms.core.OmeroWebSessionRequestHandler.java
License:Open Source License
/** * Handler implementation whose responsibility is to make the OMERO session * key into the routing context via the <code>omero.session_key</code> * key of the <code>event</code> context dictionary. * @see Handler#handle(Object)//from w w w . j a v a2 s.c o m */ @Override public void handle(RoutingContext event) { // First try to get the OMERO session key from the // `X-OMERO-Session-Key` request header. String sessionKey = event.request().headers().get("X-OMERO-Session-Key"); if (sessionKey != null) { log.debug("OMERO session key from header: {}", sessionKey); event.put("omero.session_key", sessionKey); event.next(); return; } // Next see if it was provided via the `bsession` URL parameter sessionKey = event.request().getParam("bsession"); if (sessionKey != null) { log.debug("OMERO session key from 'bsession' URL parameter: {}", sessionKey); event.put("omero.session_key", sessionKey); event.next(); return; } // Finally, check if we have a standard OMERO.web cookie available to // retrieve the session key from. JsonObject omeroWeb = config.getJsonObject("omero.web", new JsonObject()); String name = omeroWeb.getString("session_cookie_name", "sessionid"); Cookie cookie = event.getCookie(name); if (cookie == null) { event.response().setStatusCode(403); event.response().end(); return; } final String djangoSessionKey = cookie.getValue(); log.debug("OMERO.web session key: {}", djangoSessionKey); sessionStore.getConnectorAsync(djangoSessionKey).whenComplete((connector, throwable) -> { if (throwable != null) { log.error("Exception retrieving connector", throwable); } if (connector == null) { event.response().setStatusCode(403); event.response().end(); return; } event.put("omero.session_key", connector.getOmeroSessionKey()); event.next(); }); }
From source file:com.hubrick.vertx.kafka.consumer.KafkaConsumerVerticle.java
License:Apache License
@Override public void start() throws Exception { super.start(); final JsonObject config = vertx.getOrCreateContext().config(); vertxAddress = getMandatoryStringConfig(config, KafkaConsumerProperties.KEY_VERTX_ADDRESS); configuration = KafkaConsumerConfiguration.create( getMandatoryStringConfig(config, KafkaConsumerProperties.KEY_GROUP_ID), getMandatoryStringConfig(config, KafkaConsumerProperties.KEY_KAFKA_TOPIC), getMandatoryStringConfig(config, KafkaConsumerProperties.KEY_ZOOKEEPER), config.getString(KafkaConsumerProperties.KEY_OFFSET_RESET, "largest"), config.getInteger(KafkaConsumerProperties.KEY_ZOOKEPER_TIMEOUT_MS, 100000), config.getInteger(KafkaConsumerProperties.KEY_MAX_UNACKNOWLEDGED, 100), config.getLong(KafkaConsumerProperties.KEY_MAX_UNCOMMITTED_OFFSETS, 1000L), config.getLong(KafkaConsumerProperties.KEY_ACK_TIMEOUT_SECONDS, 600L), config.getLong(KafkaConsumerProperties.KEY_COMMIT_TIMEOUT_MS, 5 * 60 * 1000L), config.getInteger(KafkaConsumerProperties.KEY_MAX_RETRIES, Integer.MAX_VALUE), config.getInteger(KafkaConsumerProperties.KEY_INITIAL_RETRY_DELAY_SECONDS, 1), config.getInteger(KafkaConsumerProperties.KEY_MAX_RETRY_DELAY_SECONDS, 10), config.getLong(KafkaConsumerProperties.EVENT_BUS_SEND_TIMEOUT, DeliveryOptions.DEFAULT_TIMEOUT)); consumer = KafkaConsumer.create(vertx, configuration, this::handler); consumer.start();/*from w w w. j a v a 2 s . c o m*/ }
From source file:com.hubrick.vertx.kafka.producer.KafkaProducerServiceVerticle.java
License:Apache License
@Override public void start() { // Get the address of EventBus where the message was published final String address = config().getString(ADDRESS); if (Strings.isNullOrEmpty(address)) { throw new IllegalStateException("address must be specified in config"); }/* w w w.j av a2 s. c o m*/ // Get the address of EventBus where the message was published final String topic = config().getString(DEFAULT_TOPIC); if (Strings.isNullOrEmpty(topic)) { throw new IllegalStateException("topic must be specified in config"); } final JsonObject statsDConfig = config().getJsonObject(STATSD); StatsDConfiguration statsDConfiguration = null; if (statsDConfig != null) { final String prefix = statsDConfig.getString(PREFIX, PREFIX_DEFAULT); final String host = statsDConfig.getString(HOST, HOST_DEFAULT); final int port = statsDConfig.getInteger(PORT, PORT_DEFAULT); statsDConfiguration = new StatsDConfiguration(host, port, prefix); } final KafkaProducerConfiguration kafkaProducerConfiguration = new KafkaProducerConfiguration(topic, config().getString(BROKER_LIST, BROKER_LIST_DEFAULT), config().getInteger(REQUEST_ACKS, REQUEST_ACKS_DEFAULT)); kafkaProducerConfiguration.setStatsDConfiguration(statsDConfiguration); final String type = config().getString(TYPE); if (!Strings.isNullOrEmpty(type)) { kafkaProducerConfiguration.setType(ProducerType.valueOf(type)); } final Integer maxRetries = config().getInteger(MAX_RETRIES); if (maxRetries != null) { kafkaProducerConfiguration.setMaxRetries(maxRetries); } final Integer retryBackoffMs = config().getInteger(RETRY_BACKOFF_MS); if (retryBackoffMs != null) { kafkaProducerConfiguration.setRetryBackoffMs(retryBackoffMs); } final Integer bufferingMaxMs = config().getInteger(BUFFERING_MAX_MS); if (bufferingMaxMs != null) { kafkaProducerConfiguration.setBufferingMaxMs(bufferingMaxMs); } final Integer bufferingMaxMessages = config().getInteger(BUFFERING_MAX_MESSAGES); if (bufferingMaxMessages != null) { kafkaProducerConfiguration.setBufferingMaxMessages(bufferingMaxMessages); } final Integer enqueueTimeout = config().getInteger(ENQUEUE_TIMEOUT); if (enqueueTimeout != null) { kafkaProducerConfiguration.setEnqueueTimeout(enqueueTimeout); } final Integer batchMessageNum = config().getInteger(BATCH_MESSAGE_NUM); if (batchMessageNum != null) { kafkaProducerConfiguration.setBatchMessageNum(batchMessageNum); } kafkaProducerService = new DefaultKafkaProducerService(kafkaProducerConfiguration); ProxyHelper.registerService(KafkaProducerService.class, vertx, kafkaProducerService, address); kafkaProducerService.start(); }
From source file:de.elsibay.TokenizedBridgeEventHandlerImpl.java
License:Open Source License
@Override public void handle(BridgeEvent event) { String token = null;/*ww w .j a va 2 s . c o m*/ if (event.rawMessage() != null) { JsonObject headers = event.rawMessage().getJsonObject("headers"); if (headers != null) { token = headers.getString(tokenName, ""); } } bridgeEventAuthTokenHandler.accept(event, token); }