Diamond Introduction and Rapid Application

Source: Internet
Author: User
Tags datetime documentation svn create database port number tomcat

I. Overview

Diamond is the use of Taobao internal management of a long-lasting configuration of the system, it is characterized by simple, reliable, easy to use, at present, most of the internal Taobao system configuration, from diamond to unified management.

Diamond provides a service for the application system to get the configuration, not only to get the relevant configuration from diamond at startup, but also to perceive changes in configuration data and obtain the changed configuration data during the run.

Persistent configuration refers to the persistence of configuration data into disk and database.

Diamond is characterized by simplicity, reliability and ease of use:

Simple: The overall structure is very simple, thus reducing the likelihood of errors.

Reliable: The application in any case can start, in the host Taobao core system and normal operation for more than a year, no major failure occurred.

Easy to use: The client uses only two lines of code, exposing the interface is very simple and easy to understand.

Second, rapid use

1, source code check out

Check out the source code for diamond from the following SVN address:

Http://code.taobao.org/svn/diamond/trunk

2, the construction of the server

(1) MySQL

To install the Mysql-server, please refer to the official MySQL documentation, after installation, log in as root, set up the user and give permissions, establish the database, and then build the table, the statements are as follows:

Create Database Diamond;

Grant all on diamond.* to zh@ '% ' of ' identified by ' ABC ';

Use Diamond

CREATE TABLE Config_info (

' ID ' bigint (+) unsigned not NULL auto_increment,

' data_id ' varchar (255) Not NULL default ' ',

' group_id ' varchar (+) not NULL default ' ',

' Content ' longtext not NULL,

' Md5′varchar (+) not NULL default ',

' Gmt_create ' datetime not NULL default ' 2010-05-05 00:00:00′,

' Gmt_modified ' datetime not NULL default ' 2010-05-05 00:00:00′,

PRIMARY KEY (' id '),

UNIQUE KEY ' uk_config_datagroup ' (' data_id ', ' group_id ')

);

When you are finished, add the database configuration information (IP, username, password) to the Diamond-server project's src/resources/ The Db.url,db.user,db.password attribute in the Jdbc.properties file above, the library name, user name, and password created here must be the same as the corresponding attribute in Jdbc.properties.

(2) Tomcat

Tomcat is the running container for the diamond server.

For Tomcat installation, please refer to the Tomcat official documentation for the recommended use of TOMCAT7

There is no need to make any changes to Tomcat.

(3) Diamond Server

At the root of the Diamond-server source code, execute MVN clean package-dmaven.test.skip, which succeeds in diamond-server/ Generate Diamond-server.war under target directory (if MAVEN is not installed, refer to the MAVEN official documentation for installation).

After packaging is complete, place the Diamond-server.war under Tomcat's WebApps directory.

Start Tomcat, which starts the Diamond-server

(4) HTTP Server

HTTP server is used to store a list of addresses such as the diamond server and can use any HTTP server, for example, Tomcat.

In general, the HTTP server and the diamond server are deployed on different machines, and for the sake of simplicity, deploy both in the same Tomcat application under the same machine, note that if deployed in different Tomcat, the port number must be 8080. Cannot be modified (so it must be deployed on a different machine).

In the (3) Tomcat WebApps in the Diamond-server to establish the file diamond, the file content is Diamond-server address list, one line address, address is IP, for example:

127.0.0.1

After completing the above 4 steps, the server-side build is complete.

2. Release data

Diamond publishes data in a manual fashion.

In the browser, enter the address in step (2) Http://ip:8080/diamond-server/,ip for server, user name, 123 password, log in to the background management interface, then click "Configure Information Management"--"Add configuration information , enter Dataid, group, content in the input box, and then click "Submit".

After success, you can query the published data in configuration information management.

3. Subscription data

The Diamond Client API primarily provides the ability to subscribe to data.

(1) Client Gets server address

Getting the server-side address is transparent to the client, and the client simply needs to make the following domain bindings locally:

IP A.B.C

IP is the IP of the http-server built in front

(2) Create Subscribers

Diamondmanager manager = new Defaultdiamondmanager (group, Dataid, New Managerlistener () {

Public Executor Getexecutor () {

return null;

}

public void Receiveconfiginfo (String configinfo) {

The logic of the client processing data

}

});

Description of the parameter:

Group and Dataid are string types, and they are combined as the only key that holds data on the Diamond-server side

Managerlistener is a client-registered data listener whose role is to accept changing configuration data in the run and then callback the Receiveconfiginfo () method to execute the client's logic of processing the data. If you are working on changing configuration data, be sure to register Managerlistener

(3) Get Configuration data

String configinfo = manager.getavailableconfigureinfomation (timeout);

The Diamond-server-side saved configurations are all text types, and the configuration data returned to the client is the java.lang.String type, and timeout is the time-out for obtaining configuration data from the network. Each time the client invokes the method, it is guaranteed to obtain a copy of the latest available configuration data.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.