In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "Dubbo basic knowledge summary and zookeeper installation method", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "Dubbo basic knowledge summary and zookeeper installation method" bar!
Concept 1 SOA: Service-Oriented Architecture
Service-oriented architecture (SOA) is a component model that connects different functional units of an application (called services) through well-defined interfaces and contracts between these services. Interfaces are defined in a neutral manner and should be independent of the hardware platform, operating system, and programming language that implements the service. This allows services built in a variety of systems to interact in a unified and common way.
Service-oriented architecture, which can distribute, combine and use loosely coupled coarse-grained application components through the network according to the requirements. The service layer is the foundation of SOA, which can be directly called by the application, so as to effectively control the human dependence of the interaction with the software agent in the system.
SOA is a coarse-grained, loosely coupled service architecture, which communicates between services through a simple and precisely defined interface, without involving the underlying programming interface and communication model. SOA can be seen as a natural extension of the Bamp S model, XML (a subset of the standard general markup language) / Web Services technology.
SOA will help software engineers stand at a new height to understand the development and deployment of various components in the enterprise architecture, and it will help enterprise system architects to structure the entire business system with faster, more reliable and more reusable. Compared with the past, the system based on SOA architecture can face the rapid changes of business more calmly.
2 RPC: Remote Procedure Call Protocol
Remote procedure call protocol, which is a protocol that requests services from remote computer programs through the network without knowing the underlying network technology. The RPC protocol assumes the existence of certain transport protocols, such as TCP or UDP, to carry information data between communication programs. In the OSI network communication model, RPC spans the transport layer and the application layer. RPC makes it easier to develop applications, including web-based distributed multiprograms.
RPC adopts client / server mode. The requester is a client and the service provider is a server. First, the client invocation process sends a call message with process parameters to the service process, and then waits for the reply message. On the server side, the process stays asleep until the call message arrives. When a call message arrives, the server obtains the process parameters, calculates the result, sends the reply message, and then waits for the next call message. Finally, the client invokes the process to receive the reply message, obtains the process result, and then calls execution to proceed.
3 OSI network communication model:
OSI is the abbreviation of Open System Interconnection, which means open systems interconnection. The International Organization for Standardization (ISO) has formulated the OSI model, which defines the standards for the interconnection of different computers and is the basic framework for designing and describing computer network communication. OSI model divides the work of network communication into seven layers, namely physical layer, data link layer, network layer, transport layer, session layer, presentation layer and application layer.
What is Dubbo
Dubbo is a framework based on SOA structure developed by Alibaba to realize RPC remote call.
Dubbo framework, is based on the container operation. The container is Spring.
When writing services and clients, you need a registry to publish and subscribe to services. The registry contains all the service information published by the server, including request address, parameter naming, parameter number, parameter limit, parameter encryption and so on. The client subscribes to the service through the registry, obtains all the information of the service, and realizes RPC remote access.
Official website: http://dubbo.io/
Alibaba has donated the dubbo framework to the Apache Software Foundation.
3. Dubbo structure 1 Registry
A registration center. Core components for publishing and subscribing to Dubbo services.
After the Dubbo service is written successfully, it is published to the registry. The client subscribes to the service through the registry and applies it.
2 Provider
A provider of services. Server. A computer that runs a real service code.
Such as: Tencent released the three-party login.
3 Consumer
The consumer of the service. Client. Is the code that remotely invokes the Provider service.
Such as: three-party website, the site provides Tencent-related login entry.
4 Container
A container. It is the container that allows Provider and Consumer to execute normally. Give Provider and Consumer a working environment. Use Spring containers in Dubbo.
5 Protocol
An agreement. Dubbo's Consumer and Provider communication standards.
Dubbo supports a variety of protocols. Such as: dubbo protocol (Dubbo custom application protocol), RMI protocol, TCP protocol and so on.
6 Monitor
Monitoring center, management center, dispatching center. The monitoring center that manages the number of Provider, the number of Consumer and the number of Consumer calls to Provider. It is equivalent to statistics.
IV. Registry Registration Center
Dubbo supports multiple registries. Different registries provide different registration services.
1 ZooKeeper
A service management application developed by Java. Is a sub-project of the Hadoop project. The zookeeper. Is a management application for other applications, responsible for coordination, scheduling, management, configuration and other functions.
Support breakpoint recovery, session recovery, configuration service items, configuration consumption items, wildcard information configuration, etc.
ZooKeeper is an application developed by Java. The running environment only needs JDK and JVM.
2 Multicast
A broadcast registration center. As long as Provider and Consumer are in the same network segment, the service can be published and subscribed.
Limitations: only suitable for small architectures or development tests. Because it may cause a broadcast storm. More than 5 physical machines in the network segment publish services at the same time, which may cause data communication problems and fail to realize fast service subscription and application.
3 Redis
KV server registry. KV server, cache server. Memory database. NOSQL database. Later, there will be a detailed explanation of the course.
Similar to the ZooKeeper registry. Provider publishes services to Redis, and Consumer subscribes to services from Redis.
Advantage: high efficiency.
Defects: the description of the data is relatively simple and the frequency of use is relatively small. Without a large number of tests, the stability is uncertain.
4 Simple
It is a registry customized by Dubbo. Reduce tripartite dependence. Reduce code dependency and coupling.
Only suitable for small applications and development testing.
5. Zookeeper installation 1 download materials
Official website: http://zookeeper.apache.org/
When downloading materials, do not download the beta version.
2 upload data to linux3 and decompress
Tar-zxf zookeeper-3.4.6.tar.gz
Decompress it and use it. It is recommended to copy to the / usr/local directory. Make it available to all system users.
4 copy to / usr/local directory
Cp-r zookeeper-3.4.6 / usr/local/zookeeper/
5 Zookeeper directory structure 5.1 bin
Executable file. Such as: start, stop, restart and other commands.
5.2 conf
Configuration information. Configuration file for Zookeeper application
5.3 lib
Zookeeper application jar package library directory. Is the save location of all jar packages that Zookeeper depends on
5.4 data
Custom catalog, commonly used. The directory used to save Zookeeper running data.
5.5 docs
Official help documentation provided by Zookeeper
5.6 contrib
Zookeeper provides information about plug-ins and scripts.
5.7 src
source code
5.8 zookeeper-3.4.6.jar
Zookeeper core code base. Later development of possible applications of jar. When using maven to develop applications, download the jar package through dependencies.
6 Test start
When the service status changes, Zookeeper automatically outputs a log message. The file name is zookeeper.out. The text is saved in the directory where the status of the service is changed. For example, execute the command bin/zkServer.sh start. Usr/local/zookeeper in the directory / directory. Log files are output in the / usr/local/zookeeper directory.
ZkServer.sh-Zookeeper service script. Used to start, stop, restart use.
Command: bin/zkServer.sh start
The startup was not successful. There is a mistake. Prompt zoo.cfg configuration file does not exist. The configuration file is saved in the conf directory of the Zookeeper application.
6.1 configure Zookeeper
Zookeeper provides a template configuration file named zoo_sample.cfg. Exe. All default configuration information is defined in the template file. It can be used by copying.
Cp zoo_sample.cfg zoo.cfg
6.2 provide a data storage directory
Create a directory anywhere. The data storage directory used for Zookeeper execution. It is recommended to create it in the Zookeeper installation directory.
Recommended command: execute mkdir data in the Zookeeper installation directory
6.3 Edit zoo.cfg configuration file
# check time. Valid duration of the visit
TickTime=2000
# initialize the number of ticket. How many client concurrent accesses are supported by default.
InitLimit=10
# number of concurrent access threads
SyncLimit=5
# absolute path configuration is recommended for the directory where Zookeeper execution process data is saved.
DataDir=/usr/local/zookeeper/data
# client port
ClientPort=2181
6.4 Test start
The following message indicates that the service has been started successfully. Standalone represents that the stand-alone version is being executed.
[root@node1 ~] # / usr/local/zookeeper/bin/zkServer.sh start
JMX enabled by default
Using config: / usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper... STARTED
7 stop
Bin/zkServer.sh stop
8 restart
Bin/zkServer.sh restart
9 View service status
Bin/zkServer.sh status
10 client access test
Command: bin/zkCli.sh [- server host address: Port]
By default, the local port 2181 Zookeeper service is connected.
[application name: host: number of commands executed by port (status)]
[zk: localhost:2181 (CONNECTED) 0]
10.1 disconnect the client
Execute the following command:
[zk: localhost:2181 (CONNECTED) 0] quit
VI. Entry code
Maven Project-dubbo Project. Pom project.
Import jar package. Use maven dependency import.
Com.alibaba
Dubbo
2.5.7
1 Provider
Maven project-Provider, is the module of dubbo project. Pom project.
The Provider project is divided into two sub-projects, both of which are module of the Provider project.
The service project is the jar project. Define the interface.
The service-impl project is the jar project. Define the implementation of the interface.
1.1 Dubbo related operations:
1.1.1 Notes
Use Spring annotations to manage the interface implementation objects to be published.
It can also be managed using the tag bean.
1.1.2 spring profile
1.1.2.1 scanning service notes
1.1.2.2 configure Provider service information for Dubbo
1.1.3 Code release Service
Through the execution of the code, the spring configuration information can be released.
Publish the bean object information in the spring container to the Zookeeper registry.
Just start the spring container. Spring's container can be started. Because the ClassPathXmlApplicationContext type implements the interface Runnable. ClassPathXmlApplicationContext can start threads independently.
2 Consumer
Maven project-consumer, is the module of dubbo project. Jar project
Write test code. Invoke the service code defined in Provider. Get the result returned by the code.
Consumer project can only be dependent on provider-service project. Through the form of dubbo, remote call.
2.1 Notes
Use spring annotations to manage attribute dependencies in Consumer code and code.
2.2 spring configuration
2.2.1 scan comments
Manage attribute dependencies in Consumer code and code.
2.2.2 dubbo configuration
That describes the Dubbo framework information.
3 configuration details 3.1 dubbo:application
A named tag for the Dubbo application. It is the only mark of Dubbo framework for application management.
It is recommended that each Dubbo application should be named differently.
Apply named data: letters, numbers,'_','-','$'.
3.2 dubbo:protocol
A protocol definition is a label description provided to the provider. It is the protocol information that Provider binds when publishing the service.
The default protocol is dubbo protocol
Default Dubbo protocol port: 20880.
3.3 dubbo:registry
A registration center. Dubbo is at the core of the service publish and subscribe process. The recommended registration is Zookeeper.
You need to define the protocol to access the registry and the address of the registry.
3.4 dubbo:service
Publish the label configuration of the service. Service information to be released by Provider code. Which bean object provides the service for the service to be published? What is the service interface to be released? Requires that the bean object must implement the interface.
At the same time, the configuration of service release can be configured. Such as: number of retries, timeout, etc.
3.4.1 other attributes
3.4.1.1 timeout
The length of the timeout. When Consumer accesses Provider, how long must it take to get the response result?
An exception is thrown outside the time limit.
The default value is 1000 milliseconds. The result of Provider execution must be within 1000 milliseconds.
3.4.1.2 retries
Consumer accesses Provider if an exception occurs. The number of automatic retries.
The default value is: 2. The first visit was initiated on its own initiative. If there is anything abnormal, automatically retry 2 times.
3.5 dubbo:reference
The service reference configuration defined by the Consumer party. After subscribing to the service from the registry, how to use it.
The tag informs the Dubbo framework to create a proxy object based on the subscribed service.
The proxy object is also a bean object managed by the spring container. It can be obtained through the auto-assembly annotation @ Autowired.
3.5.1 other attributes
3.5.1.1 timeout
The default is 1000 milliseconds. Defined by the dubbo:consumer tag.
If the dubbo:service tag defines timeout, and the dubbo:reference tag does not define the timeout attribute. Then use the timeout. Service defined by the tag.
3.5.1.2 retries
The number of retries. The default is 2. Defined by the dubbo:consumer tag.
If the dubbo:service tag defines retries, and the dubbo:reference tag does not define the retries attribute. Then use the retries. Service defined by the tag.
3.6 dubbo:provider
Is the parent configuration tag of the dubbo:service tag. If a dubbo:provider tag is defined, the dubbo:sevice tag uses its defined attribute information by default. Such as: retries, timeout, etc.
If you define:
Then all dubbo:service tags that do not define timeout and retries attributes use 3000 milliseconds as the timeout and 0 as the number of retries.
3.6.1 Special Properties
3.6.1.1 payload
Define the parameters and return values of the method in the service within the most big data range. The default is 8 m data.
When Consumer accesses Provider, the maximum parameter passed is 8m. When Provider returns the result to Consumer, the maximum is 8m.
Default value: 88388608, units are bytes.
3.7 dubbo:consumer
A label that defines the default configuration of the consumer. Is to provide default settings for the dubbo:reference tag.
For example, the dubbo:reference tag has no attributes configured. Use 3000 as the default timeout and 0 as the number of retries.
4. Brief introduction of protocol
The communication protocol of Dubbo framework. Dubbo framework supports a variety of communication protocols. Dubbo protocol is used by default.
Dubbo protocol is a kind of protocol defined by Dubbo framework.
4.1 dubbo protocol
Dubbo default protocol adopts single persistent connection and NIO asynchronous communication mode. It is suitable for service calls with large amount of data and high concurrency. And the situation where the service consumer machine far exceeds the service provider machine.
Dubbo protocol is a NIO protocol, long connection small data transmission protocol, not suitable for transmission big data. Such as: documents, media, pictures, etc. Unless the request for access is very low, you can use the Dubbo protocol to transmit big data.
Single persistent connection: when Consumer and Provider communicate, there is only one connection, no matter how long it takes.
NIO: net io. Network IO stream. Asynchronous communication. Consumer can send request data all the time, and part of the Provider processing returns part of the result.
The Dubbo protocol requires that when communicating between Consumer and Provider, all transmitted data must be serializable.
The service method parameter table and return value types provided by Provider must be serializable.
Parameters and return value types cannot be customized to implement interface List,Set,Map,Number,Calendar, etc.
When transferring data, only the value of the type property and the type of the property are transferred. Method information and static data are not transmitted.
4.2 RMI protocol
The standard protocol provided by JDK is the remote method invocation protocol. Remote method invoke.
Multi-connection, short connection, tcp protocol, synchronous data transmission. Service parameters and return values must be serializable.
Suitable for the situation where the number of clients and servers is about the same. Files can be transferred. The timeout period is not valid.
4.3 hessian protocol
Hessian protocol, based on http application layer protocol. Expose the service through servlet.
Multi-connection, short connection, http protocol. Synchronous transmission. The parameter returns a large amount of data. The number of Provider is greater than the number of Consumer. The parameters and return values of the service must be serializable.
4.4 memcached protocol
Application layer protocol based on RPC.
Is based on Memcached efficient KV server to achieve the registry. Similar to Redis.
There is no need for Consumer awareness of registry location. You can use the property property to implement the application of the service.
At this point, I believe you have a deeper understanding of "Dubbo basic knowledge summary and zookeeper installation method". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.