Why play dubbo

Said a major premise, the first game of our company has always been a single mode, as the game’s life cycle is outspread, the subsequent will appear a variety of cross-server function, in the past, the development has to be based on the netty cross-server function, via the cross-server agreement to the remote trigger corresponding logic; the length of the basic cross-server function development occupies about three times the take function development, The development efficiency is relatively low.

In order to solve the problem of low efficiency of the functional development cross-server, I recently ordered to make RPC and service, so the dubbo, basically is to dubbo in acutely, familiar with the company projects the RPC service and can also build the basis of about, didn’t guess correctly, the follow-up is to share in dubbo under the table and colleagues, Anyway, also want to share, first write a teaching process first, then can directly send them to see.

Dubbo framework is relatively large, so I plan to write a series. Those who want to learn Dubbo can pay attention to me. In the future, I will expand and talk about the RPC and service-oriented design of our company’s basic framework.

Say a funny thing, when I first came into contact with dubbo, it was pronounced tubo. I also argued with my colleagues. Finally, I checked it and found it was dubbo.

 ̄□ ̄ | |

This article is the first dubbo article, first teach you to run dubbo, don’t think just start so simple, or a lot of steps, including the start of the registry, background startup and other steps, interested in learning dubbo to play!

What about the Dubbo structure

Provider: Exposes the service Provider of the service. In fact, it is a service that provides the service.

Consumer: The service Consumer that invokes the remote service, that is, the service caller.

Registry: the Registry where services are registered and discovered, the channel of communication between callers and registrants of services,

Monitor: A monitoring center that collects statistics on service invocation times and invocation times.

Container: The concept of a service Container is unnecessary.

To put it simply:

  • The service container is responsible for starting, loading, and running service providers.

  • At startup, a service provider registers its services with the registry.

  • Service consumers, at startup, subscribe to the registry for the services they need.

  • The registry returns a list of service provider addresses to the consumer, and if there are changes, the registry pushes the change data to the consumer based on the long link.

  • The service consumer, from the list of provider addresses, selects a provider to invoke based on the load balancing algorithm.

  • Service consumers and providers accumulate the number of calls and call time in memory, and regularly send statistics to the monitoring center.

Get the registry running

# # # # Zookeeper is what

Zookeeper is a distributed, open source distributed application coordination service. It is an open source implementation of Google’s Chubby. It is an important component of Hadoop and Hbase.

The software provides consistency services for distributed applications, including configuration and maintenance, name service, distributed synchronization, and group service.

The Zookeeper registry automatically deletes the provider information and automatically recovers the registration data when the provider restarts.

Deploy the Zookeeper

Step 1:

Website can download: www.apache.org/dyn/closer….

Step 2:

CFG and log4j.properties in the conf directory. Rename zoo_sample. CFG to zoo.cfg. This is because Zookeeper looks for this file as the default configuration file when it is started.

Talk about a few important configurations in the zoo.cfg file

  • TickTime: This is the interval for maintaining heartbeats between Zookeeper servers or between clients and servers, that is, one heartbeat is sent for each tickTime.

  • DataDir: As the name suggests, this is the directory where Zookeeper saves data. By default, this is where Zookeeper keeps the log files that write data.

  • ClientPort: This is the port through which the client connects to the Zookeeper server. Zookeeper listens to this port and accepts client access requests.

Step 3:

Run Zookeeper and start zkserver. CMD in the bin directory of Zookeeper

Leave it on after startup, don’t close the CMD, and remember to start Zookeeper before dubbo consumers and providers run.

This is what happens when you run it successfully

Run the management background

Dubbo – what’s the admin

Dubbo-admin is the management background of dubbo framework. It can manage registered services (providers) and service callers (Comsumers), including routing, monitoring, configuration and other functions.

Generally, Dubbo uses Zookeeper to register management services, but dubbo-admin relies on Zookeeper to check which services are registered.

Install the dubbo – admin

Step 1:

Download the dubbo-admin project source code at github.com/apache/dubb…

Step 2:

Use IDEA to open the project and start the entry class

Step 3:

After the startup, the default access is http://localhost:7001/

Enter the root account and password to enter

Finally, you can see the administration page.

Get the Dubbo service running

Step 1:

Clone project source from Github github.com/apache/dubb… To the local

Import the source code using Idea and switch to version 3.0

Install various dependencies

Step 2:

Look at the Dubbo-Demo module and go directly to the XML module, which internally provides test cases for consumers and providers

In the XML module, there is an XML configuration under resources in the Consumer and Provider modules that describes the details of service exposure and subscription.

Service Registrar

Service subscriber

Directly start the corresponding Application. After successful startup, you should see the logs of RPC-related calls.

Startup provider

Start subscriber

The program shows that the subscriber is constantly calling the provider’s services

Step 3:

Look at the admin background and you can see

Admin background already had relevant record, this time we can undertake the governance of the service through admin background.

conclusion

Dubbo is running like this, I believe that after reading it, I should leave a few questions in my mind, such as how the subscriber find the registry, how the admin backend modification notice to the subscriber and the registry, and how the subscriber is to achieve remote method call, don’t worry, pay attention to me, the next article will analyze Dubbo from the source code, For you to solve a doubt.

If you want to learn Dubbo, follow me.

The original link: mp.weixin.qq.com/s/zCMAW6CeA…

Thank you for your support 👍👍👍!