Spring Tutorial – Միկրոսպասարկում Spring Boot շրջանակով,en

Microservice with Spring Boot framework

Spring Tutorial – Միկրոսպասարկում Spring Boot շրջանակով,en

Overview:

Միկրոծառայությունների հայեցակարգը լայնորեն կիրառվում է ձեռնարկություններում,en. Compared to the monolithic IT systems, Microservices offer more benefits and help overcome the limitations of the monolithic systems, especially in the context of modern-day needs of the enterprises. 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. The Spring Boot harnesses all good things about the Spring Framework that are necessary for Microservice development and customizes the 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. Servicesառայությունները հայտնի են նաև որպես մոդուլներ և դրանք կարող են ինքնուրույն կառավարել ծրագրակազմի մոդուլը,,en,Առայությունները կարող են լինել,,en,և սովորաբար լինում են,,en,տարբերվում են միմյանցից,,en,Theառայությունները պետք է շփվեն միմյանց հետ, և նրանք կարող են դա անել տարբեր եղանակներով,,en,Հաղորդակցության ընտրված եղանակը կախված է ծրագրային ապահովման պահանջներից,,en,որոշ ստանդարտ արձանագրություններ, որոնք օգտագործվում են մշակողների կողմից, HTTP/REST են JSON- ով կամ Protobuf- ով,,en,DevOps- ի մասնագետները կարող են օգտագործել ցանկացած արձանագրություն, որն իրենց կարծիքով հարմար է,,en,ներկայացուցչական պետական ​​փոխանցում,,en,արձանագրությունը օգտակար է համարվում համեմատաբար ցածր բարդության պատճառով,,en,Հավանաբար միկրոսերվիսները հասկանալու լավագույն միջոցը և դրա առավելությունները համեմատել մոնոլիտ ծրագրային համակարգերի հետ,,en,Միկրոծառայությունները անդրադառնում են մոնոլիտ համակարգերի որոշակի սահմանափակումներին,,en,Մոնոլիտ համակարգում ծառայությունները սերտորեն կապված են,,en. 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. The way chosen to communicate depends on the software requirements. 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. Generally, 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. Դրա պատճառով,,en,եթե մեկ կամ մի քանի ծառայություններ թարմացվեն կամ ամրագրվեն,,en,մյուս ծառայությունները նույնպես ազդվում են, քանի որ բոլոր ծառայությունները պետք է վերամշակվեն և վերաբաշխվեն,,en,Մոնոլիտ համակարգերն ունեն նաև գործարկման ժամանակի մեկ համակարգ, որն ազդում է բոլոր ծառայությունների վրա,,en,պահանջվում է, թե ոչ,,en,մոնոլիտ համակարգերի թերությունները անհարկի վերաբաշխումներն են,,en,սերտորեն զուգակցված ծառայություններն առաջարկում են նվազագույն կամ ընդհանրապես ճկունություն,,en,անարդյունավետություն և բարձր ծախսեր,,en,Համեմատեք մոնոլիտ համակարգերը Միկրոսպասարկման ճարտարապետության հետ,,en,եթե Ձեզ անհրաժեշտ է թարմացնել կամ շտկել ծառայությունը,,en,Դուք դա անում եք ՝ առանց ազդելու մյուս ծառայությունների վրա,,en,Դու կարող ես,,en,անհրաժեշտ է վերանայել հաղորդակցության արձանագրությունը թարմացումից կամ շտկումից հետո,,en,քանի որ ծառայությունները թույլ են զուգակցված,,en,փոխարինումը հեշտ է ՝ առանց համակարգի վրա ազդելու,,en,Երեք,,en, 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, monolithic systems’ disadvantages are unnecessary redeployments; 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. It offers certain unique ways that help you build applications easily. First, it helps you avoid writing verbose code, also referred to as Boilerplate software development by simplifying code writing. Երկրորդ, 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 ծրագրային ծրագրեր կառուցելիս, բայց նույնիսկ պնդում է, որ ծրագրավորողներն ազատում են ներմուծման մասին հայտարարություններ գրելուց,,en,Գարնանային կոշիկ - ինչ կապ ունի,,en,հեշտացնում է Միկրոծառայությունների զարգացումը, քանի որ ծրագրավորողները կարող են ընտրել,,en,և օգտագործեք շրջանակից պահանջվող բաղադրիչները ՝ առանց բաղադրիչների մանրամասների վրա չափազանց շատ ժամանակ ծախսելու,,en,Spring Boot- ը գտնվում է Spring Framework- ի վերևում և այն տալիս է մշակողներին այն, ինչ նրանք պետք է, որպեսզի մշակողները կարիք չունեն զննել շրջանակը և ժամանակ ծախսել գարնանային հավելվածի բաղադրիչների կառուցման վրա:,,en,Կարող եք ասել, որ դա մի տեսակ մինի շրջանակ է,,en,Spring Boot- ը նպաստում է ավելի մեծ արտադրողականության ՝ դարձնելով այնպիսի հասկացություններ, ինչպիսիք են RESTful HTTP- ը և ներկառուցված վեբ ծրագիրը, դյուրին օգտագործման և տեղակայման համար,,en.

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 rests on top of the Spring Framework and it gives the developers what they need so developers do not need to scour the framework and spend time on building components for the Spring application. 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- ը ապահովում է հարմար մեխանիզմ `ծրագրեր կառուցելու համար,,en,հայտնի է որպես Գարնանային նախաստորագրող,,en,Այն հեշտացնում է զարգացումը ՝ թույլ տալով մշակողներին ընտրել հենց իրենց անհրաժեշտ գրադարանները,,en,մետատվյալների տրամադրում և պարզապես նախագծի ստեղծում,,en,Միկրոծառայությունների զարգացումը կարող է արագացվել Spring Boot- ի միջոցով,,en,Միկրոծառայություններ ստեղծելու համար,,en,գարնանային շրջանակի օգտագործմամբ,,en,մենք պետք է հետևենք որոշակի քայլերի,,en,Այդ քայլերը մենք կքննարկենք մեկ առ մեկ,,en,Առայության գրանցում,,en,Միկրոծառայությունները իրականում միասին աշխատող տարբեր գործընթացներ են,,en,Սա ծառայությունների վրա հիմնված հաղորդակցություն է `բաղադրիչ ճարտարապետության փոխարեն,,en,այդ միկրոսպասարկումները գտնելու համար,,en,որոշ գրանցամատյան պետք է պահպանվի,,en,բոլոր միկրոծառայությունները կգրանցվեն այնտեղ,,en,Կան գրանցման մի քանի սերվեր,,en,հասանելի է շուկայում,,en,Մեկը կոչվում է «Էվրիկա»,,en, 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. Ընդհանուր, development of Microservices can be expedited using Spring Boot.








Sample դիմումը & Configuration

For creating microservices (by using Spring framework), we need to follow certain steps. We will discuss those steps one by one.

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 (բաց աղբյուր) available in the market. One is called ‘Eureka’ որը ներառված է գարնանային ամպի կողմից,,en,Գարնանային ամպը նաև աջակցում է «հյուպատոսին»,,en,որն այլընտրանք է «Eureka» - ին,,en,Օրինակ գրանցման սերվեր,,en,@EnableEurekaServer,,en,հանրային դասի ServiceRegServer,,en,Spring Boot- ը կփնտրի registration-server.yml,,en,System.setProperty,,en,spring.config.name,,en,գրանցման սերվեր,,en,SpringApplication.run,,en,ServiceRegServer.class,,en,pom.xml,,bg,Այս բաժնում մենք ստուգելու ենք pom.xml կազմաձևման ֆայլի հիմնական բաղադրիչները,,en,Նմուշ pom.xml կազմաձևման ֆայլ,,en,org.springframework.cloud,,en,գարուն-ամպ-սկսնակ-ծնող,,en,_Brixton..RELEASE,,en,Կարգավորեք գարնանային կոշիկը,,en,Spring-boot-starter,,en,Կարգավորեք Spring MVC և REST,,en,օգտագործելով ներկառուցված Tomcat սերվեր,,en,Գարնանային ամպի մեկնարկիչ,,en,գարուն-ամպ-մեկնարկիչ,,en,Վերցրեք Eureka- ն ծառայության գրանցման համար,,en,spring-cloud-starter-eureka-server,,en,Հատկությունների ֆայլ,,en,Գարնանային բեռնման ծրագիրը միշտ ստուգում է application.properties կամ application.yml ֆայլը ՝ կազմաձևման հետ կապված տեղեկատվության համար,,en. Spring cloud also supports ‘Consul’, which is an alternative to ‘Eureka’.

Listing 1: Sample registration server

@SpringBootApplication

@EnableEurekaServer

public class ServiceRegServer {

 

հասարակական ստատիկ անվավեր հիմնական(Լար[] 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: Sample pom.xml configuration file

<parent>

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

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

<version>_Brixton_.RELEASE</version>

</parent>

<dependencies>

<կախվածություն>

<!– Setup Spring Boot –>

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

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

</կախվածություն>

<կախվածություն>

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

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

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

</կախվածություն>

<կախվածություն>

<!– Spring Cloud starter –>

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

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

</կախվածություն>

<կախվածություն>

<!– Take Eureka for service registration –>

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

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

</կախվածություն>

</dependencies>

Properties file:

Spring boot application always check application.properties or application.yml file for configuration related information. Այս դիմումում,,en,մենք կունենանք application.yml,,en,reg-srever.yml,,cy,ֆայլ ՝ կազմաձևման հետ կապված տեղեկատվությունը պահելու համար,,en,Բացահայտման սերվերի կազմաձևում,,en,էվրիկա,,en,հյուրընկալողի անունը,,en,հաճախորդ,,en,registerWithEureka- ով,,en,fetchRegistry,,en,եթե բացենք Eureka- ի վահանակը http- ում,,en,դիմումների բաժինը դատարկ կլինի,,en,մենք պետք է միկրոծառայությունը գրանցենք հայտնագործման սերվերի հետ,,en,եթե թարմացնենք վահանակը,,en,այնտեղ ցույց կտա միկրոսպասարկումը,,en,Spring boot start-up դասի կազմաձևում,,en,Սա Spring boot start-up դաս է,,en,Սա դիմումի հիմնական մուտքի կետն է,,en,Sample Spring boot starter class,,en,@EnableAutoConfiguration,,en,@EnableDiscoveryClient,,en,@Ներմուծում,,en,SampleWebApplication.class,,en,հանրային դասի AccServer,,en,AccRepository accRepository,,en,Կարգավորեք acc-server.yml- ի միջոցով,,en,acc-server,,en,AccServer.class,,en,Գրանցումը հայտնագործման սերվերի հետ,,en,մենք գրանցելու ենք դասը հայտնագործման սերվերի հետ,,en,Գրանցվեք հայտնագործման սերվերի հետ,,en, we will have application.yml (reg-srever.yml) file for storing configuration related information.

Listing 3: Sample registration server

# Discovery server configuration

eureka:

օրինակ:

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:

This is the Spring boot start-up class. 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;

հասարակական ստատիկ անվավեր հիմնական(Լար[] 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

# Գարնանային հատկությունների մանրամասները,,en,acc-service,,en,Բացահայտման սերվերի մուտքի մանրամասներ,,en,serviceUrl,,fr,defaultZone,,en,eureka/,,en,HTTP սերվերի մանրամասները,,en,թարմացրեք վահանակը,,en,և այն ցույց կտա միկրոծառայությունը, որը թվարկված է հավելվածների բաժիններում,,en,Թվում է, թե ծրագրավորողի արտադրողականության բարձրացումը և ժամանակը խնայելը Գարնանային կոշիկի և միկրոսպասարկումների համադրության երկու ամենակարևոր հատկանիշներից են,,en,սա նաև պետք է նշել, որ դա դեռ համեմատաբար նոր հասկացություն է, և ժյուրին չի կողմնորոշվում դրա համընդհանուր կիրառելիության մեջ, և շոշափելի օգուտները դեռ կուտակվում են,,en,Կարդացեք ավելի շատ հոդվածներ գարնան մասին,,en

spring:

application:

անվանում: 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.








Ամփոփում

It seems improving developer productivity and saving time are two of the most important features of the Spring Boot and Microservices combination. However, this also needs to be noted that it is still a relatively new concept and the jury is out on its universal applicability and the tangible benefits are yet to accrue.

Explore – Read more articles on Spring

 

============================================= ============================================== Գնեք լավագույն տեխնոլոգիական գրքերը Amazon- ում,en,Էլեկտրականություն CT շագանակագույն էլեկտրաէներգիա,en
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Enjoy this blog? Please spread the word :)

Follow by Email
LinkedIn
LinkedIn
Share