1.Powiedz o sobie, gdzie pracuejsz, jakie projekty
Witam wszystkich: nazywam się Tomasz Lelek, jestem programistą w firmie Schibsted Tech Polska.
Pracuje przy projektach zwiazanych z java.
Mozecie mnie znalesc na twitterze i githubue
Jesli ktos bedzie mial pytania to prosze o zadawanie ich na koniec prezentacji.
2.In my presentatnion i’ll try to show, how to build microservices using scala language and scalatra framework
1, why we want build microserwice architecture ?
2.Which technologies allow us to build them realtivly simply
3.I’ll create new serivice, implement couple rest methods, write some tests, and show how easily use akka actors in that service
4.How to monitor such microservice
4.Why we even want to create architecutre of microserwices ?
In a java work, often we see projects, which could be describe by one work : monolith
Characteristics of arhitecure such projects is very tight coupling, where change in one place in code, could have big impanct on code in place which is totaly not connected with our change.
I am working with application which could be described as Monolith
7 When we made decision to pull out some fucntionality from monolithic app into microserwice, we want to change arhictecture, in a way, which won’t be seen for a end user of our application.
We want our application to work in exact same way as previosly, but handling requests of user will be done not in monoilithic application, but in new microservice.
We want that change be unnoticable for end user.
To be able to achive this, we use simple dispacher ( proxy). When from web application ( browser) request for doing some action which was previosuly done in monolithic app is send, that reqeust is captured by server (eg apache ) and redirect to new microserwice, which execture actions, which was previosuly executed by legacy system application.This is unnoticable for end user.
9.APACHE MOD REWRITE – it works like this : define ..
10.We want to craete miroservices, but we need proper techologies to implement such architecture.
We need some light framework, which enable us to deploy application easily, quickly. Our microserwices need to be really light,
and have only neccessary libraries ( in contraty ot some java framwerork ;)
11.
Concepcual scalatra is based on very poprular ruby framework – sinatra.
It has couple librareis, embedded container jetty, it is based on servlets, it’s written entirly in scala language.
It has integrated couple useful libraries like json mapper
When building microservices we want, our application to start very quickly. Best solution is using embeded container. Micorservice could not be deployd on a container (like tomcat ) which will be starting long time, we want possiliobty to take jar file with packed service, and run that service in one command. We want that to happen very quickly, becuaes it reduce feedback for a developer, therefore he could work much more effectivly.
When you proggraming you service, and you need to wait 40s to see your changes, it disturbs you, you loosing you focus, and flow, therefore tou work much less effectivly. When you could seen you changes in seconds, you reduce you feedback time, you could be much more better in programming,
Our service is then like a packed gift, which need only to be unpack ( run )
13. Only thing that we need to do to run our service is to
Start sbt
Then fire command container:start.
In that moment our application is started on proper port
We see that it took only 2 seconds to run that
Very useful tip :
./sbt
>container:start
~ ;copy-resources;aux-compile
-it’ll be monitoring directory with our project, and if any file will change, it’ll restart our container
Right now i’ll crate simple scalra app, and do some coding
mkdir ScalatraSimpleService
502 cd Scal
503 cd ScalatraSimpleService/
504 ls
505 g8 scalatra/scalatra-sbt
506 ls
507 cd awesomeservice/
508 ls
509 ls
510 cd project/
511 ls
512 cat build.properties
513 cat build.scala
514 ls
515 cat plugins.sbt
516 cd ..
517 ls
518 cat README.md
519 history
./sbt run
Open configurationService, I create meetupController
1.MeetupController
2.MeetupController get test
3.Add to bootstrap
4.MeetupControler post
5.Craete RateAggregateActor, and case class MeetupRate
6.Add to bootstrap
7.Show
8.modify test
14. When we know our tool ( more or less :-) we need to think about architecture.
We want our service to supply light client for other services. Then that client could be imported by other service, which could easily and transparently speak with that first service, without worring about
Sending http reqeust
So: Service importing client of other service, use that client like normal library, and client is responsible for sending requests to that other sercie. All that happends transaprently for serivce which import that light client.
Our services consist of three componenst : proper srecvie, which works on server, it’s run as embeded container, model wich will be shared beetewen client and server ( it is used as a contract ),
And third component is a mentioned light client
15. Each request to our sercie throuout client, which could be imported by another microservies. You could speak to service, also via any other http client, like curl, because each service is created according to rest
-show how client looks like ( configuration service client, maybe show how i implemented caching )
One microservice could supply many light clients, each is written in different language ( scala, java, js ), then other proggramer, which want create microservice in other language, or technology, when want to use that service, only need to import client, which is written in languege of his choice.
I’ll show you how easiliy client written in scala language, work with java code
Spid-lib -> ConfServiceFacade
To that point you could see that each servie is implemented accoring to rest, using json as exhachange format, and proper use of http protocol
18.When building csv-reports-generator and need data form dataservice, we only need to import light client supplied from dataservice.
Then we could easily use dataservice from csv generator transparently.
We could see that architecture of microservice could easily evolve
One example of microservice which we our use in production system is configruation service. It stores data about location of all microservices, and other useful things like db config, amazon sqs confiig, whatever we want
Configuration service is use as a facade abouve etcd nodes.
Etcd nodes are responsible for persistance of data and syncrhonization of data beetween them.
20. Main purpous behind such service, is to create centralized point with all configuration.Then we could use this as following
24. It’s a simple visualization of excerpt of achitrecutre of microservices. We see which service is currenly unavailable. Some services could sometimes went down
Circuit Breaker – in such disrupted environment, failure will ocure sonner or letter.
Idea behind that patter is to find about about failure very quickly, and do not repeat same action, if we know that action will cause failure
Example : when we want to send requet to other microservice, we do not want our service to hang on waiting for response from the,
If system to which we send reqest not responding, then we handle it in proper way, then we could react for failure very quickly
In that way, we avoid cascade failure. If one service hang on waiting for response from other, that service will stop to respond itself, and it will cause another failure, in other service.
It’ll be cascading failure.
29.Hystrix library go to code
42. dziekuje, jakies pytania ?
link na githubie do przykladowego microserwisu, ktory to kazdy moze sobie uruchomic