Presented during Payara Japan Tour 2019 (https://blog.payara.fish/payara-on-tour-in-japan).
In this session, you'll learn how to develop applications that evolve according to your needs, can easily run in the cloud and integrate with common cloud technologies. We'll start with a simple application, focusing on business logic. MicroProfile framework, powered by a lightweight opensource Payara Micro runtime, will get us started quickly and allow gradual improvements later.
MicroProfile contains a lot of components that make developers productive. It allows separating business logic from common concerns like configuration, failure-recovery, REST service calls, context propagation across service calls and securing services. Adding all of these to existing code is easy. It's also easy to introduce new microservices as needed and adopt cloud technologies as your application grows. I'll show you how, in a step-by-step demo. And if time allows, I'll also show how to run and scale your application effectively with Kubernetes in the cloud.
5. Cloud ready requirements
●
Pluggable services
●
Scalable according to
the load
●
Low coupling
There are even more according to the 12 factor applications manifesto
●
External configuration
●
Failure recovery
●
Security
●
Monitoring
6. @OMIHALYI
Solution: agile evolution
●
Simple API abstractions
●
Flexible implementations
●
Application logic first, against a solid platform
●
Abstract the technology, prepare for refactoring
●
Choose final technology later
10. @OMIHALYI
What is Payara Micro?
●
Executable JAR (~70MB disk size, ~30 MB RAM)
●
Runs WAR and EAR from command line
– Also Uber JAR, embeddable, maven plugin
●
Automatically forms elastic cluster
●
Web Profile and most of Full Profile, MicroProfile
●
Opensource, release each 3 months
11. @OMIHALYI
What is MicroProfile?
●
Project at Eclipse Foundation
●
Common API, multiple implementations
●
Builds on Java EE standards
●
Modern patterns:
– Microservices, Reactive, …
●
http://microprofile.io - open for everybody
15. @OMIHALYI
REST services API (server)
●
JAX-RS endpoint
public User getUser(
Integer id) {
return userById(id);
}
16. @OMIHALYI
REST services API (server)
●
JAX-RS endpoint
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public User getUser(
Integer id) {
return userById(id);
}
@PathParam("id")
17. @OMIHALYI
REST services API (client)
●
JAX-RS client
User admin = client.target(url).path("admin")
.request().get(User.class)
●
MicroProfile client (plain Java interface - much better abstraction)
User admin = userService.getUser("admin")
18. @OMIHALYI
JSON binding
@JsonbNillable
public class User implements Serializable {
private String name;
@JsonbTransient
private String description;
@JsonbProperty("userId")
private long id;
}
- new in Java EE 8 and
MicroProfile 2.0
More about JSON-B:
http://json-b.net
19. @OMIHALYI
Fault Tolerance
●
Easy to add failure handling to REST calls
with annotations
– Circuit breaker, Timeout, Retry, Bulkheads
– Fallback in case of unrecoverable failure
– Asynchronous variants
21. @OMIHALYI
CDI events, really?
●
Part of Java EE API already
●
Easy to send and observe messages
●
Similar to topics
●
Is it enough? What about:
– Sending events to other services
– Message broker to decouple services
– Transactions
22. @OMIHALYI
CDI events, really?
What about:
●
Sending events to other services – Important
even in initial project stages
●
Reliable delivery, Transactions – important in
later stages, or not at all in some projects
●
All can be extended using event handlers
23. @OMIHALYI
Events as an abstraction
●
Transfer events to other services in an event
handler
– Using Payara CDI Event Bus (simple)
– Using distributed queues (robust)
– Using any message broker (flexible)
●
Distribute incoming messages as events
●
Start simple, extend to robust
24. @OMIHALYI
Java EE JCA connectors
●
Message-driven beans, for any messaging infrastructure
●
Connetors on Github for AWS, Azure, Kafka, MQTT
@MessageDriven(activationConfig = { … })
public class KafkaMDB implements KafkaListener {
@OnRecord( topics={"my-topic"} )
public void onMsg(ConsumerRecord record) {
…
28. @OMIHALYI
Evolutionary architecture
„An evolutionary architecture supports
continual and incremental change as a first
principle along multiple dimensions.“
„Microservices meet this definition.“
Neal Ford, Rebecca Parsons
http://evolutionaryarchitecture.com/
33. @OMIHALYI
Is there a free lunch?
Microprofile provides a lot out of the box
●
Metrics – monitoring data, statistics
●
Health – problem detection and autorecovery
●
Opentracing – connects related requests
●
OpenAPI – docs for REST resources
34. @OMIHALYI
Monitoring Usecases
●
Monitoring for application metrics
●
Monitoring of failures to detect future problems
●
Health check to restart service if not healthy
●
Health (ready) check to detect when started and ready
●
Tracing to combine logs and info about related
service calls
37. Thank You
Not using the Payara Platform yet? Download the open
source software: Payara Server or Payara Micro
https://payara.fish/downloads
Need support for the Payara Platform?
https://payara.fish/support