05_RabbitMQ 的CLI管理工具 rabbitmqadmin

原文地址 http://soft.dog/2016/04/20/RabbitMQ-cli-rabbitmqadmin/

一顿仇、前言

RabbitMQ 是一個(gè)使用 Erlang 編寫的開源消息隊(duì)列中間件霹琼,被廣泛使用在各種應(yīng)用場(chǎng)景中

一般對(duì)于它的監(jiān)控和管理可以通過web來完成,詳細(xì)可以參考 RabbitMQ 監(jiān)控

但生產(chǎn)環(huán)境中經(jīng)常沒有訪問web管理界面的條件赚楚,只提供了CLI界面夕晓,或者有些自動(dòng)化的需求通過web界面無法完成抄课,這時(shí)有沒有一種直接在CLI環(huán)境下進(jìn)行管理的方法呢虏两,官方提供的 rabbitmqadmin 命令正好可以滿足這類需求

對(duì)于運(yùn)維來說尝苇,個(gè)人感覺更傾向使用CLI的方式铛只,因?yàn)殡m然web的界面更友好,但是明顯不如CLI快捷糠溜,CLI也可以結(jié)合其它命令進(jìn)行更進(jìn)一步的處理淳玩,比如將關(guān)鍵信息查出來后提供給集中的監(jiān)控系統(tǒng)以觸發(fā)報(bào)警

目前 rabbitmqadmin 可以完成以下任務(wù):

  • 列出 exchanges, queues, bindings, vhosts, users, permissions, connections and channels
  • 看到匯總信息
  • 申明和清除 exchanges, queues, bindings, vhosts, users and permissions
  • 發(fā)布和獲取消息
  • 關(guān)閉連接和清空隊(duì)列
  • 導(dǎo)入導(dǎo)出配置

這里分享一下 rabbitmqadmin 的基本操作,詳細(xì)可以參考 http://www.rabbitmq.com/management-cli.html

二非竿、RabbitMQ的安裝

RabbitMQ的安裝請(qǐng)參考我的另一篇總結(jié)01_RabbitMQ的安裝蜕着。

三、rabbitmqadmin

在web UI管理界面中汽馋,的 /cli/ 下可以下載此腳本:

1.png

點(diǎn)擊【here】會(huì)呈現(xiàn)腳本內(nèi)容:

2.png

右鍵另存為下載即可侮东。默認(rèn)名稱為rabbitmqadmin圈盔。

但是有些情況下,并沒條件使用Web UI悄雅,使用下面的方法一樣可以獲取這個(gè)腳本:

[root@h102 rabbitmq]# wget http://localhost:15672/cli/rabbitmqadmin
--2016-04-18 19:47:50--  http://localhost:15672/cli/rabbitmqadmin
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:15672... failed: Connection refused.
Connecting to localhost|127.0.0.1|:15672... connected.
HTTP request sent, awaiting response... 200 OK
Length: 34504 (34K) [text/plain]
Saving to: “rabbitmqadmin”

100%[===================================================================================================>] 34,504      --.-K/s   in 0s      

2016-04-18 19:47:50 (155 MB/s) - “rabbitmqadmin” saved [34504/34504]

[root@h102 rabbitmq]# ll rabbitmqadmin 
-rw-r--r-- 1 root root 34504 Apr 18 19:29 rabbitmqadmin
[root@h102 rabbitmq]# file rabbitmqadmin 
rabbitmqadmin: a /usr/bin/env python script text executable
[root@h102 rabbitmq]# 
[root@h102 rabbitmq]# chmod  +x rabbitmqadmin 
[root@h102 rabbitmq]# ./rabbitmqadmin --help 
Usage
=====
  rabbitmqadmin [options] subcommand

Options
=======
--help, -h              show this help message and exit
--config=CONFIG, -c CONFIG
                        configuration file [default: ~/.rabbitmqadmin.conf]
--node=NODE, -N NODE    node described in the configuration file [default:
                        'default' only if configuration file is specified]
--host=HOST, -H HOST    connect to host HOST [default: localhost]
--port=PORT, -P PORT    connect to port PORT [default: 15672]
--path-prefix=PATH_PREFIX
                        use specific URI path prefix for the RabbitMQ HTTP API
                        (default: blank string) [default: ]
--vhost=VHOST, -V VHOST
                        connect to vhost VHOST [default: all vhosts for list,
                        '/' for declare]
--username=USERNAME, -u USERNAME
                        connect using username USERNAME [default: guest]
--password=PASSWORD, -p PASSWORD
                        connect using password PASSWORD [default: guest]
--quiet, -q             suppress status messages [default: True]
--ssl, -s               connect with ssl [default: False]
--ssl-key-file=SSL_KEY_FILE
                        PEM format key file for SSL
--ssl-cert-file=SSL_CERT_FILE
                        PEM format certificate file for SSL
--format=FORMAT, -f FORMAT
                        format for listing commands - one of [raw_json, long,
                        pretty_json, kvp, tsv, table, bash] [default: table]
--sort=SORT, -S SORT    sort key for listing queries
--sort-reverse, -R      reverse the sort order
--depth=DEPTH, -d DEPTH
                        maximum depth to recurse for listing tables [default:
                        1]
--bash-completion       Print bash completion script [default: False]
--version               Display version and exit

More Help
=========

For more help use the help subcommand:

  rabbitmqadmin help subcommands  # For a list of available subcommands
  rabbitmqadmin help config       # For help with the configuration file
[root@h102 rabbitmq]# 

以上已經(jīng)拿到了rabbitmqadmin這個(gè)python腳本并設(shè)置為可執(zhí)行,接下來設(shè)置為全局可執(zhí)行命令驱敲。

[root@h102 rabbitmq]# vim /etc/profile

將該腳本所在目錄,其添加到/etc/profile中即可宽闲。

PATH后面是所在目錄:
export PATH=$PATH:/usr/local/server/rabbitmq/

保存退出,讓該設(shè)置立即生效:

[root@h102 rabbitmq]# source /etc/profile 

四众眨、基礎(chǔ)概念

4.1 架構(gòu)

Producer、Exchange容诬、Binding娩梨、Queue、Consumer 之間的關(guān)系:

3.png

Routing Key览徒、Binding Key狈定、Exchange Type 的關(guān)系:

4.png

4.2 概念

5.png

4.3 投遞過程

消息隊(duì)列的使用過程大概如下:

  1. 客戶端連接到消息隊(duì)列服務(wù)器,打開一個(gè)channel
  2. 客戶端聲明一個(gè)exchange习蓬,并設(shè)置相關(guān)屬性
  3. 客戶端聲明一個(gè)queue纽什,并設(shè)置相關(guān)屬性
  4. 客戶端使用routing key,在exchange和queue之間建立好綁定關(guān)系
  5. 客戶端投遞消息到exchange
  6. 客戶端從指定的queue中消費(fèi)信息

五躲叼、rabbitmqadmin 用法

[root@h102 rabbitmq]# rabbitmqadmin --help 
Usage
=====
  rabbitmqadmin [options] subcommand

Options
=======
--help, -h              show this help message and exit
--config=CONFIG, -c CONFIG
                        configuration file [default: ~/.rabbitmqadmin.conf]
--node=NODE, -N NODE    node described in the configuration file [default:
                        'default' only if configuration file is specified]
--host=HOST, -H HOST    connect to host HOST [default: localhost]
--port=PORT, -P PORT    connect to port PORT [default: 15672]
--path-prefix=PATH_PREFIX
                        use specific URI path prefix for the RabbitMQ HTTP API
                        (default: blank string) [default: ]
--vhost=VHOST, -V VHOST
                        connect to vhost VHOST [default: all vhosts for list,
                        '/' for declare]
--username=USERNAME, -u USERNAME
                        connect using username USERNAME [default: guest]
--password=PASSWORD, -p PASSWORD
                        connect using password PASSWORD [default: guest]
--quiet, -q             suppress status messages [default: True]
--ssl, -s               connect with ssl [default: False]
--ssl-key-file=SSL_KEY_FILE
                        PEM format key file for SSL
--ssl-cert-file=SSL_CERT_FILE
                        PEM format certificate file for SSL
--format=FORMAT, -f FORMAT
                        format for listing commands - one of [raw_json, long,
                        pretty_json, kvp, tsv, table, bash] [default: table]
--sort=SORT, -S SORT    sort key for listing queries
--sort-reverse, -R      reverse the sort order
--depth=DEPTH, -d DEPTH
                        maximum depth to recurse for listing tables [default:
                        1]
--bash-completion       Print bash completion script [default: False]
--version               Display version and exit

More Help
=========

For more help use the help subcommand:

  rabbitmqadmin help subcommands  # For a list of available subcommands
  rabbitmqadmin help config       # For help with the configuration file
[root@h102 rabbitmq]# rabbitmqadmin help subcommands
Usage
=====
  rabbitmqadmin [options] subcommand

  where subcommand is one of:

Display
=======

  list users [<column>...]
  list vhosts [<column>...]
  list connections [<column>...]
  list exchanges [<column>...]
  list bindings [<column>...]
  list permissions [<column>...]
  list channels [<column>...]
  list parameters [<column>...]
  list consumers [<column>...]
  list queues [<column>...]
  list policies [<column>...]
  list nodes [<column>...]
  show overview [<column>...]

Object Manipulation
===================

  declare queue name=... [node=... auto_delete=... durable=... arguments=...]
  declare vhost name=... [tracing=...]
  declare user name=... password=... tags=...
  declare exchange name=... type=... [auto_delete=... internal=... durable=... arguments=...]
  declare policy name=... pattern=... definition=... [priority=... apply-to=...]
  declare parameter component=... name=... value=...
  declare permission vhost=... user=... configure=... write=... read=...
  declare binding source=... destination=... [arguments=... routing_key=... destination_type=...]
  delete queue name=...
  delete vhost name=...
  delete user name=...
  delete exchange name=...
  delete policy name=...
  delete parameter component=... name=...
  delete permission vhost=... user=...
  delete binding source=... destination_type=... destination=... properties_key=...
  close connection name=...
  purge queue name=...

Broker Definitions
==================

  export <file>
  import <file>

Publishing and Consuming
========================

  publish routing_key=... [exchange=... payload=... payload_encoding=... properties=...]
  get queue=... [count=... requeue=... payload_file=... encoding=...]

  * If payload is not specified on publish, standard input is used

  * If payload_file is not specified on get, the payload will be shown on
    standard output along with the message metadata

  * If payload_file is specified on get, count must not be set

[root@h102 rabbitmq]# rabbitmqadmin help config
Usage
=====
rabbitmqadmin [options] subcommand

Configuration File
==================

  It is possible to specify a configuration file from the command line.
  Hosts can be configured easily in a configuration file and called
  from the command line.

Example
=======

  # rabbitmqadmin.conf.example START

  [host_normal]
  hostname = localhost
  port = 15672
  username = guest
  password = guest
  declare_vhost = / # Used as default for declare / delete only
  vhost = /         # Used as default for declare / delete / list

  [host_ssl]
  hostname = otherhost
  port = 15672
  username = guest
  password = guest
  ssl = True
  ssl_key_file = /path/to/key.pem
  ssl_cert_file = /path/to/cert.pem

  # rabbitmqadmin.conf.example END

Use
===

  rabbitmqadmin -c rabbitmqadmin.conf.example -N host_normal ...

5.1 查詢

5.1.1 查看 users
[root@h102 rabbitmq]# rabbitmqadmin list users
+-------+-----------------------------+------------------------------+---------------+
| name  |      hashing_algorithm      |        password_hash         |     tags      |
+-------+-----------------------------+------------------------------+---------------+
| guest | rabbit_password_hashing_md5 | 7jG486YR6/F0hVLWYfCnqRyxKe4= | administrator |
| test  | rabbit_password_hashing_md5 | /iSnvCNZ5m3kvqoqqH4U3dSEqTM= | administrator |
+-------+-----------------------------+------------------------------+---------------+
[root@h102 rabbitmq]# rabbitmqadmin list users name
+-------+
| name  |
+-------+
| guest |
| test  |
+-------+
[root@h102 rabbitmq]# rabbitmqadmin list users tags
+---------------+
|     tags      |
+---------------+
| administrator |
| administrator |
+---------------+
[root@h102 rabbitmq]#
5.1.2 查看 vhosts
[root@h102 rabbitmq]# rabbitmqadmin list vhosts
+------+----------+
| name | messages |
+------+----------+
| /    | 13       |
+------+----------+
5.1.3 查看 connections
[root@h102 rabbitmq]# rabbitmqadmin list connections
No items
5.1.4 查看 exchanges
[root@h102 rabbitmq]# rabbitmqadmin list exchanges
+--------------------+---------+
|        name        |  type   |
+--------------------+---------+
|                    | direct  |
| amq.direct         | direct  |
| amq.fanout         | fanout  |
| amq.headers        | headers |
| amq.match          | headers |
| amq.rabbitmq.log   | topic   |
| amq.rabbitmq.trace | topic   |
| amq.topic          | topic   |
| kk                 | fanout  |
| test               | fanout  |
+--------------------+---------+
5.1.5 查看 bindings
[root@h102 rabbitmq]# rabbitmqadmin list bindings
+--------+-------------+-------------+
| source | destination | routing_key |
+--------+-------------+-------------+
|        | hello       | hello       |
|        | test        | test        |
| kk     | hello       | hello       |
| kk     | test        | test        |
+--------+-------------+-------------+
5.1.6 查看 permissions
[root@h102 rabbitmq]# rabbitmqadmin list permissions
+-------+-----------+------+-------+-------+
| vhost | configure | read | user  | write |
+-------+-----------+------+-------+-------+
| /     | .*        | .*   | guest | .*    |
+-------+-----------+------+-------+-------+
[root@h102 rabbitmq]# rabbitmqadmin list permissions read
+------+
| read |
+------+
| .*   |
+------+
5.1.7 查看 channels
[root@h102 rabbitmq]# rabbitmqadmin list channels
No items
5.1.8 查看 consumers
[root@h102 rabbitmq]# rabbitmqadmin list consumers
No items
5.1.9 查看 queues
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------+----------+
| name  | messages |
+-------+----------+
| hello | 8        |
| test  | 5        |
+-------+----------+
5.1.10 查看 查看 policies
[root@h102 rabbitmq]# rabbitmqadmin list policies
No items
5.1.11 查看 nodes
[root@h102 rabbitmq]# rabbitmqadmin list nodes
+-------------+------+----------+
|    name     | type | mem_used |
+-------------+------+----------+
| rabbit@h102 | disc | 52274376 |

+-------------+------+----------+

5.1.12 查看 overview
[root@h102 rabbitmq]# rabbitmqadmin show overview
+------------------+------------------+-----------------------+----------------------+
| rabbitmq_version |   cluster_name   | queue_totals.messages | object_totals.queues |
+------------------+------------------+-----------------------+----------------------+
| 3.6.1            | rabbit@h101.temp | 13                    | 2                    |
+------------------+------------------+-----------------------+----------------------+

5.2 刪除

5.2.1 刪除 queue
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------+----------+
| name  | messages |
+-------+----------+
| hello | 8        |
| test  | 5        |
+-------+----------+
[root@h102 rabbitmq]# rabbitmqadmin delete queue name=hello
queue deleted
[root@h102 rabbitmq]# rabbitmqadmin list queues
+------+----------+
| name | messages |
+------+----------+
| test | 5        |
+------+----------+
5.2.2 刪除 user
[root@h102 rabbitmq]# rabbitmqadmin list users
+-------+-----------------------------+------------------------------+---------------+
| name  |      hashing_algorithm      |        password_hash         |     tags      |
+-------+-----------------------------+------------------------------+---------------+
| guest | rabbit_password_hashing_md5 | 7jG486YR6/F0hVLWYfCnqRyxKe4= | administrator |
| test  | rabbit_password_hashing_md5 | /iSnvCNZ5m3kvqoqqH4U3dSEqTM= | administrator |
+-------+-----------------------------+------------------------------+---------------+
[root@h102 rabbitmq]# rabbitmqadmin delete user name=test
user deleted
[root@h102 rabbitmq]# rabbitmqadmin list users
+-------+-----------------------------+------------------------------+---------------+
| name  |      hashing_algorithm      |        password_hash         |     tags      |
+-------+-----------------------------+------------------------------+---------------+
| guest | rabbit_password_hashing_md5 | 7jG486YR6/F0hVLWYfCnqRyxKe4= | administrator |
+-------+-----------------------------+------------------------------+---------------+
5.2.3 刪除 exchange
[root@h102 rabbitmq]# rabbitmqadmin list exchanges
+--------------------+---------+
|        name        |  type   |
+--------------------+---------+
|                    | direct  |
| amq.direct         | direct  |
| amq.fanout         | fanout  |
| amq.headers        | headers |
| amq.match          | headers |
| amq.rabbitmq.log   | topic   |
| amq.rabbitmq.trace | topic   |
| amq.topic          | topic   |
| kk                 | fanout  |
| test               | fanout  |
+--------------------+---------+
[root@h102 rabbitmq]# rabbitmqadmin delete exchange name=test
exchange deleted
[root@h102 rabbitmq]# rabbitmqadmin list exchanges
+--------------------+---------+
|        name        |  type   |
+--------------------+---------+
|                    | direct  |
| amq.direct         | direct  |
| amq.fanout         | fanout  |
| amq.headers        | headers |
| amq.match          | headers |
| amq.rabbitmq.log   | topic   |
| amq.rabbitmq.trace | topic   |
| amq.topic          | topic   |
| kk                 | fanout  |
+--------------------+---------+
5.2.4 刪除 binding
[root@h102 rabbitmq]# rabbitmqadmin list bindings  source destination_type destination properties_key
+--------+------------------+-------------+----------------+
| source | destination_type | destination | properties_key |
+--------+------------------+-------------+----------------+
|        | queue            | test        | test           |
| kk     | queue            | test        | test           |
+--------+------------------+-------------+----------------+
[root@h102 rabbitmq]# rabbitmqadmin delete binding source='kk'  destination_type=queue  destination=test  properties_key=test
binding deleted
[root@h102 rabbitmq]# rabbitmqadmin list bindings source destination_type destination properties_key
+--------+------------------+-------------+----------------+
| source | destination_type | destination | properties_key |
+--------+------------------+-------------+----------------+
|        | queue            | test        | test           |
+--------+------------------+-------------+----------------+

Note: source芦缰、 destination_type、destination枫慷、properties_key 缺一不可让蕾,否則會(huì)報(bào)錯(cuò)
Tip: vhost、policy或听、parameter探孝、permission 的刪除方法類似 ,connection 的關(guān)閉方法也類似
5.2.5 清空隊(duì)列
[root@h102 rabbitmq]# rabbitmqadmin list queues
+------+----------+
| name | messages |
+------+----------+
| test | 5        |
+------+----------+
[root@h102 rabbitmq]# rabbitmqadmin purge queue name=test
queue purged
[root@h102 rabbitmq]# rabbitmqadmin list queues
+------+----------+
| name | messages |
+------+----------+
| test | 0        |
+------+----------+
5.2.6 格式化輸出
使用 -f 可以指定格式

有如下幾種格式 raw_json, long, pretty_json, kvp, tsv, table, bash

默認(rèn)為 table

[root@h102 rabbitmq]# rabbitmqadmin list users
+-------+-----------------------------+------------------------------+---------------+
| name  |      hashing_algorithm      |        password_hash         |     tags      |
+-------+-----------------------------+------------------------------+---------------+
| guest | rabbit_password_hashing_md5 | 7jG486YR6/F0hVLWYfCnqRyxKe4= | administrator |
+-------+-----------------------------+------------------------------+---------------+
[root@h102 rabbitmq]# rabbitmqadmin -f raw_json list users
[{"name":"guest","password_hash":"7jG486YR6/F0hVLWYfCnqRyxKe4=","hashing_algorithm":"rabbit_password_hashing_md5","tags":"administrator"}]
[root@h102 rabbitmq]# rabbitmqadmin -f long list users

--------------------------------------------------------------------------------

             name: guest
hashing_algorithm: rabbit_password_hashing_md5
    password_hash: 7jG486YR6/F0hVLWYfCnqRyxKe4=
             tags: administrator

--------------------------------------------------------------------------------

[root@h102 rabbitmq]# rabbitmqadmin -f pretty_json list users
[
  {
    "hashing_algorithm": "rabbit_password_hashing_md5", 
    "name": "guest", 
    "password_hash": "7jG486YR6/F0hVLWYfCnqRyxKe4=", 
    "tags": "administrator"
  }
]
[root@h102 rabbitmq]# rabbitmqadmin -f kvp list users
name="guest" hashing_algorithm="rabbit_password_hashing_md5" password_hash="7jG486YR6/F0hVLWYfCnqRyxKe4=" tags="administrator"
[root@h102 rabbitmq]# rabbitmqadmin -f tsv list users
name    hashing_algorithm   password_hash   tags
guest   rabbit_password_hashing_md5 7jG486YR6/F0hVLWYfCnqRyxKe4=    administrator
[root@h102 rabbitmq]# rabbitmqadmin -f table list users
+-------+-----------------------------+------------------------------+---------------+
| name  |      hashing_algorithm      |        password_hash         |     tags      |
+-------+-----------------------------+------------------------------+---------------+
| guest | rabbit_password_hashing_md5 | 7jG486YR6/F0hVLWYfCnqRyxKe4= | administrator |
+-------+-----------------------------+------------------------------+---------------+
[root@h102 rabbitmq]# rabbitmqadmin -f bash list users
guest

5.3 聲明定義

5.3.1 定義一個(gè) queue
[root@h102 rabbitmq]# rabbitmqadmin list bindings
No items
[root@h102 rabbitmq]# rabbitmqadmin list queues
No items
[root@h102 rabbitmq]# rabbitmqadmin declare queue name=test  durable=true
queue declared
[root@h102 rabbitmq]# rabbitmqadmin list queues
+------+----------+
| name | messages |
+------+----------+
| test | 0        |
+------+----------+
[root@h102 rabbitmq]# rabbitmqadmin list bindings
+--------+-------------+-------------+
| source | destination | routing_key |
+--------+-------------+-------------+
|        | test        | test        |
+--------+-------------+-------------+

PS :
durable=true 代表持久化打開

發(fā)現(xiàn)定義一個(gè)新的queue后神帅,RabbitMQ會(huì)自動(dòng)為之創(chuàng)建一個(gè) binding
5.3.2 發(fā)布一條消息
[root@h102 rabbitmq]# rabbitmqadmin list queues
+------+----------+
| name | messages |
+------+----------+
| test | 0        |
+------+----------+
[root@h102 rabbitmq]# rabbitmqadmin publish routing_key=test payload="just for test"
Message published
[root@h102 rabbitmq]# rabbitmqadmin list queues
+------+----------+
| name | messages |
+------+----------+
| test | 1        |
+------+----------+

Tip: 這里有一個(gè)細(xì)節(jié)再姑,我們并未指定任何 exchange ,依舊可以成功發(fā)送消息找御,
    是不是不需要 exchange 參與整個(gè)消息的派送過程呢元镀,這和前面說的信息處理流程貌似有沖突呀,先賣個(gè)關(guān)子霎桅,后面再解釋
5.3.3 消費(fèi)一條信息
[root@h102 rabbitmq]# rabbitmqadmin get queue=test requeue=true
+-------------+----------+---------------+---------------+---------------+------------------+------------+-------------+
| routing_key | exchange | message_count |    payload    | payload_bytes | payload_encoding | properties | redelivered |
+-------------+----------+---------------+---------------+---------------+------------------+------------+-------------+
| test        |          | 0             | just for test | 13            | string           |            | False       |
+-------------+----------+---------------+---------------+---------------+------------------+------------+-------------+
[root@h102 rabbitmq]# rabbitmqadmin list queues
+------+----------+
| name | messages |
+------+----------+
| test | 1        |
+------+----------+
[root@h102 rabbitmq]# rabbitmqadmin get queue=test requeue=false
+-------------+----------+---------------+---------------+---------------+------------------+------------+-------------+
| routing_key | exchange | message_count |    payload    | payload_bytes | payload_encoding | properties | redelivered |
+-------------+----------+---------------+---------------+---------------+------------------+------------+-------------+
| test        |          | 0             | just for test | 13            | string           |            | True        |
+-------------+----------+---------------+---------------+---------------+------------------+------------+-------------+
[root@h102 rabbitmq]# rabbitmqadmin list queues
+------+----------+
| name | messages |
+------+----------+
| test | 0        |
+------+----------+
5.3.4 定義一個(gè) exchange

我們前面發(fā)布消息的過程中并未指定exchange栖疑,依舊成功發(fā)布了,事實(shí)上只是未明確指出滔驶,系統(tǒng)還是幫我們指了遇革,RabbitMQ 的邏輯中是沒法繞過 exchange 而直接給queue發(fā)送消息的

exchange 有以下幾種類型:

direct,topic,headers萝快,fanout

Fanout锻霎、Direct、Topic 三種 Exchange Type 的區(qū)別:

6.png

系統(tǒng)中默認(rèn)就有如下 exchange:

[root@h102 rabbitmq]# rabbitmqadmin list exchanges
+--------------------+---------+
|        name        |  type   |
+--------------------+---------+
|                    | direct  |
| amq.direct         | direct  |
| amq.fanout         | fanout  |
| amq.headers        | headers |
| amq.match          | headers |
| amq.rabbitmq.log   | topic   |
| amq.rabbitmq.trace | topic   |
| amq.topic          | topic   |
+--------------------+---------+
[root@h102 rabbitmq]#

我們創(chuàng)建了一個(gè) queue 后揪漩,系統(tǒng)自動(dòng)為它定義了一個(gè) binding:

[root@h102 rabbitmq]# rabbitmqadmin list bindings
+--------+-------------+-------------+
| source | destination | routing_key |
+--------+-------------+-------------+
|        | test        | test        |
+--------+-------------+-------------+

從中我們看出了一些端倪旋恼,我們不手動(dòng)指定 exchange時(shí),使用的默認(rèn) exchange是空字符串(系統(tǒng)中的第一個(gè)exchange奄容,binding中的source部分)冰更,并且這個(gè)默認(rèn)的exchange是 direct 類型,這種隱式調(diào)用確保了我的消息準(zhǔn)確投遞昂勒。

這里再定義三個(gè)exchange 分屬三種類型:

[root@h102 rabbitmq]# rabbitmqadmin list exchanges
+--------------------+---------+
|        name        |  type   |
+--------------------+---------+
|                    | direct  |
| amq.direct         | direct  |
| amq.fanout         | fanout  |
| amq.headers        | headers |
| amq.match          | headers |
| amq.rabbitmq.log   | topic   |
| amq.rabbitmq.trace | topic   |
| amq.topic          | topic   |
+--------------------+---------+
[root@h102 rabbitmq]# rabbitmqadmin declare exchange name=my.fanout type=fanout
exchange declared
[root@h102 rabbitmq]# rabbitmqadmin declare exchange name=my.direct type=direct
exchange declared
[root@h102 rabbitmq]# rabbitmqadmin declare exchange name=my.topic type=topic
exchange declared
[root@h102 rabbitmq]# rabbitmqadmin list exchanges
+--------------------+---------+
|        name        |  type   |
+--------------------+---------+
|                    | direct  |
| amq.direct         | direct  |
| amq.fanout         | fanout  |
| amq.headers        | headers |
| amq.match          | headers |
| amq.rabbitmq.log   | topic   |
| amq.rabbitmq.trace | topic   |
| amq.topic          | topic   |
| my.direct          | direct  |
| my.fanout          | fanout  |
| my.topic           | topic   |
+--------------------+---------+
[root@h102 rabbitmq]#
[root@h102 rabbitmq]# rabbitmqadmin list bindings
+--------+-------------+-------------+
| source | destination | routing_key |
+--------+-------------+-------------+
|        | test        | test        |
+--------+-------------+-------------+
5.3.5 定義 binding

上面申明了幾個(gè) exchange 蜀细,嘗試發(fā)布一條信息:

[root@h102 rabbitmq]# rabbitmqadmin list queues
+------+----------+
| name | messages |
+------+----------+
| test | 0        |
+------+----------+
[root@h102 rabbitmq]# rabbitmqadmin publish routing_key=test exchange=my.fanout  payload="just for test"
Message published but NOT routed
[root@h102 rabbitmq]# rabbitmqadmin list queues
+------+----------+
| name | messages |
+------+----------+
| test | 0        |
+------+----------+
[root@h102 rabbitmq]# rabbitmqadmin publish routing_key=test payload="just for test2"
Message published
[root@h102 rabbitmq]# rabbitmqadmin list queues
+------+----------+
| name | messages |
+------+----------+
| test | 1        |
+------+----------+
[root@h102 rabbitmq]# rabbitmqadmin list bindings
+--------+-------------+-------------+
| source | destination | routing_key |
+--------+-------------+-------------+
|        | test        | test        |
+--------+-------------+-------------+

指定 exchange=my.fanout 后,報(bào) Message published but NOT routed 戈盈,然后檢查queue 發(fā)現(xiàn)并產(chǎn)生新消息奠衔,而直接不指定卻成功發(fā)布了,原因是沒有binding奕谭,exchange 并不知道將數(shù)據(jù)轉(zhuǎn)發(fā)給誰

binding 定義了 exchange 與 queue 的關(guān)系涣觉,并且限定了路由的部分規(guī)則

信息路由規(guī)則一部分由 exchange的類型決定 痴荐,一部分由 binding 關(guān)系決定血柳,binding 的 key 還能起到甄選信息的作用。

我們創(chuàng)建一個(gè) binding:

[root@h102 rabbitmq]# rabbitmqadmin list bindings
+--------+-------------+-------------+
| source | destination | routing_key |
+--------+-------------+-------------+
|        | test        | test        |
+--------+-------------+-------------+
[root@h102 rabbitmq]# rabbitmqadmin declare binding source=my.fanout destination=test routing_key=first
binding declared
[root@h102 rabbitmq]# rabbitmqadmin list bindings
+-----------+-------------+-------------+
|  source   | destination | routing_key |
+-----------+-------------+-------------+
|           | test        | test        |
| my.fanout | test        | first       |
+-----------+-------------+-------------+

再次嘗試發(fā)布信息:

[root@h102 rabbitmq]# rabbitmqadmin list queues
+------+----------+
| name | messages |
+------+----------+
| test | 0        |
+------+----------+
[root@h102 rabbitmq]# rabbitmqadmin get queue=test requeue=true
No items
[root@h102 rabbitmq]# rabbitmqadmin publish routing_key=first exchange=my.fanout  payload="just for test1"
Message published
[root@h102 rabbitmq]# rabbitmqadmin list queues
+------+----------+
| name | messages |
+------+----------+
| test | 1        |
+------+----------+
[root@h102 rabbitmq]# rabbitmqadmin publish routing_key=first payload="just for test2"
Message published but NOT routed
[root@h102 rabbitmq]# rabbitmqadmin list queues
+------+----------+
| name | messages |
+------+----------+
| test | 1        |
+------+----------+
[root@h102 rabbitmq]# rabbitmqadmin get queue=test requeue=true
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| routing_key | exchange  | message_count |    payload     | payload_bytes | payload_encoding | properties | redelivered |
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| first       | my.fanout | 0             | just for test1 | 14            | string           |            | False       |
+-------------+-----------+---------------+----------------+---------------+------------------+------------+
5.3.6 fanout 的特性

定義第二個(gè)queue 生兆,也使用 my.fanout binding 起來难捌,取 routing_key 為 second:

[root@h102 rabbitmq]# rabbitmqadmin list queues
+------+----------+
| name | messages |
+------+----------+
| test | 1        |
+------+----------+
[root@h102 rabbitmq]# rabbitmqadmin declare queue name=test.fanout durable=true
queue declared
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 1        |
| test.fanout | 0        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin list bindings
+-----------+-------------+-------------+
|  source   | destination | routing_key |
+-----------+-------------+-------------+
|           | test        | test        |
|           | test.fanout | test.fanout |
| my.fanout | test        | first       |
+-----------+-------------+-------------+
[root@h102 rabbitmq]# 
[root@h102 rabbitmq]# rabbitmqadmin declare binding source=my.fanout destination=test.fanout routing_key=second
binding declared
[root@h102 rabbitmq]# rabbitmqadmin list bindings
+-----------+-------------+-------------+
|  source   | destination | routing_key |
+-----------+-------------+-------------+
|           | test        | test        |
|           | test.fanout | test.fanout |
| my.fanout | test        | first       |
| my.fanout | test.fanout | second      |
+-----------+-------------+-------------+

嘗試再發(fā)一條數(shù)據(jù)到 my.fanout 中:

[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 1        |
| test.fanout | 0        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin publish routing_key=second exchange=my.fanout payload="just for test3"
Message published
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 2        |
| test.fanout | 1        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin get queue=test requeue=true
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| routing_key | exchange  | message_count |    payload     | payload_bytes | payload_encoding | properties | redelivered |
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| first       | my.fanout | 1             | just for test1 | 14            | string           |            | True        |
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
[root@h102 rabbitmq]# rabbitmqadmin get queue=test.fanout requeue=true
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| routing_key | exchange  | message_count |    payload     | payload_bytes | payload_encoding | properties | redelivered |
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| second      | my.fanout | 0             | just for test3 | 14            | string           |            | False       |
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 2        |
| test.fanout | 1        |
+-------------+----------+

這次我們使用 routing_key=first 來投遞消息:

[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 2        |
| test.fanout | 1        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin purge queue name=test
queue purged
[root@h102 rabbitmq]# rabbitmqadmin purge queue name=test.fanout
queue purged
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 0        |
| test.fanout | 0        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin publish routing_key=first exchange=my.fanout payload="just for test4"
Message published
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 1        |
| test.fanout | 1        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin get queue=test requeue=true
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| routing_key | exchange  | message_count |    payload     | payload_bytes | payload_encoding | properties | redelivered |
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| first       | my.fanout | 0             | just for test4 | 14            | string           |            | False       |
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
[root@h102 rabbitmq]# rabbitmqadmin get queue=test.fanout requeue=true
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| routing_key | exchange  | message_count |    payload     | payload_bytes | payload_encoding | properties | redelivered |
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| first       | my.fanout | 0             | just for test4 | 14            | string           |            | False       |
+-------------+-----------+---------------+----------------+---------------+------------------+------------

發(fā)現(xiàn)結(jié)果一樣,應(yīng)證了前面說的 routing_key 會(huì)被忽略的說法鸦难,但是不能不指定根吁,否則會(huì)報(bào)錯(cuò):

[root@h102 rabbitmq]# rabbitmqadmin publish exchange=my.fanout payload="just for test5"

ERROR: mandatory argument "routing_key" required

rabbitmqadmin --help for help

[root@h102 rabbitmq]#
5.3.7 direct 的特性

定義第三個(gè)queue ,使用 my.direct binding 起來:

[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 0        |
| test.fanout | 0        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin declare queue name=test.direct durable=true
queue declared
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 0        |
| test.direct | 0        |
| test.fanout | 0        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin declare binding source=my.direct destination=test routing_key=third
binding declared
[root@h102 rabbitmq]# rabbitmqadmin declare binding source=my.direct destination=test.direct routing_key=fourth
binding declared
[root@h102 rabbitmq]# rabbitmqadmin list bindings
+-----------+-------------+-------------+
|  source   | destination | routing_key |
+-----------+-------------+-------------+
|           | test        | test        |
|           | test.direct | test.direct |
|           | test.fanout | test.fanout |
| my.direct | test        | third       |
| my.direct | test.direct | fourth      |
| my.fanout | test        | first       |
| my.fanout | test.fanout | second      |
+-----------+-------------+-------------+
[root@h102 rabbitmq]# 

嘗試分別使用 third 和 fourth 的 routing_key 來發(fā)布消息:

[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 0        |
| test.direct | 0        |
| test.fanout | 0        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin publish routing_key=third exchange=my.direct payload="just for test6"
Message published
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 1        |
| test.direct | 0        |
| test.fanout | 0        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin get queue=test requeue=true
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| routing_key | exchange  | message_count |    payload     | payload_bytes | payload_encoding | properties | redelivered |
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| third       | my.direct | 0             | just for test6 | 14            | string           |            | False       |
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
[root@h102 rabbitmq]# rabbitmqadmin publish routing_key=fourth exchange=my.direct payload="just for test7"
Message published
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 1        |
| test.direct | 1        |
| test.fanout | 0        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin get queue=test.direct requeue=true
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| routing_key | exchange  | message_count |    payload     | payload_bytes | payload_encoding | properties | redelivered |
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| fourth      | my.direct | 0             | just for test7 | 14            | string           |            | False       |
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
[root@h102 rabbitmq]# 

從反饋結(jié)果來看合蔽,direct 的 exchange 就像點(diǎn)對(duì)點(diǎn)通信击敌,fanout 的 exchange 就像是廣播

5.3.4 topic 的特性

定義第四個(gè)queue ,使用 my.topic binding 起來

[root@h102 rabbitmq]# rabbitmqadmin purge queue name=test
queue purged
[root@h102 rabbitmq]# rabbitmqadmin purge queue name=test.direct
queue purged
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 0        |
| test.direct | 0        |
| test.fanout | 0        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin declare queue name=test.topic durable=true
queue declared
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 0        |
| test.direct | 0        |
| test.fanout | 0        |
| test.topic  | 0        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin declare binding source=my.topic destination=test routing_key=*.hard.* 
binding declared
[root@h102 rabbitmq]# rabbitmqadmin declare binding source=my.topic destination=test.topic routing_key=cheap.# 
binding declared
[root@h102 rabbitmq]# rabbitmqadmin declare binding source=my.topic destination=test.direct routing_key=*.*.food 
binding declared
[root@h102 rabbitmq]# rabbitmqadmin declare binding source=my.topic destination=test.fanout routing_key=*.*.food
binding declared
[root@h102 rabbitmq]# rabbitmqadmin list bindings
+-----------+-------------+-------------+
|  source   | destination | routing_key |
+-----------+-------------+-------------+
|           | test        | test        |
|           | test.direct | test.direct |
|           | test.fanout | test.fanout |
|           | test.topic  | test.topic  |
| my.direct | test        | third       |
| my.direct | test.direct | fourth      |
| my.fanout | test        | first       |
| my.fanout | test.fanout | second      |
| my.topic  | test        | *.hard.*    |
| my.topic  | test.direct | *.*.food    |
| my.topic  | test.fanout | *.*.food    |
| my.topic  | test.topic  | cheap.#     |
+-----------+-------------+-------------+

如果不使用 * 和 # 拴事,那么 topic 的特性就和 direct 一樣了:

[root@h102 rabbitmq]# rabbitmqadmin declare binding source=my.topic destination=test.fanout routing_key=xtest
binding declared
[root@h102 rabbitmq]# rabbitmqadmin list bindings
+-----------+-------------+-------------+
|  source   | destination | routing_key |
+-----------+-------------+-------------+
|           | test        | test        |
|           | test.direct | test.direct |
|           | test.fanout | test.fanout |
|           | test.topic  | test.topic  |
| my.direct | test        | third       |
| my.direct | test.direct | fourth      |
| my.fanout | test        | first       |
| my.fanout | test.fanout | second      |
| my.topic  | test        | *.hard.*    |
| my.topic  | test.direct | *.*.food    |
| my.topic  | test.fanout | *.*.food    |
| my.topic  | test.fanout | xtest       |
| my.topic  | test.topic  | cheap.#     |
+-----------+-------------+-------------+
[root@h102 rabbitmq]#

嘗試使用以上 routing_key 發(fā)送消息:

[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 0        |
| test.direct | 0        |
| test.fanout | 0        |
| test.topic  | 0        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin publish routing_key=a.hard.b  exchange=my.topic payload="just for test8"
Message published
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 1        |
| test.direct | 0        |
| test.fanout | 0        |
| test.topic  | 0        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin publish routing_key=a.hard.food  exchange=my.topic payload="just for test9"
Message published
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 2        |
| test.direct | 1        |
| test.fanout | 1        |
| test.topic  | 0        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin publish routing_key=cheap.soft.food  exchange=my.topic payload="just for test10"
Message published
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 2        |
| test.direct | 2        |
| test.fanout | 2        |
| test.topic  | 1        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin publish routing_key=cheap.hard.drink  exchange=my.topic payload="just for test11"
Message published
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 3        |
| test.direct | 2        |
| test.fanout | 2        |
| test.topic  | 2        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin publish routing_key=xtest exchange=my.topic payload="just for test12"
Message published
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 3        |
| test.direct | 2        |
| test.fanout | 3        |
| test.topic  | 2        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin publish routing_key=cheap.hard.food  exchange=my.topic payload="just for test13"
Message published
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 4        |
| test.direct | 2        |
| test.fanout | 4        |
| test.topic  | 3        |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
|    name     | messages |
+-------------+----------+
| test        | 4        |
| test.direct | 3        |
| test.fanout | 4        |
| test.topic  | 3        |
+-------------+----------+
[root@h102 rabbitmq]# 

到此為止沃斤,我們看到了 topic 的組播,異步特性

六刃宵、rabbitmqadmin命令匯總

wget http://localhost:15672/cli/rabbitmqadmin
rabbitmqadmin --help
rabbitmqadmin help subcommands
rabbitmqadmin help config
rabbitmqadmin list users        查看所有用戶 User
rabbitmqadmin list users name       查看所有用戶名 Username
rabbitmqadmin list users tags       查看所有用戶角色
rabbitmqadmin list vhosts       查看所有虛擬主機(jī)
rabbitmqadmin list connections      查看所有連接
rabbitmqadmin list exchanges        查看所有路由 Exchange
rabbitmqadmin list bindings     查看所有路由與隊(duì)列的關(guān)系綁定binding
rabbitmqadmin list permissions      查看所有角色的權(quán)限 Permission
rabbitmqadmin list channels     查看所有通道 Channel
rabbitmqadmin list consumers        查看所有消費(fèi)者 Consumer
rabbitmqadmin list queues       查看所有消息隊(duì)列 Queue
rabbitmqadmin list nodes        查看所有節(jié)點(diǎn) Node
rabbitmqadmin show overview     概覽 Overview
rabbitmqadmin list bindings source destination_type destination properties_key      查看所有路由與隊(duì)列的關(guān)系綁定的詳細(xì)信息 Binding
rabbitmqadmin purge queue name=test     清空隊(duì)列
rabbitmqadmin -f raw_json list users        格式化輸出
rabbitmqadmin -f long list users        格式化輸出
rabbitmqadmin -f pretty_json list users
rabbitmqadmin -f kvp list users
rabbitmqadmin -f tsv list users
rabbitmqadmin -f table list users
rabbitmqadmin -f bash list users
rabbitmqadmin declare queue name=test durable=true      定義一個(gè)隊(duì)列queue衡瓶,durable=true 代表持久化打開。
rabbitmqadmin publish routing_key=test payload="just for test"      發(fā)布一條消息
rabbitmqadmin get queue=test requeue=true       消費(fèi)一條信息
rabbitmqadmin get queue=test requeue=false
rabbitmqadmin declare exchange name=my.fanout type=fanout       定義一個(gè)Fanout路由
rabbitmqadmin declare exchange name=my.direct type=direct       定義一個(gè)Direct路由
rabbitmqadmin declare exchange name=my.topic type=topic         定義一個(gè)Topic路由
rabbitmqadmin declare binding source=my.fanout destination=test routing_key=first       定義 binding
rabbitmqadmin delete queue name=hello       刪除消息隊(duì)列 Queue
rabbitmqadmin delete user name=test     刪除用戶 User
rabbitmqadmin delete exchange name=test     刪除路由器 Exchange
rabbitmqadmin delete binding source='kk' destination_type=queue destination=test properties_key=test        刪除路由器與消息隊(duì)列的關(guān)系綁定 Binding
rabbitmqadmin publish routing_key=first exchange=my.fanout payload="just for test1"     使用路由轉(zhuǎn)發(fā)消息
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末牲证,一起剝皮案震驚了整個(gè)濱河市哮针,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖十厢,帶你破解...
    沈念sama閱讀 212,383評(píng)論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件等太,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡蛮放,警方通過查閱死者的電腦和手機(jī)澈驼,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,522評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來筛武,“玉大人缝其,你說我怎么就攤上這事∨橇” “怎么了内边?”我有些...
    開封第一講書人閱讀 157,852評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)待锈。 經(jīng)常有香客問我漠其,道長(zhǎng),這世上最難降的妖魔是什么竿音? 我笑而不...
    開封第一講書人閱讀 56,621評(píng)論 1 284
  • 正文 為了忘掉前任和屎,我火速辦了婚禮,結(jié)果婚禮上春瞬,老公的妹妹穿的比我還像新娘柴信。我一直安慰自己,他們只是感情好宽气,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,741評(píng)論 6 386
  • 文/花漫 我一把揭開白布随常。 她就那樣靜靜地躺著,像睡著了一般萄涯。 火紅的嫁衣襯著肌膚如雪绪氛。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,929評(píng)論 1 290
  • 那天涝影,我揣著相機(jī)與錄音枣察,去河邊找鬼。 笑死燃逻,一個(gè)胖子當(dāng)著我的面吹牛序目,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播唆樊,決...
    沈念sama閱讀 39,076評(píng)論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼宛琅,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了逗旁?” 一聲冷哼從身側(cè)響起嘿辟,我...
    開封第一講書人閱讀 37,803評(píng)論 0 268
  • 序言:老撾萬榮一對(duì)情侶失蹤舆瘪,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后红伦,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體英古,經(jīng)...
    沈念sama閱讀 44,265評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,582評(píng)論 2 327
  • 正文 我和宋清朗相戀三年昙读,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了召调。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,716評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡蛮浑,死狀恐怖唠叛,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情沮稚,我是刑警寧澤艺沼,帶...
    沈念sama閱讀 34,395評(píng)論 4 333
  • 正文 年R本政府宣布,位于F島的核電站蕴掏,受9級(jí)特大地震影響障般,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜盛杰,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,039評(píng)論 3 316
  • 文/蒙蒙 一挽荡、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧即供,春花似錦定拟、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,798評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至祸穷,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間勺三,已是汗流浹背雷滚。 一陣腳步聲響...
    開封第一講書人閱讀 32,027評(píng)論 1 266
  • 我被黑心中介騙來泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留吗坚,地道東北人祈远。 一個(gè)月前我還...
    沈念sama閱讀 46,488評(píng)論 2 361
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像商源,于是被迫代替她去往敵國(guó)和親车份。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,612評(píng)論 2 350