Starter pack for Vert.x development. Read a wiki for preparation.
Here you could find some IDEA shortcuts that i've found the most useful(this list is being updated continuosly).
Now let's dive in this project:
There are some important files to understand this project. Two main directories is common
and profiles
.
Look at build.gradle
, it is the first project configuration file. You should see project dependencies,
their's meanings one by one:
- Service discovery - component, that provides an infrastructure to publish and discover various services
- Hazlecast - default custer manager
- Web - http server
- Web client - asynchronous http client
- Circuit breaker - implementation of
Circuit breaker pattern
- Health check - testing the health of the application
*Check Useful vert.x
concepts section for more.
Now turn your attention to src/main/java/vertx/common
folder. There are two files.
Start reading Launcher.java
first and MicroserviceVerticle.java
second.
This whole part is just two classes intended for future reuse by inheriting from them.
That is why it is common
- because all this code is common for our project(and lots of other vert.x
projects, perhaps)
This time profiles/build.gradle
contains pretty much the same libraries with few additions like google
and vert.x
libraries for gRPC
. We won't stop here, go to profiles/src/main/java/profiles/
folder.
Launcher.java
is the entry point that runs vert.x
. Other classes are placed in folders:
This folder contains classes for transfering to main types of messages over eventbus
: configuration messages and profiles messages. So here is the meaning of every class here:
Config
is just a data class: representation of conf/config.json in plain java classConfigMessageCoded
is an class that implementsMessageCodec
interface - general way of transportation of custom message types overeventbus
and this class are used concretly to transportConfig
class.Profile
is just a data class: representation of user info in plain java classProfileMessageCodec
is just like anConfigMessageCodec
but for transporting ofProfile
class
The folder contains only one file: ProfileServiceImpl.java
. This class is a service for fetching profile. First it fetches
Profile
object, transforms it to ProfileObject
object, wraps it with ProfileResponse
object and passes it to client when it is requested.
This folder contains classes and here is theirs purpose:
ConfigurationVerticle
- for configuration maintenance update/retrievalServiceDiscoveryVerticle
- the name suggests the meaning, read here for moreApiVerticle
- for settlingVertxServer
(adding service for retrieval of Profile data via gRPC)ProfileVerticle
- just replying to Profile requests with {"Petr", "Ivanov", ... }.MainVerticle
- for deploying all verticles listed above
ProfilesClient.java
is a client class that connects to our server and prints response("Petr", "Ivanov", ... ).
The common question is: "How do our client knows the address of our server and other configuration info?". Well, it takes all this from our conf/config.json
file. It is not magic.
For more - read comments in code.
This part is all about useful links to understand vert.x
and this project of course(be patient):
- Unofficial tutorial
- Official tutorial
- Guide to asynchronous programming, actually all about
vert.x
(read the first three items)
- ServiceDiscovery(read the first eight items)
- Hazelcast
- Web
- Web client
- Circuit breaker
- Health check
Google a lot and read a lot, other info is comments in files.