rabbitmq安装和运行rabbitmq-tutorials里的erlang例子

徐嘉谊
2023-12-01

先安装erlang,详见http://blog.csdn.net/mirahs/article/details/48245287

安装rabbitmq:

[root@test erlang]# wget https://github.com/rabbitmq/rabbitmq-server/releases/download/rabbitmq_v3_5_4/rabbitmq-server-generic-unix-3.5.4.tar.gz
[root@test erlang]# tar xf rabbitmq-server-generic-unix-3.5.4.tar.gz
[root@test erlang]# mv rabbitmq_server-3.5.4/ /usr/local/rabbitmq
[root@test erlang]# echo 'export PATH=/usr/local/rabbitmq/sbin:${PATH}' >> /etc/profile
[root@test erlang]# source /etc/profile

启动rabbitmq,5672端口开启:

[root@test erlang]# rabbitmq-server -detached
Warning: PID file not written; -detached was passed.
[root@test erlang]# netstat -ntlp            
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name           
tcp        0      0 0.0.0.0:4369                0.0.0.0:*                   LISTEN      6034/epmd                   
tcp        0      0 0.0.0.0:5672                0.0.0.0:*                   LISTEN      6705/beam.smp       
tcp        0      0 0.0.0.0:25672               0.0.0.0:*                   LISTEN      6705/beam.smp       

下载rabbitmq-tutorials代码及依赖:

[root@test erlang]# svn co https://github.com/rabbitmq/rabbitmq-tutorials/trunk/erlang rabbitmq-tutorial-erlang
[root@test erlang]# cd rabbitmq-tutorial-erlang/

[root@test rabbitmq-tutorial-erlang]# wget http://www.rabbitmq.com/releases/rabbitmq-erlang-client/v3.5.4/rabbit_common-3.5.4.ez
[root@test rabbitmq-tutorial-erlang]# unzip rabbit_common-3.5.4.ez
[root@test rabbitmq-tutorial-erlang]# mv rabbit_common-3.5.4 rabbit_common

[root@test rabbitmq-tutorial-erlang]# wget http://www.rabbitmq.com/releases/rabbitmq-erlang-client/v3.5.4/amqp_client-3.5.4.ez
[root@test rabbitmq-tutorial-erlang]# unzip amqp_client-3.5.4.ez
[root@test rabbitmq-tutorial-erlang]# mv amqp_client-3.5.4 amqp_client

rabbitmq-tutorials目录内容如下:

[root@test rabbitmq-tutorial-erlang]# ll
total 840
drwxr-xr-x 4 root root   4096 Jul 22 03:47 amqp_client
-rw-r--r-- 1 root root 250183 Jul 22 22:42 amqp_client-3.5.4.ez
-rwxr-xr-x 1 root root   1281 Sep 16 16:59 emit_log_direct.erl
-rwxr-xr-x 1 root root    883 Sep 16 16:59 emit_log.erl
-rwxr-xr-x 1 root root   1308 Sep 16 16:59 emit_log_topic.erl
-rwxr-xr-x 1 root root   1052 Sep 16 16:59 new_task.erl
drwxr-xr-x 4 root root   4096 Jul 22 03:47 rabbit_common
-rw-r--r-- 1 root root 549335 Jul 22 22:42 rabbit_common-3.5.4.ez
-rw-r--r-- 1 root root   1622 Sep 16 16:59 README.md
-rwxr-xr-x 1 root root    872 Sep 16 16:59 receive.erl
-rwxr-xr-x 1 root root   1345 Sep 16 16:59 receive_logs_direct.erl
-rwxr-xr-x 1 root root   1175 Sep 16 16:59 receive_logs.erl
-rwxr-xr-x 1 root root   1346 Sep 16 16:59 receive_logs_topic.erl
-rwxr-xr-x 1 root root    763 Sep 16 16:59 send.erl
-rwxr-xr-x 1 root root   1257 Sep 16 16:59 worker.erl

执行tutorials测试代码

Tutorial one: “Hello World!”:

[root@test rabbitmq-tutorial-erlang]# ./send.erl 
 [x] Sent 'Hello World!'

[root@test rabbitmq-tutorial-erlang]# ./receive.erl 
 [*] Waiting for messages. To exit press CTRL+C
 [x] Received <<"Hello World!">>

停止rabbitmq

[root@test ~]# rabbitmqctl stop
 类似资料: