Java Code Examples for io.vertx.core.eventbus.EventBus#consumer()
The following examples show how to use
io.vertx.core.eventbus.EventBus#consumer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KinesisVerticle.java From reactive-refarch-cloudformation with Apache License 2.0 | 6 votes |
@Override public void start() { EventBus eb = vertx.eventBus(); kinesisAsyncClient = createClient(); eventStream = System.getenv(STREAM_NAME) == null ? "EventStream" : System.getenv(STREAM_NAME); eb.consumer(KINESIS_EVENTBUS_ADDRESS, message -> { try { TrackingMessage trackingMessage = Json.decodeValue((String)message.body(), TrackingMessage.class); String partitionKey = trackingMessage.getMessageId(); byte [] byteMessage = createMessage(trackingMessage); sendMessageToKinesis(byteMessage, partitionKey); // Now send back reply message.reply("OK"); } catch (KinesisException exc) { LOGGER.error(exc); } }); }
Example 2
Source File: Jukebox.java From vertx-in-action with MIT License | 6 votes |
@Override public void start() { logger.info("Start"); EventBus eventBus = vertx.eventBus(); eventBus.consumer("jukebox.list", this::list); eventBus.consumer("jukebox.schedule", this::schedule); eventBus.consumer("jukebox.play", this::play); eventBus.consumer("jukebox.pause", this::pause); vertx.createHttpServer() .requestHandler(this::httpHandler) .listen(8080); vertx.setPeriodic(100, this::streamAudioChunk); }
Example 3
Source File: CacheVerticle.java From reactive-refarch-cloudformation with Apache License 2.0 | 5 votes |
@Override public void start() { EventBus eb = vertx.eventBus(); this.registerToEventBusToGetData(eb); this.registerToEventBusForUpdates(eb); this.registerToEventBusToFill(eb); eb.consumer(Constants.CACHE_PURGE_EVENTBUS_ADDRESS, message -> CACHE.cleanUp()); }
Example 4
Source File: OsgiSender.java From chuidiang-ejemplos with GNU Lesser General Public License v3.0 | 5 votes |
public void setEventBus(EventBus eb){ this.eb = eb; eb.consumer("hola",message->{ System.out.println(message.body()); Data data = new Data(); data.value=Math.random(); // eb.send("data", data); }); }
Example 5
Source File: ClusterReceiver.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void start() { EventBus eventBus = vertx.eventBus(); eventBus.registerDefaultCodec(CustomMessage.class, new CustomMessageCodec()); eventBus.consumer("cluster-message-receiver", message -> message.reply(new CustomMessage("cluster-message-receiver reply"))); }
Example 6
Source File: ModuleManager.java From okapi with Apache License 2.0 | 5 votes |
private void consumeModulesUpdated() { EventBus eb = vertx.eventBus(); eb.consumer(EVENT_NAME, res -> { String moduleId = (String) res.body(); enabledModulesCache.remove(moduleId); }); }
Example 7
Source File: TenantManager.java From okapi with Apache License 2.0 | 5 votes |
private void consumeTimers() { EventBus eb = vertx.eventBus(); eb.consumer(EVENT_NAME, res -> { String tenantId = (String) res.body(); handleTimer(tenantId); }); }
Example 8
Source File: Receiver.java From tools-journey with Apache License 2.0 | 5 votes |
@Override public void start() { EventBus eb = vertx.eventBus(); eb.consumer("ping-address", message -> { System.out.println("Received message: " + message.body()); // Now send back reply message.reply("pong!"); }); System.out.println("Receiver ready!"); }
Example 9
Source File: CacheVerticle.java From reactive-refarch-cloudformation with Apache License 2.0 | 5 votes |
private void registerToEventBusToGetData(final EventBus eb) { eb.consumer(Constants.CACHE_EVENTBUS_ADDRESS, message -> { // Is data stored in cache? TrackingMessage trackingMessage = Json.decodeValue(((JsonObject)message.body()).encode(), TrackingMessage.class); LOGGER.debug("Wrote message to cache: " + message.body()); TrackingMessage value = CACHE.getIfPresent(trackingMessage.getProgramId()); if (null == value) { JsonObject msgToSend = JsonObject.mapFrom(trackingMessage); LOGGER.info("Key " + trackingMessage.getProgramId() + " not found in cache --> Redis"); eb.send(Constants.REDIS_EVENTBUS_ADDRESS, msgToSend, res -> { if (res.succeeded()) { JsonObject msg = (JsonObject)res.result().body(); if (msg.isEmpty()) { message.reply(msg); } else { LOGGER.debug("Message from Redis-Verticle: " + msg); TrackingMessage msgFromRedis = Json.decodeValue(msg.encode(), TrackingMessage.class); CACHE.put(msgFromRedis.getProgramId(), msgFromRedis); message.reply(msg); } } else { message.reply(new JsonObject()); } }); } else { LOGGER.debug("Message " + Json.encode(value) + " found in cache --> HttpVerticle"); value.setMessageId(trackingMessage.getMessageId()); message.reply(JsonObject.mapFrom(value)); } }); }
Example 10
Source File: CacheVerticle.java From reactive-refarch-cloudformation with Apache License 2.0 | 5 votes |
private void registerToEventBusForUpdates(final EventBus eb) { // Writing the data into the cache // Called from Redis verticle (Redis pub/sub-update) eb.consumer(Constants.CACHE_REDIS_EVENTBUS_ADDRESS, message -> { LOGGER.debug("I have received a message: " + message.body()); LOGGER.debug("Message type: " + message.body().getClass().getName()); writeDataToCache(message); }); }
Example 11
Source File: RedisVerticle.java From reactive-refarch-cloudformation with Apache License 2.0 | 5 votes |
void registerToEventBusForCacheVerticle(final EventBus eb, final RedisClient redis) { eb.consumer(Constants.REDIS_EVENTBUS_ADDRESS, message -> { // Getting data from Redis and storing it in cache verticle TrackingMessage trackingMessage = Json.decodeValue(((JsonObject)message.body()).encode(), TrackingMessage.class); LOGGER.info(RedisVerticle.class.getSimpleName() + ": I have received a message: " + message.body()); LOGGER.info("Looking for programId " + trackingMessage.getProgramId() + " in Redis"); redis.hgetall(trackingMessage.getProgramId(), res -> { if (res.succeeded()) { JsonObject result = res.result(); if (null == result || result.isEmpty()) { LOGGER.info("No object found"); message.reply(new JsonObject()); } else { String strRes = Json.encode(result); TrackingMessage msg = Json.decodeValue(strRes, TrackingMessage.class); msg.setMessageId(trackingMessage.getMessageId()); JsonObject msgResult = JsonObject.mapFrom(msg); LOGGER.info("Result: " + msgResult); message.reply(msgResult); } } else { LOGGER.info("No object found: " + res.cause()); message.reply(new JsonObject()); } }); }); }
Example 12
Source File: RedisVerticle.java From reactive-refarch-cloudformation with Apache License 2.0 | 5 votes |
void registerToEventBusForPurging(final EventBus eb, final RedisClient redis) { eb.consumer(Constants.REDIS_PURGE_EVENTBUS_ADDRESS, message -> redis.flushall(res -> { if (!res.succeeded()) { LOGGER.info(res.cause()); } })); }
Example 13
Source File: RedisVerticle.java From reactive-refarch-cloudformation with Apache License 2.0 | 5 votes |
void registerToEventBusForAdding(final EventBus eb, final RedisClient redis) { eb.consumer(Constants.REDIS_STORE_EVENTBUS_ADDRESS, message -> { TrackingMessage trackingMessage = Json.decodeValue(((JsonObject)message.body()).encode(), TrackingMessage.class); redis.hmset(trackingMessage.getProgramId(), JsonObject.mapFrom(trackingMessage), res -> { if (!res.succeeded()) { LOGGER.info(res.cause()); } }); }); }
Example 14
Source File: VertxEventBusMetricsTest.java From vertx-micrometer-metrics with Apache License 2.0 | 5 votes |
@Test public void shouldDiscardMessages(TestContext context) { vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions() .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true)) .setEnabled(true))) .exceptionHandler(t -> context.exceptionHandler().handle(t)); int num = 10; EventBus eb = vertx.eventBus(); MessageConsumer<Object> consumer = eb.consumer("foo"); consumer.setMaxBufferedMessages(num); consumer.pause(); consumer.handler(msg -> fail("should not be called")); for (int i = 0; i < num; i++) { eb.send("foo", "the_message-" + i); } eb.send("foo", "last"); waitForValue(vertx, context, "vertx.eventbus.discarded[side=local]$COUNT", value -> value.intValue() == 1); List<RegistryInspector.Datapoint> datapoints = listDatapoints(startsWith("vertx.eventbus")); assertThat(datapoints).contains(dp("vertx.eventbus.pending[side=local]$VALUE", 10)); // Unregister => discard all remaining consumer.unregister(); waitForValue(vertx, context, "vertx.eventbus.discarded[side=local]$COUNT", value -> value.intValue() == 11); datapoints = listDatapoints(startsWith("vertx.eventbus")); assertThat(datapoints).contains(dp("vertx.eventbus.pending[side=local]$VALUE", 0)); }
Example 15
Source File: Listener.java From vertx-in-action with MIT License | 5 votes |
@Override public void start() { EventBus bus = vertx.eventBus(); bus.<JsonObject>consumer("sensor.updates", msg -> { JsonObject body = msg.body(); String id = body.getString("id"); String temperature = format.format(body.getDouble("temp")); logger.info("{} reports a temperature ~{}C", id, temperature); }); }
Example 16
Source File: CacheVerticle.java From reactive-refarch-cloudformation with Apache License 2.0 | 4 votes |
private void registerToEventBusToFill(final EventBus eb) { // Handler for test data eb.consumer(Constants.CACHE_STORE_EVENTBUS_ADDRESS, this::writeDataToCache); }
Example 17
Source File: VertxConsumer.java From chuidiang-ejemplos with GNU Lesser General Public License v3.0 | 4 votes |
public void setEventBus(EventBus eb){ this.eb = eb; eb.consumer("hola",message -> { System.out.println(message.body()); }); }
Example 18
Source File: SensorData.java From vertx-in-action with MIT License | 4 votes |
@Override public void start() { EventBus bus = vertx.eventBus(); bus.consumer("sensor.updates", this::update); bus.consumer("sensor.average", this::average); }
Example 19
Source File: ProxyHandler.java From vertx-service-proxy with Apache License 2.0 | 2 votes |
/** * Register the proxy handle on the event bus. * * @param eventBus the event bus * @param address the proxy address * @param interceptors the interceptors */ public MessageConsumer<JsonObject> register(EventBus eventBus, String address, List<Function<Message<JsonObject>, Future<Message<JsonObject>>>> interceptors) { Handler<Message<JsonObject>> handler = configureHandler(interceptors); consumer = eventBus.consumer(address, handler); return consumer; }