Function: use go to write and read message queues (intended to be used in the mail sending service)
Function: use go to write and read message queues (intended to be used in the mail sending service)
Environment tools:
Centos 64X6.4
Zeromq 3.2.4: zeromq.org
Golang: http://golang.org/
1. install golang (http://golang.org/doc/install)
This step is very simple, just download from the http://code.google.com/p/go/downloads to the server, unzip to the/usr/local/go directory, and then set the system variables.
| 12 |
Wget https://go.googlecode.com/files/go1.1.2.linux-amd64.tar.gztar-C/usr/local-xzf go1.1.2.linux-amd64.tar.gz |
Set the system variable GOROOT
Add/usr/local/go/bin to the PATH environment variable. you can do this by adding this line to your/etc/profile (for a system-wide installation) or $ HOME /. profile:
export PATH=$PATH:/usr/local/go/bin
Run the command # source/etc/profile to make the environment variable take effect.
Set the project environment variable GOPATH
Next we need to set the path of the environment variable GOPATH used by the development project. you can directly execute the following command in the command line, or write the following command into/etc/profile (or $ HOME /. so that the variables will not be lost next time. reference: http://golang.org/doc/code.html
$ Mkdir $ HOME/go
For convenience, add the workspace's bin subdirectory to your PATH:
| 12 |
$ ExportGOPATH = $ HOME/go $ exportPATH = $ PATH: $ GOPATH/bin |
You also need to write the above two commands to/etc/profile, and then execute the # source/etc/profile command to make the environment variable take effect.
So far, the go configuration has basically been completed. you can use the go env command to view the relevant configuration information.
II. install zeromq
Refer to: http://blog.haohtml.com/archives/13798. ZeroMQ 2.3.4 is used here.
3. install gozmq
If git is not installed, install it first. refer to: http://blog.haohtml.com/archives/10093
Here we use the https://github.com/alecthomas/gozmqloud Library.
| 12 |
Cd ~ /Gogo get-tags zmq_3_x github.com/alecthomas/gozmq |
If
"# Pkg-config -- cflags libzmq libzmqPackage libzmq was not found in the pkg-config search path. perhaps you shoshould add the directory containing 'libzmq. pc 'to the PKG_CONFIG_PATH environment variableNo package 'libzmq' foundPackage libzmq was not found in the pkg-config search path. perhaps you shoshould add the directory containing 'libzmq. pc 'to the PKG_CONFIG_PATH environment variableNo package 'libzmq' foundPackage libzmq was not found in the pkg-config search path. perhaps you shoshould add the directory containing 'libzmq. pc 'to the PKG_CONFIG_PATH environment variableNo package 'libzmq' foundPackage libzmq was not found in the pkg-config search path. perhaps you shoshould add the directory containing 'libzmq. pc 'to the PKG_CONFIG_PATH environment variableNo package 'libzmq' foundexit status 1"
Error. the error message is that the libzmq. pc file is not found in the pkgconfig path. The main problem is the pkgconfig path. you only need to configure the pkgconfig directory to give the user the environment variable PKG_CONFIG_PATH.
| 1 |
ExportPKG_CONFIG_PATH =/usr/local/lib/pkgconfig |
4. program development
Directly write the two sections of the https://github.com/alecthomas/gozmqloud code to the zmqserver.go and zmqClient. go files. (you can also download the provided instance https://github.com/alecthomas/gozmq/tree/master/examples directly)
At this time, two terminals are opened. one is the execution server and the other is the execution client.
Server:
Note that nothing will be output at this time, because the customer service provider does not have any write operations. execute the client below. check the changes on the server.
Client:
At this time, you will find that the client has 10 write operations (producers), and the server has 10 Output Operations (consumers). This indicates that everything is normal. otherwise, check whether the above operations are correct.
The following operations show how developers use them.