A Golang push server cluster: Gopush-cluster

Source: Internet
Author: User
Tags zookeeper mercurial
This is a creation in Article, where the information may have evolved or changed.

Terry-Mao/gopush-clusteris a cluster-enabled Comet service (support WebSocket, and TCP protocol).

Characteristics

    • Lightweight
    • Performance
    • Pure Golang Implementation
    • Support Message Expiration
    • Support for offline message storage
    • Supports single and multiple private messaging push
    • Support for multiple subscribers of a single key (maximum number of subscribers can be limited)
    • Heartbeat Support (app Heartbeat and TCP keepalive)
    • Support for secure authentication (unauthorized users cannot subscribe)
    • Multi-protocol support (WEBSOCKET,TCP)
    • Detailed statistical information
    • Topology-capable architecture (support for adding and removing comet nodes, Web nodes, message nodes)
    • Support Failover with zookeeper

Installation (version 1.0.5)

First, installation dependent

?
12 $ yum -y install java-1.7.0-openjdk$ yum -y install gcc-c++

Second, build zookeeper

1. Create a new directory

?
123 $ mkdir -p /data/apps$ mkdir -p /data/logs/gopush-cluster$ mkdir -p /data/programfiles

2. Download zookeeper, recommended download 3.4.5 or later

?
123 $ cd /data/programfiles$ wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.5/zookeeper-3.4.5.tar.gz$ tar -xvf zookeeper-3.4.5.tar.gz -C ./

3. Start Zookeeper (Zookeeper cluster configuration is not detailed here, if there are more than one machine, it is recommended to do the cluster)

?
123 $ cp /data/programfiles/zookeeper-3.4.5/conf/zoo_sample.cfg /data/programfiles/zookeeper-3.4.5/conf/zoo.cfg$ cd /data/programfiles/zookeeper-3.4.5/bin$ ./zkServer.sh start

Third, build Redis

?
1234567891011 $ cd /data/programfiles$ wget http://download.redis.io/releases/redis-2.8.17.tar.gz$ tar -xvf redis-2.8.17.tar.gz -C ./$ cd redis-2.8.17/src$ make$ make test$ make install$ mkdir /etc/redis$ cp /data/programfiles/redis-2.8.17/redis.conf /etc/redis/$ cp /data/programfiles/redis-2.8.17/src/redis-server /etc/init.d/redis-server$ /etc/init.d/redis-server /etc/redis/redis.conf
    • Install tcl8.5 If the error is as follows (reference 2)
?
12345 which: no tclsh8.5 in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/geffzhang/bin)You need 'tclsh8.5'in order to run the Redis testMake[1]: *** [test] error 1make[1]: Leaving directory ‘/data/program files/redis-2.6.4/src’Make: *** [test] error 2!

Iv. Install the Git tool (you can skip this step if it is already installed)

Reference: Git

Yum-y Install git

V. Building Golang Environment

1. Download the source code (download the corresponding installation package according to your own system)

?
123 $ cd /data/programfiles$ wget -c --no-check-certificate https://go.googlecode.com/files/go1.3.linux-amd64.tar.gz$ tar -xvf go1.3.linux-amd64.tar.gz -C /usr/local

2. Configure the GO environment variable (here I add in/etc/profile.d/golang.sh)

?
123456 $ vim /etc/profile.d/golang.sh# 将以下环境变量添加到profile最后面export GOROOT=/usr/local/goexport PATH=$PATH:$GOROOT/binexport GOPATH=/data/apps/go$ source /etc/profile

Vi. Deployment of Gopush-cluster

1. Download Gopush-cluster and dependent packages

./dependencies.sh
    • If prompted as follows, the need to install Google's HG tool (install mercurial, reference information 1)

      ?
      12 go: missing Mercurial command. See http://golang.org/s/gogetcmdpackage code.google.com/p/go.net/websocket: exec:"hg": executable file not found in $PATH

2. Install message, comet, Web module (configuration file according to actual machine environment configuration)

?
123456789101112 $ CD $GOPATH/src/github.com/terry-mao/gopush-cluster/message Code class= "CPP Plain" >$ go install $ CP message-example.conf $GOPATH/bin/message.conf< /code>$ CP log $ CD. /comet/ $ go install $ CP comet-example.conf $GOPATH/ bin/comet.conf $ CP log .xml $GOPATH/bin/comet_log.xml $ CD. /web/ $ go install $ CP web-example.conf $GOPATH/bin/ web.conf $ CP log .xml $GOPATH/bin/web_log.xml

All of these environments are built to complete!

Seven, start Gopush-cluster

?
1234 $ cd /$GOPATH/bin$ nohup $GOPATH/bin/message -c $GOPATH/bin/message.conf 2>&1 >> /data/logs/gopush-cluster/panic-message.log&$ nohup $GOPATH/bin/comet -c $GOPATH/bin/comet.conf 2>&1 >> /data/logs/gopush-cluster/panic-comet.log&$ nohup $GOPATH/bin/web -c $GOPATH/bin/web.conf 2>&1 >> /data/logs/gopush-cluster/panic-web.log&

Eight, testing

1. Push individual private messages (example: message expiration is expire=600 seconds)

?
1 $ curl -d "{\"test\":1}"http://localhost:8091/1/admin/push/private?key=Terry-Mao\&expire=600

Successful return:{"ret":0}

2. Bulk Push private messages

?
1 $ curl -d "{\"m\":\"{\\\"test\\\":1}\",\"k\":\"t1,t2,t3\"}"http://localhost:8091/1/admin/push/mprivate?expire=600

Successful return:{"data":{"fk":["t1","t2"]},"ret":0}

    • The field m is the message body, which k is the subscription key to bulk push, with each key , split.

      ?
      12 注:1)新版推送的消息内容必须是json格式,否则获取消息时会报错.   2)批量推送正常情况下是没有`fk`字段的,如果有部分推送失败则返回`fk`,结构为字符串数组.

3. Get the Offline messaging interface

Open in Browser:

http :// localhost : 8090 / 1 /msg/get?k = Terry - Mao & m = 0

Successful return:

?
12345678 {    "data":{        "msgs":[            {"msg":{"test":1},"mid":13996474938346192,"gid":0}        ]    },    "ret":0}

4. Get the Node interface

Open in Browser:

http :// localhost : 8090 / 1 /server/get?k = Terry - Mao & P = 2

Successful return:

?
123456 {    "data":{        "server":"localhost:6969"    },    "ret":0}

Ix. attached information

1. Download and install HG

?
12345 $ wget http: //mercurial /release/mercurial-1 .4.1. tar .gz $ tar -xvf mercurial-1.4.1. tar .gz $ CD mercurial-1.4.1 $ make $ make install
    • If the installation prompt cannot find the file ' Python.h ' then you need to install Python-devel
Yum-y Install Python-devel
    • If error: couldn ' t find libraries, add environment variable
PYTHONPATH =/usr/local/lib64/python2.6/site-packages

2. Installing tcl8.5

?
12345678 $ cd/data/programfiles$ wget http://downloads.sourceforge.net/tcl/tcl8.5.10-src.tar.gz$ tar-xvf tcl8.5.10-src.tar.gz -C ./$ cdtcl8.5.10$ cdunix$ ./configure$ make$ makeinstall

Configuration

Example of a Web node configuration file:

Web

Example of a configuration file for a comet node:

Comet

Sample configuration file for message node:

Message

Example

Java:gopush-cluster-sdk

Ios:cocoagopush

Javascript:gopush-cluster-javascript-sdk

Document

Web node-related documentation:

Internal protocols are primarily for internal management such as push messages, manage comet nodes, and so on.

Client protocols are primarily intended for use by clients, such as acquiring nodes, getting offline messages, and so on.

Comet node-related documentation:

The client protocol is primarily for the client to connect to the Comet node's protocol description.

The internal RPC protocol is intended primarily for internal RPC interface usage instructions.

Related documents for the message node:

The internal RPC protocol is primarily intended for use with internal RPC interfaces.

Architecture


Project home:http://www.open-open.com/lib/view/home/1415176479262

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.