Upload
edgar-silva
View
819
Download
0
Embed Size (px)
Citation preview
Microservices Server – MSS Workshop Edgar Silva edgar @wso2.com
2
Basics Pre-Reqs
Chapter 1 – Getting Started
o Java 8 o Maven o See the MSS’s releases page:
o https://github.com/wso2/product-mss/releases o Let’s work direct from the source:
o Git pull o https://github.com/wso2/product-mss
o Or simply download from this url: (easier) https://github.com/wso2/product-mss/archive/master.zip
4
5
o So, cd <MSS_HOME>/samples
o Make you sure you could import the project hello_world
6
o Go to the dir: o <MSS_HOME>/samples/hello_world
o Type: mvn package
7
o After Maven process o ( be pacient with downloading J ) o What is happening:
o The pom.xml inside the sample, inherits the dependencies from the root’s pom.xml, that’s why you don’t need to worry with this process
o In a few (seconds) you will have a hello_service....jar into your target folder.
8
9
• WSO2 Microservices Server booting in my case less than 300ms • In the previous maven process, every dependency from other jars
were included into your helloworld-1.0.0-SNAPSHOT.jar, including the
reference to the Main Java Class. • Everything you need is ready J
10
package org.wso2.carbon.mss.example; import javax.ws.rs.GET;import javax.ws.rs.Path;import javax.ws.rs.PathParam; /** * Hello service resource class. */@Path("/hello")public class HelloService { @GET @Path("/{name}") public String hello(@PathParam("name") String name) { return "Hello " + name; } }}
JAX-RS
Simple class (REST Endpoint
REST Java Method
o The simplest Java Class startup o See the main method:
11
public class Application { public static void main(String[] args) { new MicroservicesRunner() .deploy(new HelloService()) .start(); }
12
edgar$curl-vhttp://localhost:8080/hello/valentina
o Take a look on this: o http://www.confusedbycode.com/curl/
13
14
public class Application { public static void main(String[] args) { new MicroservicesRunner(7888, 8888) .deploy(new HelloService()) .start(); }
Services exposed through different ports(*)
(*) Default port is 8080 when no ports are specified
15
1. Enter in the <mss_home>/samples/stockquote-service
2. mvn package 3. java -jar target/stockquote-service-1.0.0-
SNAPSHOT.jar
16
o In the console type: (Windows Users o curl -v http://localhost:8080/stockquote/GOOG
17
o Now we will send a POST message to our Service: o Please type (or copy and paste) the following command:
o curl-v-XPOST-H"Content-Type:application/json"-d'{"symbol":"BVMF","name":"Bovespa","last":149.62,"low":150.78,"high":149.18,"createdByHost":"localhost"}'http://localhost:8080/stockquote
o This command will save a new Symbol into our Stock Quote Service
18
o You had used: o Java 8 + maven for building our samples and
exercises o Executed Microservices with basic jar –jar
approach o You saw how easy you can build REST Services
and deploy them into your Mic’service Server (powered by WSO2)
19
20
o Several approaches for a “decoupled SOA” o In this tutorial we will use the “Container-
based approach” o Microservices are about:
o Lighter o Business Need Oriented o Composable
21
22
Web Server
ASP.NET ADO.NET
Windows OS
.NET CLR Runtime Front-Store HTML
23
Web Server
Web Framework (JSF, Struts,
etc)
Persitence (JPA,
Hibernate,SpringTemplates)
Any OS
JVM
Other (JMS, JTA
etc)
App Server
Front-Store HTML
24
ProductService
get/productspost/productsget/products/{id}get/products/offset/10/1
CustomerService
get/customerspost/customersget/customers/{id}get/customers/export
AddressService
get/addresspost/address/{zip}get/address/geo/{x}/{y}
3 Examples
25
ProductService
CustomerService
AddressService
AddressService ProductService
CustomerService
AddressService CustomerService
SinglePage APP HTML
FrontStoreService
Delivery Service
o Quick deployments o You are deploying a loosely-coupled, modular
component only J o Not a huge EAR with dozens of Jars as you used to do in
a monolithic enterprise App
26
27
Monolithic
Microservices
Reference: http://martinfowler.com/articles/microservices.html#ComponentizationViaServices
28
Paulo Merson https://insights.sei.cmu.edu/saturn/2015/11/defining-microservices.html Great definition, written by another Brazilian J
From an architecture perspective, the microservice style belongs primarily to the deployment view. It dictates that the deployment unit should contain only one service or just a few cohesive services. The deployment constraint is the distinguishing factor. As a result, microservices are easier to deploy, become more scalable, and can be developed more independently by different teams using different technologies.
“
o Benefits of using microservices:
o Deployability o Availability o Scalability o Modifiability o Management
29
Paulo Merson https://insights.sei.cmu.edu/saturn/2015/11/microservices-beyond-the-hype-what-you-gain-and-what-you-lose.html ( Great post )
o I would add: o Deployability o Availability (Auto-Scaling via Containers) o Analytics o Scalability o Modifiability o Management
30
Paulo Merson https://insights.sei.cmu.edu/saturn/2015/11/microservices-beyond-the-hype-what-you-gain-and-what-you-lose.html
o Part 2: (Soon) o Analytics o Auto-Scaling with Kubernetes and Docker
31
http://www.wso2.com
32