6 Beyond the event-bus

 

This chapter covers:

  • exposing services on top of the event-bus,
  • asynchronous testing of verticles and event-bus services.

The event-bus is a fundamental tool for articulating event processing in Vert.x, but there is more to it! Event-bus services are useful to expose typed interfaces rather than plain messaging, especially when multiple message types are expected at an event-bus destination. Testing is also an important concept, and we cover here what is different in testing asynchronous Vert.x code compared to traditional testing.

In this chapter we are going to revisit an earlier example, refactor it to an event-bus service, and show how to test it.

6.1  Revisiting heat sensors with a service API

In chapter 3 we had used heat sensors as an example. We had a SensorData verticle that kept the last observed values for each sensor, and that could compute their average using a request / reply communication on the event-bus. To recall the example, listing 6.1 has the code for computing the temperatures average.

Listing 6.1. Event-bus based average computation API
private void average(Message<JsonObject> message) {    #1
  double avg = lastValues.values().stream()
    .collect(Collectors.averagingDouble(Double::doubleValue));
  JsonObject json = new JsonObject().put("average", avg);
  message.reply(json);     #2
}

6.2  Return of the RPCs

 
 
 
 

6.3  Defining a service interface

 
 
 

6.4  Service implementation

 
 
 
 

6.5  Enabling proxy code generation

 

6.6  Deploying event-bus services

 
 
 
 

6.7  Service proxies beyond callbacks

 
 

6.8  Testing and Vert.x

 
 
 

6.8.1  Using JUnit 5 with Vert.x

 
 

6.8.2  Testing DataVerticle

 
 
 

6.8.3  Running the tests

 
 

6.9  Summary

 
 

6.10  References

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage