微服务 1 springboot

1.介绍microservice

2.介绍springboot

3.创建协作的微服务

4.docker部署微服务

5.添加api描述,openapi/swagger

6.添加持久层

7.reactive microservice

构建 scalable, resilient and manageable microservice

问题:

  • How I learned about microservices and what experience I have of their benefits and challenges

autonomous software component, having its own persistence and communicating with api

多个好处:Decomposing the platform's functionality into a set of autonomous software components provides a number of benefits:

好处1:deploy parts of system, integrating existing systems

好处2:replace components with customers'

好处3:being delievered and upgraded seperately

好处3:scaled out to serveral server instances independently

面临挑战:

挑战1:manually configuring load balancers and manually setting up new nodes. time-consuming and error-prone.

挑战2:chain of failures

挑战3:keepping the configuration consistent and up-to-date in all of instances of components

挑战4:monitoring, in terms of latency issues and hardware usage(CPU, memory, disk and the network)

挑战5 collecting log files and correlating related log events

  • What is a microservice-based architecture?

defining microservice: splitting up a monolithic application into smaller components, achieving two goals:

1. faster development, enabling continuous deployments

2.easier to scale, manually or automatically

an autonomous software component: independently upgradable and scalable

条件1:mircroservices don't share data in database

条件2:communicating with well defined interface

条件3:deployed as seperate runtime processes, such as docker

条件4:microservice instance is stateless

How big should a microservice be?

1.small enough  to fit to the head of a develper

2.not jeopardize performance(latency) or data consistency

  • Challenges with microservices

1.many small components, synchronise communication, a chain of problems

2.configuration up-to-date, many small components,  challenging

3.track a request involved many components, root cause analysis, log events locally

4.analyzing the usage of hardware resources

5.manual configuration, error prone

the 8 fallacies of distributed system

1.the network is reliable

2.latency is zero

3.bandwidth is infinite

4.the network is secure

5. topology doesnt change

6.there is an adminstrator

7.transport cost is zero

8.the network is homogenous

the rule of thumb:

detecting problems, restarting failed components, request to failed component should be resumed when fixed, all of these need to be fully automated.

  • Design patterns for handling challenges

the design patterns:

service discovery, edge server, reactive microservices, central configuration, centralized log analysis, distributed tracing, circuit breaker, control loop, centralized monitor and alarm.

spring boot, spring cloud, kubernetes

service discovery

problem: discover microservice

solution: a service discovery service

solution requirments:

1.automatically register or unregister microservices

2.logic endpoint,  request will be routed to one of the microservices

3.load banlance

4. detect instances that are not currently healthy.

two different strategy:

1.client side routing

2.server side routing

edge server:

problems:expose some of the microservices to the outside, and hide the remaining. protected against the requists from malicious clients.

solution:edge server that all incoming requists will go through.

reverse proxy, intergrated with discover service to provide dynamic load balancing capabilities.

solution requirments:

1.internal services should not be exposed to outside; only ruote requests to microservices that are configured to allow external requiests.

2.expose and protect external services from malicious requiests, use OAuth, OIDC, JWT TOKENs and api keys to ensure the clients are trustworthy.

reactive service

problem:synchronize communication using blocking I/O(a restful json api over http),the number of concurrent requests, longer response time, crashing server. overusing breaking I/O, error prone,  a chain of failures, Circuit Breaker,.

solution: use non-blocking I/O, no thread are allocated while waiting

solution requirements: an asynchronous programming model, resilient

central configuation

problem: how do I get a complete picture of configuration, how do I update the configuration

solution: a configuration server

solution requirments: store configuration information for a group of microservices, with different settings for different enviroments(dev, test, prod, qa)

centalized log analysis

problem: How I get an overview of what is going on in the system landscape?find out microservices getting into trouble and start writing error message, find related log messages, Identify which microservice instance is the root cause of the problem

solution: centralized logging,

collecting new logs, interpreting and storing log events in a structured and searchable way in a central database

providing APIs and graphic tools

distributed tracing:

problem: track requests and messages that flow between microservices

ideantify the root cause, find log message related to a specific order number

solution:correlation ID

solution requirments:assign correltion ID to a request, add the correlation ID when a micrservice makes a request.  add the correlation ID to all log events

circuit breaker

problem: synchronized intercommunication, a chain of failure

synchronous requests, blocking I/o

solution: a circuit breaker that prevents new and outgoing requests.

solution requirements: open the circuit and fail fast

probfor failure correction(half open circuit)

close the circuit if the probs detect the service is healed (self heal)

control loop

problem: difficult to manually detect and correct problems

solution:

a control loop constantly observers and , if required, takes action

solution requirements:

kubernetes

centralized monitoering and alarms

problem:

very hard to discover the root cause of problem

solution:

a monitor service

solution rquirements:

collect metrics from all the servers

detect new microservice instance

privide apis and graphic tools

  • Software enablers that can help us handle these challecornges

spring boot

spring cloud

Docker

Kubernates

Istio(a service mesh)

  • Other important considerations that aren't covered in this book

other important configuration

1.Importance of dev/ops: shorter delivery time,

2.conway's law:

3.decomposing a monolithic application into microservices:slow delivery, slow performance, inconsistant data

4.importance of api design: the same concept, the same description in terms of naming and data type; evolve in a controller manner

5.migration path from on-premise to the cloud

6.good design principles for microservices, the 12 factor api

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
微服务是一种面向服务的架构风格,它将一个大型应用程序拆分成多个小型服务,每个服务都可以独立开发、部署和扩展。Spring Boot是一种用于简化Spring应用程序开发的框架,它可以帮助开发人员更快地创建独立的、可执行的Spring应用。 在微服务架构中,使用多个数据源是一种常见的需求。可以通过以下步骤来设计和实现Spring Boot的多数据源适配: 1. 配置数据源:首先,在应用程序的配置文件中配置多个数据源。每个数据源应该具有唯一的名称和相应的数据库连接信息。 2. 定义数据源管理类:创建一个数据源管理类,用于管理多个数据源。可以使用Spring的@Qualifier注解来标识不同的数据源,并使用@Autowired注解自动注入数据源。 3. 配置事务管理:对于多数据源情况下的事务管理,需要配置多个事务管理器。可以使用Spring的@Primary注解来标识默认的事务管理器,并使用@Bean注解将所有的事务管理器配置为一个bean。 4. 使用数据源:在需要使用数据源的地方,使用@Qualifier注解指定具体的数据源。例如,在Repository层使用@Qualifier注解指定使用哪个数据源。 通过以上步骤,就可以在Spring Boot中实现多数据源的适配。开发人员可以根据具体的业务需求配置和管理多个数据源,并在需要的地方使用不同的数据源来访问并操作数据库。 总之,通过Spring Boot的灵活性和强大的功能,可以方便地适配和管理多个数据源。这样就能满足微服务架构中对于多数据源的需求,并提供更强大和灵活的数据访问能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值