This document discusses microservices and how they can be implemented using Vert.x 3. It begins with defining characteristics of microservices like being component oriented and focusing on business capabilities. It then covers microservice design patterns like architecture, deployment and interaction patterns. Next, it introduces Vert.x 3 as an event driven toolkit for building reactive applications in Java. Key Vert.x 3 concepts are explained like Verticles, the event bus and clustering. The document concludes by proposing a Vert.x 3 microservice framework with components for service Verticles, a service router, registry for service discovery and heartbeats. A demo of this prototype framework is also mentioned.
2. About me
• Andy Moncsek
• Senior Consultant Application development
• Trivadis AG Switzerland
• Email: Andy.Moncsek@Trivadis.com
• Twitter: @AndyAHCP
5. characteristics of microservices [1 Martin
Fowler]
• component oriented, replaceable, independent
• focus on business capabilities
• UNIX style: do one thing well & work together
• smart endpoint & dump pipes (no ESB ;-) )
• distributed / decentralized data
AA
AE
AF
AG
AC
AH
AB
AC
AI
6. microservice design patterns
• Architecture patterns
• Router/Aggregator/Chained/shared-data
• Deployment patterns
• instance per host, VM, Container
AA
AE
AF
AG
AC
AH
AB
AC
AI
7. microservice design patterns
• Interaction/communication pattern
• Request-Reply vs. Pub-Sub / Events vs.
Queries/Commands
• Service discovery
• serverside/clientside-discovery / self-/3d-party-
registration AA
AE
AF
AG
AC
AH
AB
AC
AI
9. Vert.X 3
(tool-kit for building reactive
applications)
• nodeJS for Java developers :-D (sorry Tim)
• event driven / non blocking
• polyglot (written in Java 8)
• general purpose (web, backend)
• http://vert-x3.github.io, current version: v3.0-milestone6
10. Vert.X 3 (terms)
• Vert.X
• Verticle
• Event Bus
• Eventloop vs. Worker AA
AE
AF
AG
AC
AH
AB
AC
AI
11. Vert.X 3 (terms)
• Scaling, Cluster / HA
• VerticleFactory
• packaging
• TCP, UDP, HTTP, WebSocket, SocketJS, FileSystem,….. AA
AE
AF
AG
AC
AH
AB
AC
AI
13. microservices on top
of Vert.x 3
C
E
B
A
C
G
H
F
I
https://github.com/amoAHCP/vert.x-microservice
14. Vert.X microservice framework
• current status: working prototype!
• idea: all-in-one microservice framework based on Vert.X
• components:
• service Verticle
• service router / API gateway
• service registry / heartbeat
• service discovery AA
AE
AF
AG
AC
AH
AB
AC
AI
15. Vert.X microservice framework - service
Verticle
Verticle
@ApplicationPath("/articleService")
desc.
@Path("/comments/:id")
@OperationType(Type.REST_GET)
findComments(@PathParam("id") final String id, Message m)
@Path("/fetchByArticleIdWS")
@OperationType(Type.WEBSOCKET)
fetchByArticleIdWS(String id, WSMessageReply r)
@Path("/fetchByArticleId")
@OperationType(Type.EVENTBUS)
fetchByArticleId(String id, EBMessageReply r)
16. Vert.X microservice framework - router / gateway
Event Bus
Event Bus
Event Bus
Vert.X cluster
service
service
service
service
service
router
/gateway
host:port
@Path("/articleService/comments/:id")
@Path(„/../fetchByArticleIdWS")
@Path(„/..byArticleId“)
client
client
client
1 Martin Fowler : http://www.infoq.com/news/2014/11/gotober-fowler-microservices
be aware of different depl. patterns
Req.-Resp.: response expected, need to know who to ask; Pub-Sub. : service registers itself
Events (order 123 created), Queries/Commands : what should happen
https://www.voxxed.com/blog/2015/04/coupling-versus-autonomy-in-microservices/
be aware of different depl. patterns
Req.-Resp.: response expected, need to know who to ask; Pub-Sub. : service registers itself
Events (order 123 created), Queries/Commands : what should happen
https://www.voxxed.com/blog/2015/04/coupling-versus-autonomy-in-microservices/
1: The runtime env. either as binary dist. , embedded, fat-jar
2: Verticles are chunks of code that get deployed and run by Vert.x
3: connects all parts of your application (Verticles) / clusterable (Hazlecast)
4: default: Event Loop single threaded - Don’t block the event loop! / Worker Verticles
1: define number of instances (1 thread/instance), Clustering: „EventBus over network“, HA: failover
2: VerticleFactory: SPI to extend Vert.x (different languages, Spring)
3: no custom modules anymore (simple maven & maven-shade-plugin)
4: create …
classical „jersey-style“ Path + method vs. async handler registration
Why? „reactive / event-driven“ is cool but for many developers still „neuland“
classical input/output (method with parameter and return type) is not applicable (it blocks!)… solution message reply handler
challenge: many verticles instances (lokal and cluster)
needs to synchronize registration process on startup…
solution: cluster-wide counter
challenge registry: clusterWideMap is not iterate able…
solution: key is the router-key, value is a blob of a descriptor object with all registered descriptions
generally figure out how dropwizard is usable for heartbeat
client / server API the same
connects through vertx instance or REST-URL