当前位置:网站首页>Getting started with microservices

Getting started with microservices

2022-07-04 13:46:00 Hua Weiyun

Microservices

Today's application development and IT System management is cloud driven . New cloud applications need to be fast 、 agile 、 Scalable and reliable .
Microservice architecture is a way to decompose large applications into a set of smaller Services . Each service runs in its own process , And use HTTP/HTTPS、WebSocket or AMQP Wait for the protocol to communicate with other processes . Each microservice implements a specific end-to-end domain or business function within a specific context boundary , Every microservice must be developed independently , And it can be deployed independently . Last , Each microservice should have its relevant domain data model and domain logic , And it can be based on different data storage technologies (SQL、NoSQL) And different programming languages .
It can be said that , Microservice is an idea , Split the previous large-scale monolithic applications into one that can run independently , Deployed Services , There is no detailed division of the split here , Generally, a service is responsible for implementing a business function according to the business scenario , The services are connected through HTTPS/HTTP Wait for the protocol to communicate ( Most commonly used Restful API). This is the basic idea of microservice .
Of course, in the actual use of microservices , There will be quite a number of extension issues .
Containerization is a method of software development , Through this method, applications or services can be 、 Its dependencies and their configuration ( Abstracted as a deployment manifest file ) Packaged together as a container image . Container applications can be tested as a unit , And deploy them as container image instances to the host operating system (OS). So use containers , It is an effective method to realize the microservice architecture pattern .
The typical microservice architecture is shown in the figure below :
 Insert picture description here

Docker

Docker Is an open source application container engine , be based on Go Language And follow Apache2.0 Open source agreement .Docker Allows developers to package their applications and dependencies into a lightweight package 、 In a portable container , Then post to any popular Linux On the machine , You can also implement virtualization . Containers are completely sandboxed using the sandbox mechanism , There will be no interface between them ( similar iPhone Of app), More importantly, the container performance overhead is minimal .Docker Is a for development , An open platform for delivering and running applications .Docker Enables you to separate your applications from your infrastructure , So you can quickly deliver software . With the help of Docker, You can manage your infrastructure the same way you manage your applications . By using Docker The way to quickly deliver , Test and deploy code , You can significantly reduce the delay between writing code and running it in a production environment .

docker Use

  1. install docker
  2. Dockerfile
fsutil file createnew Dockerfile 0

The command creation name is Dockerfile The file of
And add the following :

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS buildWORKDIR /srcCOPY backend.csproj .RUN dotnet restoreCOPY . .RUN dotnet publish -c release -o /app

This will perform the following steps in order when called :

  • Pull mcr.microsoft.com/dotnet/sdk:6.0 Image and name it build
  • Set the working directory in the image to /src
  • The name that will be found locally is backend.csproj Copy the file to the newly created /src Directory
  • Invoke in the project dotnet restore
  • Copy everything in the local working directory to the image
  • Invoke in the project dotnet publish
FROM mcr.microsoft.com/dotnet/aspnet:6.0WORKDIR /appEXPOSE 80EXPOSE 443COPY --from=build /app .ENTRYPOINT ["dotnet", "backend.dll"]

This will perform the following steps in order when called :

  • Pull mcr.microsoft.com/dotnet/aspnet:6.0 image
  • Set the working directory in the image to /app
  • Open port 80 and 443
  • Create the build Mirrored /app Copy all contents in the directory to the application directory of this image
  • Set the entry point of this image to dotnet, And will backend.dll Pass as a parameter
  1. Build the image
docker build -t mymicroservice .

docker build Command to use Dockerfile structure Docker image .

  • -t mymicroservice Parameter indicates that it marks the image ( name ) by mymicroservice.
  • The last parameter tells it which directory to use to find Dockerfile (. Specify current directory ).
  • This command will download and generate all dependencies to create Docker image , This operation may take some time .
  1. See the build results , And run
docker images

A list of all images available on the computer , Including the image just created

docker run -it --rm -p 3000:80 --name mymicroservicecontainer mymicroservice

Run the image just created

docker ps

View the running container

原网站

版权声明
本文为[Hua Weiyun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207041155517089.html

随机推荐