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 H F I about microservices Vert.x 3 introduction microservices on top of Vert.x 3
C E B A G H F I about microservices
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 1 Martin Fowler : http://www.infoq.com/news/2014/11/gotober-fowler-microservices A E F G C H B I
microservice design patterns Architecture patterns Router/Aggregator/Chained/shared-data Deployment patterns instance per host, VM, Container 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/ A E F G C H B I
microservice design patterns Interaction/communication pattern Request-Reply vs. Pub-Sub / Events vs. Queries/Commands Service discovery serverside/clientside-discovery / self-/3d-party- registration 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/ A E F G C H B I
C E B A G H F I Vert.x 3
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 F E A 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 A E F G C H B I
Vert.X 3 (terms) Scaling, Cluster / HA VerticleFactory packaging TCP, UDP, HTTP, WebSocket, SocketJS, FileSystem,….. 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 … A E F G C H B I
C E B A G H F I DEMO Vert.x 3
microservices on top of Vert.x 3 B A G H F I microservices on top of Vert.x 3 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 A E F G C H B I
Vert.X microservice framework - service Verticle @ApplicationPath("/articleService") Verticle @Path("/comments/:id") @OperationType(Type.REST_GET) findComments(@PathParam("id") final String id, Message m) 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 @Path("/fetchByArticleIdWS") @OperationType(Type.WEBSOCKET) fetchByArticleIdWS(String id, WSMessageReply r) desc. @Path("/fetchByArticleId") @OperationType(Type.EVENTBUS) fetchByArticleId(String id, EBMessageReply r)
Vert.X microservice framework - router / gateway client router /gateway host:port @Path("/articleService/comments/:id") @Path(„/../fetchByArticleIdWS") @Path(„/..byArticleId“) service Event Bus Vert.X cluster
Vert.X microservice framework - registry / heartbeat 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 router /gateway host:port ping register unreg. registry register Vert.X cluster
Vert.X microservice framework - discovery router /gatew ay host:po rt regis try discovery.service(„name“, op-> ); client / server API the same connects through vertx instance or REST-URL op.operation(„path“, p-> ) fail p.eventBusSend(„message",r->{ // reply }); fail Vert.X cluster
Vert.x microservice framework B A G H F I DEMO Vert.x microservice framework
C E B A G H F I any questions?
C E B A G H F I Thank you
[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/