Java Code Examples for io.vertx.core.Vertx#eventBus()
The following examples show how to use
io.vertx.core.Vertx#eventBus() .
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: DeploymentManager.java From okapi with Apache License 2.0 | 6 votes |
/** * Construct deployment manager. * @param vertx Vert.x handle * @param dm Discovery manager * @param em Event manager * @param host host name for deployed services * @param listenPort listening port for deployment node * @param nodeName Logical node name * @param config configuration */ public DeploymentManager(Vertx vertx, DiscoveryManager dm, EnvManager em, String host, int listenPort, String nodeName, JsonObject config) { this.dm = dm; this.em = em; this.vertx = vertx; this.host = host; this.listenPort = listenPort; this.nodeName = nodeName; this.eventBus = vertx.eventBus(); this.config = config; int portStart = Integer.parseInt(Config.getSysConf( "port_start", Integer.toString(listenPort + 1), config)); int portEnd = Integer.parseInt(Config.getSysConf( "port_end", Integer.toString(portStart + 10), config)); this.ports = new Ports(portStart, portEnd); }
Example 2
Source File: SensorDataTest.java From vertx-in-action with MIT License | 5 votes |
@Test void testAverage(Vertx vertx, VertxTestContext ctx) { EventBus bus = vertx.eventBus(); vertx.deployVerticle(new SensorData(), ctx.succeeding(id -> { bus.publish("sensor.updates", new JsonObject() .put("id", "a").put("temp", 20.0d)); bus.publish("sensor.updates", new JsonObject() .put("id", "b").put("temp", 22.0d)); bus.request("sensor.average", "", ctx.succeeding(reply -> ctx.verify(() -> { JsonObject json = (JsonObject) reply.body(); assertEquals(21.0d, (double) json.getDouble("average")); ctx.completeNow(); }))); })); }
Example 3
Source File: TcpEventBusBridgeImpl.java From vertx-tcp-eventbus-bridge with Apache License 2.0 | 5 votes |
public TcpEventBusBridgeImpl(Vertx vertx, BridgeOptions options, NetServerOptions netServerOptions, Handler<BridgeEvent> eventHandler) { this.eb = vertx.eventBus(); this.options = options != null ? options : new BridgeOptions(); this.bridgeEventHandler = eventHandler; server = vertx.createNetServer(netServerOptions == null ? new NetServerOptions() : netServerOptions); server.connectHandler(this::handler); }
Example 4
Source File: ApiToFileRegistry.java From apiman with Apache License 2.0 | 5 votes |
public ApiToFileRegistry(Vertx vertx, IEngineConfig foo, Map<String, String> config) { super(); this.eb = vertx.eventBus(); this.fileSystem = vertx.fileSystem(); linkRoot(); createTempFile(); createResetListener(); }
Example 5
Source File: Examples.java From vertx-sync with Apache License 2.0 | 4 votes |
public void streamExample(Vertx vertx) { EventBus eb = vertx.eventBus(); HandlerReceiverAdaptor<Message<String>> adaptor = streamAdaptor(); eb.<String>consumer("some-address").handler(adaptor); // Receive 10 messages from the consumer: for (int i = 0; i < 10; i++) { Message<String> received1 = adaptor.receive(); System.out.println("got message: " + received1.body()); } }
Example 6
Source File: Examples.java From vertx-sync with Apache License 2.0 | 4 votes |
public void fiberHandlerExample(Vertx vertx) { EventBus eb = vertx.eventBus(); vertx.createHttpServer().requestHandler(fiberHandler(req -> { // Send a message to address and wait for a reply Message<String> reply = awaitResult(h -> eb.request("some-address", "blah", h)); System.out.println("Got reply: " + reply.body()); // Now end the response req.response().end("blah"); })).listen(8080, "localhost"); }
Example 7
Source File: MetricsExamples.java From vertx-dropwizard-metrics with Apache License 2.0 | 4 votes |
public void naming2(Vertx vertx, MetricsService metricsService) { EventBus eventBus = vertx.eventBus(); JsonObject metrics = metricsService.getMetricsSnapshot(eventBus); metrics.getJsonObject("handlers"); }
Example 8
Source File: TestService.java From Summer with MIT License | 3 votes |
public SummerResponse test(Vertx vertx,RoutingContext routingContext){ EventBus eb = vertx.eventBus(); EventMessage eventMessage=EventMessage.message(null); eventMessage.setKey("68257"); // Message<EventMessage> reply = awaitResult(h -> eb.send("aaa", eventMessage, h)); // Message<EventMessage> reply1 = awaitResult(h -> eb.send("aaa", eventMessage, h)); // routingContext.response().end(SummerResponse.ok().setResult(reply.body().getMessage()).jsonPretty()); return SummerResponse.fail().message("bbb"); }
Example 9
Source File: Examples.java From vertx-sync with Apache License 2.0 | 3 votes |
public void syncResultExample(Vertx vertx) { EventBus eb = vertx.eventBus(); // Send a message and get the reply synchronously Message<String> reply = awaitResult(h -> eb.request("someaddress", "ping", h)); System.out.println("Received reply " + reply.body()); }