BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENF
HAMBURG KOPENHAGEN LAUSANNE MÜNCHEN STUTTGART WIEN ZÜRICH
Event-driven microservices with
Vxms, Hazelcast and Kubernetes
Andy Moncsek
Senior Consultant
Andy.Moncsek@trivadis.com
Twitter: @AndyAHCP
Agenda
2 23.02.2018
1. Vert.x / Vxms
2. Kubernetes
3. Configure Hazelcast to run in Kubernetes
4. Demo
5. Conclusion
Event-driven microservices with Vxms, Hazelcast and Kubernetes
Vert.x / Vxms
3 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
What Vert.x is
is a tool-kit for building
reactive appications on the JVM
4 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
What Vert.x is
is the default cluster provider
of Vert.X
5 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
What Vxms is
Vxms* is an opinionated framework
on top of Vert.x for building reactive
appications on the JVM
6 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
* http://amoahcp.github.io/vxms/
Design goals
7 23.02.2018 Vert.x based microservices with vxms
easy to use
100% Vert.x
compatible
ResilienceModularity
no blaming
Vert.x example
Event-driven microservices with Vxms, Hazelcast and Kubernetes8 23.02.2018
public class Gateway extends AbstractVerticle {
@Override
public void start(Future<Void> startFuture) throws Exception {
Router router = Router.router(vertx);
router.get("/helloEventbus/:name").handler(ctx -> {
String name = ctx.request().getParam("name");
vertx.eventBus().send("/hello", name, responseHandler -> {
Message<String> result = responseHandler.result();
ctx.response().end(result.body());
});
});
JsonObject config = vertx.getOrCreateContext().config();
vertx.createHttpServer().requestHandler(router::accept)
.listen(config.getInteger("port", 9090), config.getString("host", "localhost"));
startFuture.complete();
}
}
• Create rest endpoint
• Send to eventbus
• Pass response to rest reply
What Vxms is
Event-driven microservices with Vxms, Hazelcast and Kubernetes9 23.02.2018
@ServiceEndpoint
public class Gateway extends VxmsEndpoint{
@Path("/helloEventbus/:name")
@GET
public void simpleEventbusCall(RestHandler handler) {
String name= handler.request().param("name");
handler.
eventBusRequest().
send("/hello", name).// send message to eventbus, pass result to REST response
mapToStringResponse((message, response)->
response.complete(message.result().body()).
execute();// execute non blocking
}
}
What Vxms is
Event-driven microservices with Vxms, Hazelcast and Kubernetes10 23.02.2018
@ServiceEndpoint
public class Gateway extends VxmsEndpoint{
@Path("/helloEventbus/:name")
@GET
public void simpleEventbusCall(RestHandler handler) {
String name= handler.request().param("name");
handler.
eventBusRequest().
send("/hello", name).
mapToStringResponse((message, response)->
response.complete(message.result().body()).
execute();// execute non blocking
}
}
@ServiceEndpoint
public class EventbusExample extends VxmsEndpoint{
@Consume("/hello")
public void simpleNonBlocking(EventbusHandler handler) {
String name= handler.request().body();
handler.
response().
stringResponse((response)->
response.complete("hello World "+name)).// complete non-blocking response
timeout(2000).// timeout for stringResponse handling
onError(error->LOG(error.getMessage())).
onFailureRespond((error, future)->future.complete("error:"+error.getMessage())).
retry(3).
closeCircuitBreaker(2000).
execute();// execute non blocking
}
}
Event via Hazelcast
Kubernetes
11 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
Kubernetes basics: What it is....
 Kubernetes is platform designed to automate deploying,
scaling, and operating application containers.
 Deploy your applications quickly and predictably.
 Scale your applications on the fly.
 Roll out new features seamlessly.
Event-driven microservices with Vxms, Hazelcast and Kubernetes12 23.02.2018
Kubernetes Namespaces
”virtual" cluster
Separates DEV, TEST, PROD, ... environments
13 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
Kubernetes Pods
Group of containers
Shares network/namespace/ IP
Shares environmental variables
Shared volumes
14 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
Kubernetes Controller
15 23.02.2018
Ensure X pods are running
Pod templates
Rolling update
Event-driven microservices with Vxms, Hazelcast and Kubernetes
Kubernetes Services
16 23.02.2018
Pod discovery
IP per service
1-N port numbers
Route to pods
Load balancer
Event-driven microservices with Vxms, Hazelcast and Kubernetes
Configure Hazelcast to run in
Kubernetes
17 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
Hazelcast & Kubernetes  What we want
Case 1: Lookup all nodes (Verticles) managed by one controller
 1 – N pods
 1 – X container
Case 2: Lookup all nodes/services in a cluster / namespace
 N services per cluster
Routing to X pods
18 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
Hazelcast & Kubernetes  What we get
Easy scale- up/down of service instances
Failover provided by Kubernetes and Hazelcast
Distributed Event-Bus  each Verticle instance
Replicated shared data
19 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
Hazelcast node discovery in Kubernetes
20 23.02.2018
Hazelcast discovery plugin for Kubernetes
Option 1: Kubernetes REST API
Allows discovery by service name
Option 2: DNS Lookup
Enable custom cluster.xml in Vert.X  put to classpath
https://github.com/hazelcast/hazelcast-kubernetes
Event-driven microservices with Vxms, Hazelcast and Kubernetes
Vert.x / Hazelcast node discovery in Kubernetes
21 23.02.2018
Hazelcast
<hazelcast>
…
<discovery-strategy enabled="true"
class=”….HazelcastKubernetesDiscoveryStrategy">
<properties>
<property name="service-label-name">cluster1</property>
<property name="service-label-value">true</property>
<property name="namespace">default</property>
</properties>
</discovery-strategy>
</hazelcast>
• Partition your cluster using
labels
Hazelcast.xml / Cluster.xml
Event-driven microservices with Vxms, Hazelcast and Kubernetes
kind: Service
apiVersion: v1
metadata:
labels:
service-label-name: cluster1
service-label-value: true
Kubernetes
Demo
22 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
Demo
23 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
Conclusion
Docker IS mainstream
Kubernetes dominates the orchestration market
Hazelcast is an easy to use & fast solution for
Storage, caching, messaging & more
Works well in cloud environments
Vert.x is a fast & powerful toolkit for reactive applications
Vxms reduces the complexity of Vert.x
24 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
References
25 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
- https://github.com/amoAHCP/vxms
- http://vertx.io
- https://maven.fabric8.io
- https://github.com/hazelcast/hazelcast-kubernetes
- http://docs.hazelcast.org/docs/latest-
development/manual/html/Setting_Up_Clusters/index.html
- http://www.lihaoyi.com/post/StrategicScalaStylePrincipleofLeastPower.html
Thank you
Andy Moncsek
Senior Consultant
Andy.Moncsek@trivadis.com
Twitter: @AndyAHCP
23.02.201826 Event-driven microservices with Vxms, Hazelcast and Kubernetes
Introduction
27 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
What Vert.x is
28 23.02.2018
scale polyglot
general purposefun
Event-driven microservices with Vxms, Hazelcast and Kubernetes
Design goals
29 23.02.2018 Vert.x based microservices with vxms
No Vert.x
blaming
• just an other
focus (create
services)
Easy of use
• Vert.x is very
powerful /
concepts are
still new*
100%
compatible
• to Vert.x
Design goals
30 23.02.2018 Vert.x based microservices with vxms
Resilience
• APIs to build
resilient
applications must
be 1st class citizens
Modularity
• Vxms-core
• Vxms-rest
• Vxms-event
• Vxms-K8s-discovery
Typical microservice architecture
31 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
Why?
 Idea
 Avoid Service registry & lookup
 Decouple services  async + events
 Fast re-/deploy
 And more: resilient,…
32 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
Event-driven microservice
33 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
 Using an in-memory data grid
 Automatic node lookup (services)
 Failover
 Shared data  replicated in cluster
 Pub / sub
 Request / response
 NO (active) Service discovery

Event driven microservices with vxms, hazelcast and kubernetes - muenchen

  • 1.
    BASEL BERN BRUGGDÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENF HAMBURG KOPENHAGEN LAUSANNE MÜNCHEN STUTTGART WIEN ZÜRICH Event-driven microservices with Vxms, Hazelcast and Kubernetes Andy Moncsek Senior Consultant Andy.Moncsek@trivadis.com Twitter: @AndyAHCP
  • 2.
    Agenda 2 23.02.2018 1. Vert.x/ Vxms 2. Kubernetes 3. Configure Hazelcast to run in Kubernetes 4. Demo 5. Conclusion Event-driven microservices with Vxms, Hazelcast and Kubernetes
  • 3.
    Vert.x / Vxms 323.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
  • 4.
    What Vert.x is isa tool-kit for building reactive appications on the JVM 4 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
  • 5.
    What Vert.x is isthe default cluster provider of Vert.X 5 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
  • 6.
    What Vxms is Vxms*is an opinionated framework on top of Vert.x for building reactive appications on the JVM 6 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes * http://amoahcp.github.io/vxms/
  • 7.
    Design goals 7 23.02.2018Vert.x based microservices with vxms easy to use 100% Vert.x compatible ResilienceModularity no blaming
  • 8.
    Vert.x example Event-driven microserviceswith Vxms, Hazelcast and Kubernetes8 23.02.2018 public class Gateway extends AbstractVerticle { @Override public void start(Future<Void> startFuture) throws Exception { Router router = Router.router(vertx); router.get("/helloEventbus/:name").handler(ctx -> { String name = ctx.request().getParam("name"); vertx.eventBus().send("/hello", name, responseHandler -> { Message<String> result = responseHandler.result(); ctx.response().end(result.body()); }); }); JsonObject config = vertx.getOrCreateContext().config(); vertx.createHttpServer().requestHandler(router::accept) .listen(config.getInteger("port", 9090), config.getString("host", "localhost")); startFuture.complete(); } } • Create rest endpoint • Send to eventbus • Pass response to rest reply
  • 9.
    What Vxms is Event-drivenmicroservices with Vxms, Hazelcast and Kubernetes9 23.02.2018 @ServiceEndpoint public class Gateway extends VxmsEndpoint{ @Path("/helloEventbus/:name") @GET public void simpleEventbusCall(RestHandler handler) { String name= handler.request().param("name"); handler. eventBusRequest(). send("/hello", name).// send message to eventbus, pass result to REST response mapToStringResponse((message, response)-> response.complete(message.result().body()). execute();// execute non blocking } }
  • 10.
    What Vxms is Event-drivenmicroservices with Vxms, Hazelcast and Kubernetes10 23.02.2018 @ServiceEndpoint public class Gateway extends VxmsEndpoint{ @Path("/helloEventbus/:name") @GET public void simpleEventbusCall(RestHandler handler) { String name= handler.request().param("name"); handler. eventBusRequest(). send("/hello", name). mapToStringResponse((message, response)-> response.complete(message.result().body()). execute();// execute non blocking } } @ServiceEndpoint public class EventbusExample extends VxmsEndpoint{ @Consume("/hello") public void simpleNonBlocking(EventbusHandler handler) { String name= handler.request().body(); handler. response(). stringResponse((response)-> response.complete("hello World "+name)).// complete non-blocking response timeout(2000).// timeout for stringResponse handling onError(error->LOG(error.getMessage())). onFailureRespond((error, future)->future.complete("error:"+error.getMessage())). retry(3). closeCircuitBreaker(2000). execute();// execute non blocking } } Event via Hazelcast
  • 11.
    Kubernetes 11 23.02.2018 Event-drivenmicroservices with Vxms, Hazelcast and Kubernetes
  • 12.
    Kubernetes basics: Whatit is....  Kubernetes is platform designed to automate deploying, scaling, and operating application containers.  Deploy your applications quickly and predictably.  Scale your applications on the fly.  Roll out new features seamlessly. Event-driven microservices with Vxms, Hazelcast and Kubernetes12 23.02.2018
  • 13.
    Kubernetes Namespaces ”virtual" cluster SeparatesDEV, TEST, PROD, ... environments 13 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
  • 14.
    Kubernetes Pods Group ofcontainers Shares network/namespace/ IP Shares environmental variables Shared volumes 14 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
  • 15.
    Kubernetes Controller 15 23.02.2018 EnsureX pods are running Pod templates Rolling update Event-driven microservices with Vxms, Hazelcast and Kubernetes
  • 16.
    Kubernetes Services 16 23.02.2018 Poddiscovery IP per service 1-N port numbers Route to pods Load balancer Event-driven microservices with Vxms, Hazelcast and Kubernetes
  • 17.
    Configure Hazelcast torun in Kubernetes 17 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
  • 18.
    Hazelcast & Kubernetes What we want Case 1: Lookup all nodes (Verticles) managed by one controller  1 – N pods  1 – X container Case 2: Lookup all nodes/services in a cluster / namespace  N services per cluster Routing to X pods 18 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
  • 19.
    Hazelcast & Kubernetes What we get Easy scale- up/down of service instances Failover provided by Kubernetes and Hazelcast Distributed Event-Bus  each Verticle instance Replicated shared data 19 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
  • 20.
    Hazelcast node discoveryin Kubernetes 20 23.02.2018 Hazelcast discovery plugin for Kubernetes Option 1: Kubernetes REST API Allows discovery by service name Option 2: DNS Lookup Enable custom cluster.xml in Vert.X  put to classpath https://github.com/hazelcast/hazelcast-kubernetes Event-driven microservices with Vxms, Hazelcast and Kubernetes
  • 21.
    Vert.x / Hazelcastnode discovery in Kubernetes 21 23.02.2018 Hazelcast <hazelcast> … <discovery-strategy enabled="true" class=”….HazelcastKubernetesDiscoveryStrategy"> <properties> <property name="service-label-name">cluster1</property> <property name="service-label-value">true</property> <property name="namespace">default</property> </properties> </discovery-strategy> </hazelcast> • Partition your cluster using labels Hazelcast.xml / Cluster.xml Event-driven microservices with Vxms, Hazelcast and Kubernetes kind: Service apiVersion: v1 metadata: labels: service-label-name: cluster1 service-label-value: true Kubernetes
  • 22.
    Demo 22 23.02.2018 Event-drivenmicroservices with Vxms, Hazelcast and Kubernetes
  • 23.
    Demo 23 23.02.2018 Event-drivenmicroservices with Vxms, Hazelcast and Kubernetes
  • 24.
    Conclusion Docker IS mainstream Kubernetesdominates the orchestration market Hazelcast is an easy to use & fast solution for Storage, caching, messaging & more Works well in cloud environments Vert.x is a fast & powerful toolkit for reactive applications Vxms reduces the complexity of Vert.x 24 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
  • 25.
    References 25 23.02.2018 Event-drivenmicroservices with Vxms, Hazelcast and Kubernetes - https://github.com/amoAHCP/vxms - http://vertx.io - https://maven.fabric8.io - https://github.com/hazelcast/hazelcast-kubernetes - http://docs.hazelcast.org/docs/latest- development/manual/html/Setting_Up_Clusters/index.html - http://www.lihaoyi.com/post/StrategicScalaStylePrincipleofLeastPower.html
  • 26.
    Thank you Andy Moncsek SeniorConsultant Andy.Moncsek@trivadis.com Twitter: @AndyAHCP 23.02.201826 Event-driven microservices with Vxms, Hazelcast and Kubernetes
  • 27.
    Introduction 27 23.02.2018 Event-drivenmicroservices with Vxms, Hazelcast and Kubernetes
  • 28.
    What Vert.x is 2823.02.2018 scale polyglot general purposefun Event-driven microservices with Vxms, Hazelcast and Kubernetes
  • 29.
    Design goals 29 23.02.2018Vert.x based microservices with vxms No Vert.x blaming • just an other focus (create services) Easy of use • Vert.x is very powerful / concepts are still new* 100% compatible • to Vert.x
  • 30.
    Design goals 30 23.02.2018Vert.x based microservices with vxms Resilience • APIs to build resilient applications must be 1st class citizens Modularity • Vxms-core • Vxms-rest • Vxms-event • Vxms-K8s-discovery
  • 31.
    Typical microservice architecture 3123.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
  • 32.
    Why?  Idea  AvoidService registry & lookup  Decouple services  async + events  Fast re-/deploy  And more: resilient,… 32 23.02.2018 Event-driven microservices with Vxms, Hazelcast and Kubernetes
  • 33.
    Event-driven microservice 33 23.02.2018Event-driven microservices with Vxms, Hazelcast and Kubernetes  Using an in-memory data grid  Automatic node lookup (services)  Failover  Shared data  replicated in cluster  Pub / sub  Request / response  NO (active) Service discovery