microservices with wildfly swarm - javasi 2016

38
Microservices with WildFly Swarm Charles Moulliard (@cmoulliard) 17 Oct 2016

Upload: charles-moulliard

Post on 09-Jan-2017

574 views

Category:

Technology


2 download

TRANSCRIPT

Microservices withWildFly Swarm

Charles Moulliard (@cmoulliard)17 Oct 2016

 

Who

Coder, Architect

Red Hat Engineer : Architect/Project lead for Global Platform Team

Apache Camel, Fabric8, WildFly Swarm, JBoss Forge committer

Mountain Biker, Belgian Beer Fan

Blog:

Twitter:

Email:

http://cmoulliard.github.io

@cmoulliard

[email protected]

Agenda

The Context: Microservices and Java EE

WildFly Swarm: Concepts, Ideas & Mechanics

Code and Demo

Discussions and (hopefully) beer

Microservices

 

… SOA …

 

– Martin Fowler, ThoughtWorks

Mono to Micro

Example

Be more concrete

 

 

 

… & Java EE

 

Perspectives on JavaEE

A collection of (useful) API’s

Stack of Frameworks

Designed to support distributed apps

Is JavaEE Ready Microservices ?

Depends what JavaEE 8/9 spec will propose

Does it support Microservices patterns ?

New initiative emerges :

https://microprofile.io/

Perception

Stack of …..

Plus JVM

What I really need

WildFly Swarm

 

Intro

OSS Project sponsored by Red Hat

Compatriot of Wildfly Application Server

Support MicroProfile

Microservices ready

Part of a bigger system of interrelated projects under the JBoss / Red Hatumbrella

Just Enough App Server

Use the API’s you want

Include the capabilitiesyou need

Wrap it up for deployment

Uber Jar

A single .jar file containing yourapplication,

the portions of WildFly required tosupport it,

an internal Maven repository ofdependencies,

plus a shim to bootstrap it all

Fractions

A well-defined collection of application capabilities.

May map directly to a WildFly subsystem,

or bring in external capabilities such as Netflix Ribbon.

What Fractions can do

Enable WildFly subsystems (JAX-RS, Infinispan)

Integrate additional system capabilities (Topology)

Provide deployment (ribbon-webapp, jolokia)

Alter deployment (keycloak)

Some Fractions

Convert Java EE App touse WildFly Swarm

 

Adding Fraction to your build<dependency> <groupId>org.wildfly.swarm</groupId> <artifactId>jaxrs</artifactId> </dependency> <dependency> <groupId>org.wildfly.swarm</groupId> <artifactId>cdi</artifactId> </dependency> <dependency> <groupId>org.wildfly.swarm</groupId> <artifactId>swagger</artifactId> </dependency> ...

Adding maven plugin<plugin> <groupId>org.wildfly.swarm</groupId> <artifactId>wildfly-swarm-plugin</artifactId> <version>${wildfly.swarm.version}</version> <configuration> <properties> <swarm.port.offset>200</swarm.port.offset> </properties> </configuration> <executions> <execution> <goals> <goal>package</goal> </goals> </execution> </executions> </plugin>

Building & running

Build the maven module

$ mvn clean package $ ls -la target/your.jar

Run your Swarm App

$ java -jar target/your.jar $ mvn wildfly-swarm:run

Demo

 

Going beyond simple(and Java EE)

 

Project stageslogger: level: DEBUG swarm: port: offset: 10 --- project: stage: production logger: level: INFO swarm: port: offset: 100

Customize Swarmpublic class MySwarmApp { public static void main(String[] args) throws Exception { Swarm swarm = new Swarm(false).withStageConfig("project-stages.yml"); swarm.fraction(new JAXRSFraction()) .fraction(new LoggingFraction()); // Start the container & deploy the fractions swarm.start().deploy();

Customize Fractionpublic class MySwarmApp { public static void main(String[] args) throws Exception { Swarm swarm = new Swarm(); swarm.fraction( new LoggingFraction().periodicSizeRotatingFileHandler("FILE", (h) -> { h.level(Level.INFO) .append(true) .suffix(".yyyy-MM-dd") .rotateSize("30m") .enabled(true) .encoding("UTF-8") .maxBackupIndex(2); Map<String, String> fileSpec = new HashMap<>(); fileSpec.put("path", logFile); h.file(fileSpec); }).logger("br.org.sistemafieg.cliente", (l) -> { l.level(Level.INFO) .handler("FILE"); }));

Securing accesspublic class MySwarmApp { public static void main(String[] args) throws Exception { Swarm swarm = new Swarm(); swarm.start(); ... // Create the archive and register the resources to be packaged/scanned JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class); archive.as(Secured.class) .protect() .withRole("admin"); swarm.deploy(archive);

(provided by Keycloak: OpenID, SAML, Social Login, OAuth, LDAP, ActiveDirectory)

Demo

 

WildFly Microservices Demo

Questions

Twitter : @cmoulliard

Demos https://github.com/cmoulliard/swarm-openshift

http://wildfly-swarm.io