autodiscoverable
microservices with
vertx3
Andy Moncsek
About me
• Andy Moncsek
• Senior Consultant Application development
• Trivadis AG Switzerland
• Email: Andy.Moncsek@Trivadis.com
• Twitter: @AndyAHCP
Agenda
• about microservices
• Vert.x 3 introduction
• microservices on top of Vert.x 3
C
E
B
A
C
G
H
F
I
about microservices
C
E
B
A
C
G
H
F
I
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
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
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
Vert.x 3
C
E
B
A
C
G
H
F
I
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
Vert.X 3 (terms)
• Vert.X
• Verticle
• Event Bus
• Eventloop vs. Worker AA
AE
AF
AG
AC
AH
AB
AC
AI
Vert.X 3 (terms)
• Scaling, Cluster / HA
• VerticleFactory
• packaging
• TCP, UDP, HTTP, WebSocket, SocketJS, FileSystem,….. AA
AE
AF
AG
AC
AH
AB
AC
AI
Vert.x 3
DEMO
C
E
B
A
C
G
H
F
I
microservices on top
of Vert.x 3
C
E
B
A
C
G
H
F
I
https://github.com/amoAHCP/vert.x-microservice
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
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)
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
serviceservice
serviceservice
Vert.X microservice framework - registry /
heartbeat
router
/gateway
host:port
service
service
service
service
service
Vert.X cluster
registry register
register
heart-
beat ping
Vert.X microservice framework - discovery
Vert.X cluster
servi
ce servi
ce
servi
ce servi
ce
servi
ce
router
/gatew
ay
host:po
rtregis
try
discovery.service(„name“, op->
);
op.operation(„path“, p->
)
fail
p.eventBusSend(„message",r->{
// reply
});
fail
Vert.x microservice
framework
DEMO
C
E
B
A
C
G
H
F
I
any
questions?
C
E
B
A
C
G
H
F
I
Thank you
C
E
B
A
C
G
H
F
I
• [1] http://www.infoq.com/news/2014/11/gotober-fowler-
microservices
• [2] http://www.adam-
bien.com/roller/abien/entry/the_perfect_javaee_microser
vice
• [3] https://www.voxxed.com/blog/2015/04/coupling-
versus-autonomy-in-microservices/
• [4] https://www.voxxed.com/blog/2015/04/microservice-
design-patterns/

autodiscoverable microservices with vertx3

Editor's Notes

  • #6 1 Martin Fowler : http://www.infoq.com/news/2014/11/gotober-fowler-microservices
  • #7 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/
  • #8 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/
  • #11 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
  • #12 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 …
  • #16 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
  • #18 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
  • #19 client / server API the same connects through vertx instance or REST-URL