32
Microservices Server – MSS Workshop Edgar Silva edgar @wso2.com

WSO2 Micro Services Server - Basic Workshop Part 1

Embed Size (px)

Citation preview

Page 1: WSO2 Micro Services Server - Basic Workshop Part 1

Microservices Server – MSS Workshop Edgar Silva edgar @wso2.com

Page 2: WSO2 Micro Services Server - Basic Workshop Part 1

2

Basics Pre-Reqs

Page 3: WSO2 Micro Services Server - Basic Workshop Part 1

Chapter 1 – Getting Started

Page 4: WSO2 Micro Services Server - Basic Workshop Part 1

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

Page 5: WSO2 Micro Services Server - Basic Workshop Part 1

5

Page 6: WSO2 Micro Services Server - Basic Workshop Part 1

o  So, cd <MSS_HOME>/samples

o  Make you sure you could import the project hello_world

6

Page 7: WSO2 Micro Services Server - Basic Workshop Part 1

o  Go to the dir: o  <MSS_HOME>/samples/hello_world

o  Type: mvn package

7

Page 8: WSO2 Micro Services Server - Basic Workshop Part 1

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

Page 9: WSO2 Micro Services Server - Basic Workshop Part 1

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

Page 10: WSO2 Micro Services Server - Basic Workshop Part 1

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

Page 11: WSO2 Micro Services Server - Basic Workshop Part 1

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(); }

Page 12: WSO2 Micro Services Server - Basic Workshop Part 1

12

edgar$curl-vhttp://localhost:8080/hello/valentina

Page 13: WSO2 Micro Services Server - Basic Workshop Part 1

o  Take a look on this: o  http://www.confusedbycode.com/curl/

13

Page 14: WSO2 Micro Services Server - Basic Workshop Part 1

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

Page 15: WSO2 Micro Services Server - Basic Workshop Part 1

15

Page 16: WSO2 Micro Services Server - Basic Workshop Part 1

1.  Enter in the <mss_home>/samples/stockquote-service

2.  mvn package 3.  java -jar target/stockquote-service-1.0.0-

SNAPSHOT.jar

16

Page 17: WSO2 Micro Services Server - Basic Workshop Part 1

o  In the console type: (Windows Users o  curl -v http://localhost:8080/stockquote/GOOG

17

Page 18: WSO2 Micro Services Server - Basic Workshop Part 1

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

Page 19: WSO2 Micro Services Server - Basic Workshop Part 1

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

Page 20: WSO2 Micro Services Server - Basic Workshop Part 1

20

Page 21: WSO2 Micro Services Server - Basic Workshop Part 1

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

Page 22: WSO2 Micro Services Server - Basic Workshop Part 1

22

Web Server

ASP.NET ADO.NET

Windows OS

.NET CLR Runtime Front-Store HTML

Page 23: WSO2 Micro Services Server - Basic Workshop Part 1

23

Web Server

Web Framework (JSF, Struts,

etc)

Persitence (JPA,

Hibernate,SpringTemplates)

Any OS

JVM

Other (JMS, JTA

etc)

App Server

Front-Store HTML

Page 24: WSO2 Micro Services Server - Basic Workshop Part 1

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

Page 25: WSO2 Micro Services Server - Basic Workshop Part 1

25

ProductService

CustomerService

AddressService

AddressService ProductService

CustomerService

AddressService CustomerService

SinglePage APP HTML

FrontStoreService

Delivery Service

Page 26: WSO2 Micro Services Server - Basic Workshop Part 1

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

Page 27: WSO2 Micro Services Server - Basic Workshop Part 1

27

Monolithic

Microservices

Reference: http://martinfowler.com/articles/microservices.html#ComponentizationViaServices

Page 28: WSO2 Micro Services Server - Basic Workshop Part 1

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.

Page 29: WSO2 Micro Services Server - Basic Workshop Part 1

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 )

Page 30: WSO2 Micro Services Server - Basic Workshop Part 1

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

Page 31: WSO2 Micro Services Server - Basic Workshop Part 1

o  Part 2: (Soon) o  Analytics o  Auto-Scaling with Kubernetes and Docker

31

Page 32: WSO2 Micro Services Server - Basic Workshop Part 1

http://www.wso2.com

32