http://blog.haohtml.com/archives/14496
实现功能:用go实现消息队列的写入与读取(打算用在发送邮件服务)
环境工具:
Centos 64X 6.4
zeromq 3.2.4:zeromq.org
golang:http://golang.org/
设置系统变量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
执行命令 #source /etc/profile 使环境变量生效.
设置项目环境变量GOPATH
下面我们需要设置开发项目使用的环境变量GOPATH的路径.可直接在命令行下执行下面的命令,也可以将下面的命令写入/etc/profile(或者 $HOME/.profile)中,这样下次使用的时候变量不会丢失.参考:http://golang.org/doc/code.html
$ mkdir $HOME/go
For convenience, add the workspace's bin subdirectory to your PATH:
也要以将上面两条命令写到/etc/profile里,然后再执行 #source /etc/profile 命令,使环境变量生效.
到此为止,go的配置基本上已经完成.可以用 go env 命令查看相关的配置信息.
二.安装zeromq
三.安装gozmq
如果出现"# pkg-config --cflags libzmq libzmq libzmq libzmqPackage libzmq was not found in the pkg-config search path.Perhaps you should 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 should 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 should 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 should add the directory containing `libzmq.pc'to the PKG_CONFIG_PATH environment variableNo package 'libzmq' foundexit status 1"
错误,提示没有在pkgconfig路径找到libzmq.pc文件,主要是pkgconfig路径的问题,只要配置一下pkgconfig目录给用户环境变量PKG_CONFIG_PATH即可.
四.程序开发
这个时候开两个终端.一个执行服务端,一个执行客户端.
server端:
注意这个时候,不会有什么东西输出的,因为客户商没有任何写入操作.下面执行客户端.注意看一下server端的变化
客户端:
这个时候会发现客户端有10个写入操作(生产者),而服务端有10个输出操作(消费者).说明一切正常,否则请检查上面的操作是否有误.
至于下面的操作,看开发者怎么使用了.
posted on 2016-09-22 17:33 思月行云 阅读(1804) 评论(0) 编辑 收藏 引用 所属分类: Golang 、分布式\MQ