Diamond Detailed (1)-Configuration

Source: Internet
Author: User
Tags documentation svn

Original: Http://my.oschina.net/u/435621/blog/270483?p=1


Hello everyone, today began to bring our general product Team Products--diamond topic, this time to introduce the general situation of diamond and rapid use.

I. Overview

Diamond is an internal use of Taobao management of a persistent configuration system, it is characterized by simple, reliable, easy-to-use, at present Taobao most of the system's configuration, by the diamond to carry out unified management.

Diamond provides access to configuration services for application systems, which can be used not only to obtain related configuration from Diamond at startup, but also to perceive changes in configuration data in the runtime and to obtain changed configuration data.

Persistent configuration means that the configuration data is persisted to disk and to the database.

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

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

Reliable: The application can be started under any circumstances, in the host Taobao core system and the normal operation of more than a year, no major failures have occurred.

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

Second, the rapid use

1, the 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 server's build

(1) MySQL

To install Mysql-server, please refer to the official MySQL documentation, after installation, set up a database, and then set up two tables, the table statements are as follows:

CREATE TABLE Config_info (' id ' bigint () unsigned not null auto_increment, ' data_id ' varchar (255) NOT null default ', ' group_id ' varchar (128) NOT null default ', ' content ' longtext not NULL, ' MD5 ' varchar ' (+) NOT null default ', ' Src_ip ' varchar ' default null, ' src_user ' varchar default NULL, ' 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 ')); CREATE TABLE Group_info (' id ' bigint () unsigned not NULL auto_increment, ' address ' varchar (+) NOT null default ', ' D ata_id ' varchar (255) NOT NULL default ', ' group_id ' varchar (128) NOT null default ', ' src_ip ' varchar () default NULL , ' src_user ' varchar default NULL, ' Gmt_create ' datetime not NULL default ' 2010-05-05 00:00:00′, ' gmt_modified ' Dateti Me not NULL default ' 2010-05-05 00:00:00′, PRIMARY key (' id '), the UNIQUE key ' uk_group_address ' (' Address ', ' data_id ', ' group_id ')); 

When the table is completed, add the configuration information for the database to the Src/resources/jdbc.properties file in the Diamond-server project.

(2) Tomcat

Tomcat is the running container for Diamond server.

Tomcat installation Please refer to the Tomcat official documentation and recommend the use of TOMCAT7

There is no need to make any changes to Tomcat.

(3) Diamond Server

In the Diamond-server source code root directory, execute mvn clean package-dmaven.test.skip, after success in diamond-server/ The target directory generates Diamond-server.war (if you do not have Maven installed, refer to the MAVEN official documentation for installation).

After the package is complete, place the Diamond-server.war in the WebApps directory of Tomcat.

(4) HTTP Server

HTTP server is used to store address lists such as Diamond Server, and any HTTP server can be selected, for example, Tomcat.

To install Tomcat Please join the official Tomcat documentation and note that if HTTP server and diamond Server are installed on a single machine, modify the HTTP server's ports to avoid conflicts.

After modifying the port, modify the Default_port constant in the Com.taobao.diamond.common.Constants class under Diamond-utils Engineering to the corresponding port number.

After the installation is complete, create a diamond file in the folder Diamond-server and Pushit-server,diamond-server under Tomcat WebApps, and the file content is the Diamond-server address list. One-line address, address for Ip;pushit-server also create diamond file, file content is pushit-server address list, one line address, address for Ip:port (pushit after the text will be described)

(5) Pushit

Pushit is a lightweight message Notification Service component for diamond to do real-time Notification Services to inform the client of changes in data, it is also the structure of CS, the server to build steps as follows:

Under the Pushit source code root directory, execute the MVN clean Package assembly:assembly-dmaven.test.skip command, which will succeed in pushit/ The pushit-pushit.tar.gz package is seen in the target directory.

Perform TAR-XZVF pushit-pushit.tar.gz for decompression.

Enter the Pushit directory, set up the logs directory, and create pushit.log files in the logs directory.

Enter Pushit/bin directory, execute./pushit-startup.sh. /conf/server.properties command, start pushit-server

(6) Redis

Redis is used to store some statistics-related information.

Redis installation Please refer to Redis's official documentation.

When the installation is complete, please fill in the corresponding information in the Diamond-server configuration file redis.properties.

After completing the 6 steps above, the server end of the build is completed.

2. Publish Data

Diamond Publish data in a manual manner.

Modify the Diamond-server profile user.properties to k=v add the user name and password for the login diamond-server.

In the browser, enter the address and port in step (2) of the server set up by HTTP://IP:PORT/DIAMOND-SERVER/,IP and port, log in to the admin interface, and then click "Configure Information Management"-"Add configuration Information", Enter Dataid, group, and content in the input box, and then click "Submit".

After successful, 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) The client gets the service-side address

Obtaining a service-side address is transparent to the client, and the client only needs to bind the following domain name locally:

Domain IP

Where the value of domain is the same as that of Default_domainname and Daily_domainname in the Com.taobao.diamond.common.Constants class under Diamond-utils engineering, IP for server to build the HTTP server address in step (4).

(2) Create Subscribers

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

public void Receiveconfiginfo (String configinfo) {

The logic of client processing data

}

});

Description of the parameter:

Group and Dataid are string types that combine to be the only key that holds data on the Diamond-server side

Managerlistener is a client-registered data listener, which is used to accept changed configuration data in operation, and then callback the Receiveconfiginfo () method to perform the logic of client processing data. If you want to process the changed configuration data in the run, be sure to register Managerlistener

(3) Get Configuration data

String configinfo = manager.getavailableconfiginfomation (timeout);

The Diamond-server-side saved configurations are all text types, and the configuration data returned to the client is java.lang.String type timeout the timeout for obtaining configuration data from the network. Each invocation of the method by a client call ensures that an up-to-date set of available configuration data can be obtained.


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.