Spring Tutorial – Microservice with Spring Boot framework

Microservice with Spring Boot framework

Spring Tutorial – Microservice with Spring Boot framework

Ülevaade:

The concept of Microservices is being widely put into practice across enterprises. Compared to the monolithic IT systems, Microservices offer more benefits and help overcome the limitations of the monolithic systems, eriti ettevõtete tänapäevaste vajaduste kontekstis,,en,Kaasaegsed ettevõtted soovivad vähem seisakuid,,en,vilgas juhitavus,,en,ja nende süsteemide paindlikkus,,en,Tugev teenuste sidumine ja teenuste suur vastastikune sõltuvus monoliitsetes süsteemides on takistuseks kaasaegsete ettevõtete soovide saavutamisel,,en,võimaldada suurema süsteemi teenustel olla süsteemne sõltumatus ja lõdvalt seotud, et ettevõtetel oleks suurem paindlikkus ja paindlikkus,,en,Ettevõtted võtavad teadmiseks mikroteenuste eelised,,en,uute jõusüsteemide väljatöötamiseks või olemasolevate toodete uuendamiseks kulutatakse rohkem jõupingutusi ja ressursse,,en,Spring Boot on olnud üks selline süsteem, mis aitab ettevõtetel mikroteenuseid juurutada,,en. Modern enterprises want lesser downtime, agile manageability, and flexibility from their systems. Tight service coupling and high interdependence across services in monolithic systems prove to be a barrier in achieving what modern enterprises want.

Microservices allow services in a greater system to be systemically independent and loosely coupled so that enterprises have greater flexibility and agility. As enterprises take note of the benefits of Microservices, more effort and resources are being expended to develop new supporting systems or upgrade existing products. The Spring Boot has been one such system which helps enterprises to implement the Microservices. Spring Boot kasutab ära kõiki häid asju Spring Framework'i kohta, mis on Microsofti teenuse arendamiseks vajalikud, ja kohandab seda,,en,Microservice'i arendamiseks,,en,Võite öelda, et Spring Boot on mikroraam, mis muudab mikroteenuste ehitamise lihtsamaks, kuna see pakendab supersetist vajalikud moodulid, nii et arendajad saavad vajalikud moodulid ülekoormuseta valida,,en,tuntud ka kui,,en,Mikroteenus,,en,s Arhitektuur,,en,on rühm lõdvalt seotud tarkvarateenuseid, mis moodustavad tarkvarakomplekti,,en,Teenuseid nimetatakse ka mooduliteks ja nad saavad tarkvara moodulit iseseisvalt hallata,,en,Teenused võivad olla,,en,ja tavaliselt on,,en,üksteisest erinevad,,en,Teenused peavad omavahel suhtlema ja nad saavad seda teha mitmel viisil,,en Spring framework for Microservice development. You can say that the Spring Boot is a microframework that makes building Microservices easier because it packages necessary modules from the superset so that developers can choose the necessary modules without getting overwhelmed.








Microservices – What is it?

Microservices, also known as the Microservices Architecture, are a group of loosely coupled software services that constitute a software suite. The services are also known as modules and they can manage a software module independently. The services can be, and usually are, different from one another. The services need to communicate with one another and they can do so in various ways. Suhtlusviis sõltub tarkvara nõuetest,,en,mõned arendajate kasutatavad standardprotokollid on HTTP/REST koos JSONi või Protobufiga,,en,DevOpsi spetsialistid võivad kasutada mis tahes protokolli, mis nende arvates sobib,,en,esinduslik riiklik ülekanne,,en,protokolli peetakse kasulikuks suhteliselt väiksema keerukuse tõttu,,en,Tõenäoliselt parim viis mõista Microsofti teenuseid ja selle eeliseid, võrreldes monoliitsete tarkvarasüsteemidega,,en,Mikroteenused käsitlevad monoliitsete süsteemide teatud piiranguid,,en,Teenused monoliitses süsteemis on tihedalt seotud,,en,Sellepärast,,en,kui ühte või mitut teenust uuendatakse või parandatakse,,en,see mõjutab ka teisi teenuseid, sest kõik teenused tuleb uuesti kompileerida ja ümber paigutada,,en,Monoliitsetel süsteemidel on ka üks tööaja süsteem, mis mõjutab kõiki teenuseid,,en,nõutud või mitte,,en. Still, some of the standard protocols used by the developers are HTTP/REST with JSON or Protobuf. DevOps professionals may use any protocol they think is suitable. üldiselt, the Representational State Transfer (REST) protocol is considered useful because of the comparatively lower complexity.

Probably the best way to understand Microservices and its benefits to compare with monolithic software systems. Microservices address certain limitations of monolithic systems. Services in a monolithic system are tightly coupled. Because of that, if one or more services are updated or fixed, the other services are also impacted because all services must be recompiled and redeployed. Monolithic systems also have a single run time system which impacts all services, required or not. So, monoliitsete süsteemide puudused on tarbetud ümberpaigutamised,,en,tihedalt seotud teenused pakuvad minimaalset paindlikkust või üldse mitte,,en,ebaefektiivsus ja suured kulud,,en,Võrrelge monoliitseid süsteeme mikroteenuste arhitektuuriga,,en,kui teil on vaja teenust värskendada või parandada,,en,teete seda ilma teisi teenuseid mõjutamata,,en,Sa võid,,en,peate pärast uuendamist või parandamist suhtlusprotokolli üle vaatama,,en,kuna teenused on lõdvalt seotud,,en,asendamine on lihtne, ilma et see mõjutaks süsteemi,,en,Kolm,,en,saate alati teenuseid kasutada vastavalt nõuetele, olenemata sellest, kuidas nad suhtlevad või üksteisest sõltuvad,,en,Neli,,en,ümberpaigutamisel,,en,ainult mõjutatud teenus paigutatakse ümber,,en,Mis on kevadjalats,,en,on uus raamistik, mis aitab teil luua kevadisi rakendusi,,en,Kuigi see ei kõla Spring Booti kohta midagi ainulaadset,,en,kuidas see aitab teil kevadisi rakendusi luua,,en; tightly coupled services offer minimal or no flexibility; inefficiency and high expenses. Compare monolithic systems with the Microservice Architecture. One, if you need to update or fix a service, you do so without impacting the other services. You may, however, need to review the communication protocol post the update or fix. Two, since the services are loosely coupled, replacement is easy without impacting the system. Three, you always can use services based on requirements regardless of how they communicate or depend on one another. Four, when you redeploy, only the impacted service is redeployed.

Must Read- Steps to work with Spring Integration

What is spring boot?

The Spring Boot is a new framework that helps you build Spring applications. While that sounds nothing unique about Spring Boot, how it helps you build Spring applications is. See pakub teatud ainulaadseid viise, mis aitavad teil hõlpsalt rakendusi luua,,en,see aitab vältida paljusõnalise koodi kirjutamist,,en,mida nimetatakse ka Boilerplate tarkvaraarenduseks, lihtsustades koodi kirjutamist,,en,Selle eesmärk on vabastada tarkvaraarendajad XML -sõltuvusest,,en,midagi, mis oli kevadisele raamistikule üsna omane,,en,Kevadine raamistik,,en,muideks,,en,kandis tugevat kriitikat selle mahuka XML -konfiguratsiooni tõttu,,en,Spring Boot mitte ainult ei vähenda,,en,tarkvararakendusi luues, kuid isegi väidab julgelt, et vabastab arendajad impordiavalduste kirjutamisest,,en,Kevadsaabas - milline on seos,,en,muudab Microsofti teenuste arendamise lihtsamaks, kuna tarkvaraarendajad saavad valida,,en,ja kasutage raamistikust nõutavaid komponente, ilma et peaksite komponentide detailidele liiga palju aega kulutama,,en. First, it helps you avoid writing verbose code, also referred to as Boilerplate software development by simplifying code writing. Teine, it aims to free software developers from XML dependency, something that was quite intrinsic with the Spring framework. The Spring framework, by the way, faced heavy criticism because of its bulky XML configuration. Spring Boot not only reduces the use of XML while building software applications but even makes the bold claim of freeing developers from writing import statements.

Must Read – Steps to learn Spring Batch Service

Microservices & Spring boot – What is the relation?

Spring Boot makes developing Microservices easier because software developers can choose, and use required components from the framework without needing to spend too much time on details of the components. Spring Boot toetub kevadraamistiku peale ja see annab arendajatele vajaliku, nii et arendajad ei pea raamistikku nühkima ja kulutama aega kevadise rakenduse komponentide ehitamisele,,en,Võib öelda, et see on omamoodi miniraamistik,,en,Spring Boot hõlbustab suuremat tootlikkust, muutes sellised mõisted nagu RESTful HTTP ja sisseehitatud veebirakendus hõlpsasti kasutatavaks ja juurutatavaks.,,en,Spring Boot pakub mugavat mehhanismi rakenduste ehitamiseks,,en,tuntud kui kevadine initsiaator,,en,See muudab arendamise lihtsaks, võimaldades arendajatel valida täpselt vajalikud teegid,,en,metaandmete esitamine ja projekti loomine,,en,Microsofti teenuste arendamist saab kiirendada Spring Booti abil,,en,Mikroteenuste loomiseks,,en,Kevadraamistiku abil,,en,peame järgima teatud samme,,en. You can say that it is a kind of mini framework. Spring Boot facilitates greater productivity by making concepts such as RESTful HTTP and embedded web application easy to use and deploy. Spring Boot provides a convenient mechanism for building applications, known as the Spring Initializer. It makes development easy by allowing developers to choose exactly the libraries they need, providing metadata and just generating the project. Üldine, development of Microservices can be expedited using Spring Boot.








proovi taotluse & Configuration

For creating microservices (by using Spring framework), we need to follow certain steps. Me arutame neid samme ükshaaval,,en,Teenuse registreerimine,,en,Mikroteenused on tegelikult erinevad protsessid, mis töötavad koos,,en,See on teenusel põhinev kommunikatsioon, mitte komponendipõhine arhitektuur,,en,nende mikroteenuste leidmiseks,,en,mõnda registrit tuleb säilitada,,en,seal registreeritakse kõik mikroteenused,,en,Seal on paar registreerimisserverit,,en,turul saadaval,,en,Üks neist kannab nime "Eureka",,en,mille ühendab kevadpilv,,en,Kevadpilv toetab ka konsulit,,en,mis on alternatiiv Eurekale,,en,Registreerimisserveri näidis,,en,@EnableEurekaServer,,en,avalik klass ServiceRegServer,,en,Spring Boot otsib registreerimist-server.yml,,en,System.setProperty,,en,spring.config.name,,en,registreerimisserver,,en,SpringApplication.run,,en,ServiceRegServer.class,,en,pom.xml,,bg,Selles jaotises kontrollime pom.xml konfiguratsioonifaili põhikomponente,,en.

Must Read – Spring with Testing frameworks – How does it work?

Registration of service:

Microservices are actually different processes working together. It is a service based communication instead of a component based architecture. Now, to find those Microservices, some registry has to be maintained. And, all the microservices will be registered there. There are couple of registration servers (avatud lähtekoodiga) available in the market. One is called ‘Eureka’ which is incorporated by Spring cloud. Spring cloud also supports ‘Consul’, which is an alternative to ‘Eureka’.

Listing 1: Sample registration server

@SpringBootApplication

@EnableEurekaServer

public class ServiceRegServer {

 

avaliku staatilise void main(String[] args) {

// Spring Boot will look for registration-server.yml

System.setProperty(“spring.config.name”, “registration-server”);

SpringApplication.run(ServiceRegServer.class, args);

}

}

Configuration (pom.xml):

In this section we will check the main components in pom.xml configuration file.

Listing 2: Pom.xml konfiguratsioonifaili näidis,,en,org.pringframework.cloud,,en,kevad-pilv-starter-lapsevanem,,en,_Brixton_.RELEASE,,en,Kevadkäivituse seadistamine,,en,vedru-boot-starter,,en,Seadistage kevad MVC ja REST,,en,kasutades sisseehitatud Tomcati serverit,,en,Kevadpilve käivitaja,,en,kevad-pilve-starter,,en,Võtke teenuse registreerimiseks Eureka,,en,kevad-pilv-starter-eureka-server,,en,Atribuutide fail,,en,Kevadine alglaadimisrakendus kontrollige konfiguratsiooniga seotud teavet alati failist application.properties või application.yml,,en,Selles rakenduses,,en,meil on rakendus.yml,,en,reg-srever.yml,,cy,fail konfiguratsiooniga seotud teabe salvestamiseks,,en,Avastusserveri konfiguratsioon,,en,eureka,,en,hostinimi,,en,klient,,en,registerWithEureka,,en,fetchRegistry,,en,kui avame Eureka armatuurlaua aadressil http,,en,rakenduste jaotis on tühi,,en,peame mikroteenuse registreerima avastusserveriga,,en,kui värskendame armatuurlauda,,en,see näitab seal mikroteenust,,en,Kevadkäivituse käivitusklassi konfiguratsioon,,en

<parent>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-parent</artifactId>

<version>_Brixton_.RELEASE</version>

</parent>

<dependencies>

<sõltuvus>

<!– Setup Spring Boot –>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter</artifactId>

</sõltuvus>

<sõltuvus>

<!– Setup Spring MVC and REST, using embedded Tomcat server –>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</sõltuvus>

<sõltuvus>

<!– Spring Cloud starter –>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter</artifactId>

</sõltuvus>

<sõltuvus>

<!– Take Eureka for service registration –>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-eureka-server</artifactId>

</sõltuvus>

</dependencies>

Properties file:

Spring boot application always check application.properties or application.yml file for configuration related information. In this application, we will have application.yml (reg-srever.yml) file for storing configuration related information.

Listing 3: Sample registration server

# Discovery server configuration

eureka:

näiteks:

hostname: localhost

client:

registerWithEureka: false

fetchRegistry: false

server:

port: 8761 # HTTP (Tomcat) port

Now, if we open the Eureka dashboard at http://localhost:8761, applications section will be empty. So, we need to register the microservice with the discovery server. Now, if we refresh the dashboard, it will show the microservice there.

Spring boot start-up class configuration:

See on Spring boot start-up klass,,en,See on rakenduse peamine sisenemispunkt,,en,Näidisvedru alglaadimisklass,,en,@EnableAutoConfiguration,,en,@EnableDiscoveryClient,,en,@Import,,en,SampleWebApplication.class,,en,avaliku klassi AccServer,,en,AccRepository accRepository,,en,Seadistage acc-server.yml abil,,en,acc-server,,en,AccServer.class,,en,Registreerimine avastusserveriga,,en,registreerime klassi avastusserverisse,,en,Registreeruge avastusserveriga,,en,Kevadiste omaduste üksikasjad,,en,acc-teenus,,en,Discovery Serveri juurdepääsu üksikasjad,,en,serviceUrl,,fr,defaultZone,,en,eureka/,,en,HTTP -serveri üksikasjad,,en,värskendage armatuurlauda,,en,ja see näitab rakenduste jaotistes loetletud mikroteenust,,en,Tundub, et arendaja tootlikkuse parandamine ja aja kokkuhoid on Spring Boot ja Microservices kombinatsiooni kaks kõige olulisemat omadust,,en. This is the main entry point to the application.

Listing 4: Sample Spring boot starter class.

@EnableAutoConfiguration

@EnableDiscoveryClient

@Import(SampleWebApplication.class)

public class AccServer {

@Autowired

AccRepository accRepository;

avaliku staatilise void main(String[] args) {

// Configure using acc-server.yml

System.setProperty(“spring.config.name”, “acc-server”);

SpringApplication.run(AccServer.class, args);

}

}

Registration with discovery server

Here, we will register the class with the discovery server.

Listing 5: Register with the discovery server

# Spring properties details

spring:

taotlus:

nimi: acc-service

# Discovery Server Access Details

eureka:

client:

serviceUrl:

defaultZone: http://localhost:8761/eureka/

# HTTP Server details

server:

port: 8080 # HTTP (Tomcat) port

Now, refresh the dashboard, and it will show the microservice listed under the applications sections.








Järeldus

It seems improving developer productivity and saving time are two of the most important features of the Spring Boot and Microservices combination. However, tuleb ka märkida, et see on veel suhteliselt uus kontseptsioon ja žürii on selle universaalsel rakendamisel väljas ning käegakatsutavat kasu pole veel kogunenud,,en,Loe veel artikleid kevadest,,en.

Explore – Read more articles on Spring

 

============================================= ============================================== Buy best TechAlpine Books on Amazon
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Enjoy this blog? Please spread the word :)

Follow by Email
LinkedIn
LinkedIn
Share