This session will explain how to build modern and scalable applications, while efficiently adding business value. With the right tools, technical decisions can be deferred and problems can be solved according to business needs instead. Payara Micro – an open source MicroProfile-compatible runtime – provides these tools in an easy-to-use package, allowing developers to focus on getting the job done. In addition, it can be connected using a standard API to Apache Kafka or Amazon SQS for high performance messaging.
In this talk, you’ll learn how to create an architecture around all these tools to get as much flexibility as possible and be ready to deploy your applications into cloud. During a live demonstration, you’ll see how a Java EE application can benefit from dynamic clustering, MicroProfile API, distributed configuration and scalable cache built into the Payara Micro runtime.
5. Cloud ready requirements
●
Pluggable persistence
●
Scalable according to the load
●
Low coupling
●
External configuration
●
Monitoring
●
Failure recovery
●
Security
There are more according to the 12 factor applications manifesto
10. JCache
●
Temporary cache → optimization of frequent reads
●
Temporary key-value persistence, extensible to permanent with a read/write-
through policy
●
More than 10 implementations, supported also by Payara Micro and Spring
●
Distributed implementations allow scalable persistence
●
Can cache results of data-retrieval method calls
11. JCache API
@CacheResult
User getUserForName(String name) { /*do if not cached*/ }
@Inject
Cache<String, User> users;
users.put(user.getName(), user);
User user = users.get(name);
StreamSupport.stream(users.spliterator(), false)
.filter( e -> e.getValue().getAge() > 50)
.count()
12. JCache in Payara Micro
●
Powered by Hazelcast In-Memory Data Grid
●
Integration with Java EE using CDI injection and interceptors
●
Distributed, auto-discovery of nodes by default via multicast
– Data replication and even distribution
– Lite nodes without data in heap
●
Other Hazelcast features available via injected HazelcastInstance
●
Hazelcast Jet library for fast stream processing
15. What is Payara Micro?
• Executable JAR (~60MB disk size, ~30 MB RAM)
• Runs WAR and EAR from command line
• Fully embeddable (if you want…)
• Forms dynamically scalable cluster
• Web Profile “plus”
• On Maven Central
16. Scale dynamically
●
Run multiple instances with the same command
java -jar payara-micro.jar --deploy application.war
●
Package as a single executable JAR
java -jar payara-micro.jar --deploy application.war –outputUberJar
application.jar
●
Run embedded
PayaraMicro.getInstance().addDeployment("application.war").bootStrap()
●
Run using Maven plugin
19. REST services in Java EE
●
JAX-RS endpoint
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public User getUser(@PathParam("id")
Integer id) {
return userById(id);
}
●
JAX-RS client
User user = client.target(url).path("all").request().get(User.class)
20. REST services in Java EE
●
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
- Payara Micro 5-Alpha
More about JSON-B:
http://json-b.net
22. CDI events, really?
●
Part of Java EE API already
●
Easy to send and observe messages
●
Is it enough? What about:
– Sending events to other services
– Message broker to decouple services
– Transactions
23. CDI events, really?
●
Part of Java EE API already
●
Easy to send and observe messages
●
Is it enough? What about:
– Sending events to other services (nothing else is important initially)
– Message broker to decouple services
– Transactions
24. Events as an initial abstraction
●
Transfer events to other services manually
– Using distributed queues
– Using any message broker
●
Or use a solution provided by the cluster out of the box
Temporary solutions often become final solutions
(when sufficient)
25. Payara CDI event bus
●
Out of the box in messaging in Payara Micro
●
Uses already embedded Hazelcast
●
No configuration needed, events reliably dispatched to all observers
@Inject @Outbound
Event<MyPayload> event;
void onMessage(
@Observes @Inbound
MyPayload event)
27. One more option… JCA connector
●
Message-driven beans, does it ring the bell?
– Not only for JMS but for any messaging infrastructure
●
Connetors exists for Amazon SQS, Azure Bus, Kafka, MQTT
– https://github.com/payara/Cloud-Connectors
@MessageDriven(activationConfig = { … })
public class KafkaMDB implements KafkaListener {
@OnRecord( topics={"test"})
public void getMessageTest(ConsumerRecord record) {
…
30. Or evolution to avoid refactoring
event observer
JCA
connection
observer
MDB
event
31. 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/
36. Is there a free lunch?
●
JVM and managed resources often monitored out of the box by runtimes
– Thread & connection pools, HTTP and EJB stats, CPU and MEM usage
●
Payara Micro
– Metrics over JMX, REST
– Notifiers route data from Request tracing & Health checks
●
Microprofile
– Metrics – monitoring data, statistics
– Health – problem detection and autorecovery (green/red light)
39. Cloud-ready with Payara Micro
Not by accident:
Payara Micro is designed for running resilient Java
EE applications in a modern containerized /
virtualized infrastructure.
Steve Millidge,
Payara project lead
https://www.payara.fish/