README
author Michael Bridgen <mikeb@rabbitmq.com>
Tue Aug 24 16:12:15 2010 +0100 (21 months ago)
changeset 99 e96b29ca5cbb
parent 84 b336b477d57c
child 121 cfa00b4103fc
permissions -rw-r--r--
Added tag rabbitmq_v2_0_0 for changeset d68220948b37
     1 RabbitMQ-shovel
     2 ===============
     3 
     4 
     5 Introduction
     6 ------------
     7 
     8 This is a plug-in for RabbitMQ that shovels messages from a queue on
     9 one broker to an exchange on another broker. The two brokers may be
    10 the same. The plug-in allows several shovels to be specified at the
    11 same time. Each shovel may have a number of source and destination
    12 brokers specified, and one of each is chosen whenever the shovel
    13 attempts to make a connection: this permits simple round-rabbit load
    14 balancing.
    15 
    16 Resources can be declared upon connection to both the source and
    17 destination brokers, and parameters can be specified for both the
    18 reception and publishing of messages.
    19 
    20 
    21 Requirements
    22 ------------
    23 
    24 Currently, you must build the server from source. You must also have
    25 checked out the rabbitmq-public-umbrella hg repository, and have the
    26 rabbitmq-erlang-client built. From scratch, the following commands
    27 should build RabbitMQ with the shovel plug-in:
    28 
    29 hg clone http://hg.rabbitmq.com/rabbitmq-public-umbrella
    30 cd rabbitmq-public-umbrella
    31 hg clone http://hg.rabbitmq.com/rabbitmq-codegen
    32 hg clone http://hg.rabbitmq.com/rabbitmq-erlang-client
    33 hg clone http://hg.rabbitmq.com/rabbitmq-server
    34 hg clone http://hg.rabbitmq.com/rabbitmq-shovel
    35 cd rabbitmq-server
    36 make -j
    37 mkdir -p plugins
    38 cd plugins
    39 ln -s ../../rabbitmq-erlang-client
    40 ln -s ../../rabbitmq-shovel
    41 cd ../../rabbitmq-erlang-client
    42 make
    43 cd ../rabbitmq-shovel
    44 make
    45 cd ../rabbitmq-server
    46 ./scripts/rabbitmq-activate-plugins
    47 make cleandb run
    48 
    49 
    50 Configuration
    51 -------------
    52 
    53 The RabbitMQ configuration file specifies the shovel
    54 configurations. This exists by default, in
    55 /etc/rabbitmq/rabbitmq.config under Linux systems,
    56 %RABBITMQ_BASE%\rabbitmq.config under Windows or somewhere else under
    57 OS X. This file configures both RabbitMQ-server and all the plugins
    58 installed in it. It is an Erlang-syntax file of the form:
    59 
    60 [{section1, [section1-config]},
    61  {section2, [section2-config]},
    62  ...
    63  {sectionN, [sectionN-config]}
    64 ].
    65 
    66 thus a list of tuples, where the left element of each tuple names the
    67 applications being configured. Don't forget the last element of the
    68 list doesn't have a trailing comma, and don't forget the full-stop is
    69 needed after closing the list. Hence if you configure RabbitMQ-server
    70 and the RabbitMQ-shovel, then the configuration file may have a
    71 structure like this:
    72 
    73 [{rabbit,        [configuration-for-RabbitMQ-server]},
    74  {rabbit-shovel, [configuration-for-RabbitMQ-shovel]}
    75 ].
    76 
    77 A full example of the shovel configuration is:
    78 
    79 {rabbit_shovel,
    80   [{shovels,
    81     [{my_first_shovel,
    82       [{sources,      [{brokers,
    83                           ["amqp://fred:secret@host1.domain/my_vhost",
    84                            "amqp://john:secret@host2.domain/my_vhost"
    85                           ]},
    86                        {declarations,
    87                           ['queue.declare',
    88                            {'queue.bind',
    89                                   [{exchange, <<"my_exchange">>},
    90                                    {queue,    <<>>}]}
    91                           ]}]},
    92        {destinations, [{broker, "amqp://"},
    93                        {declarations,
    94                           [{'exchange.declare',
    95                                   [{exchange, <<"my_exchange">>},
    96                                    {type, <<"direct">>},
    97                                    durable]}
    98                           ]}]},
    99        {queue, <<>>},
   100        {prefetch_count, 10},
   101        {auto_ack, false},
   102        {tx_size, 0},
   103        {publish_properties, [{delivery_mode, 2}]},
   104        {publish_fields, [{exchange, <<"my_exchange">>},
   105                          {routing_key, <<"from_shovel">>}]},
   106        {reconnect_delay, 5}
   107       ]}
   108      ]
   109    }]
   110 }
   111 
   112 Firstly, all shovels are named. Here we have one shovel, called
   113 'my_first_shovel'. We can have multiple shovels if you wish. Secondly,
   114 every shovel must have the subfields sources, destinations and queue
   115 specified, whereas the other fields (prefetch_count, auto_ack,
   116 tx_size, publish_properties, publish_fields, reconnect_delay) are
   117 optional and have defaults as follows:
   118 
   119 {prefetch_count,      0}
   120 {auto_ack,            false}
   121 {tx_size,             0}
   122 {publish_properties,  []}
   123 {publish_fields,      []}
   124 {reconnect_delay,     5}
   125 
   126 
   127 Sources and Destinations
   128 ------------------------
   129 
   130 Sources and destinations specify respectively where messages are
   131 fetched from and delivered too. One of 'broker' and 'brokers' must be
   132 specified, and 'broker' is simply shorthand for when only one broker
   133 needs specifying. Using 'brokers' allows a list of brokers to be
   134 specified: whenever the connection to a broker is lost, another one is
   135 chosen at random from the list and a connection attempt is made to
   136 that. The syntax for broker URIs is:
   137 
   138 amqp://username:password@host:port/vhost
   139 
   140 If username or password are omitted, the default values of guest and
   141 guest are used. If the vhost is omitted, the default value of / is
   142 used. If the host is omitted, then the plugin uses the "direct"
   143 connection internally rather than a network connection: this means it
   144 connects to the RabbitMQ-server node on which it is running without
   145 going through the network stack. This is much more efficient. If port
   146 is omitted then the default value is used (5672 or 5671 if SSL is
   147 used).
   148 
   149 SSL is implemented, for which additional parameters are needed:
   150 
   151 amqps://username:password@host:port/vhost?cacertfile=/path/to/cacert.pem&certfile=/path/to/certfile.pem&keyfile=/path/to/keyfile.pem&verify=verifyOption&fail_if_no_peer_cert=failOption
   152 
   153 All five parameters (3 paths: cacertfile, certfile and keyfile; 2
   154 options: verify, fail_if_no_peer_cert) must be specified. See the SSL
   155 guide at http://www.rabbitmq.com/ssl.html#configure-erlang for details
   156 of SSL in RabbitMQ in general and specifically for the Erlang client
   157 (on which the shovel is built).
   158 
   159 Note that SSL cannot be used with the direct connection (i.e. a host
   160 must be specified when using SSL), and that it is preferable to use
   161 the non-SSL direct connection when connecting to the same node that's
   162 running the shovel.
   163 
   164 
   165 Resource Declarations
   166 ---------------------
   167 
   168 Both sources and destinations can have an optional 'declarations'
   169 clause. The value of this is a list, consisting of AMQP Methods. If
   170 default values are sufficient, then the method name alone can be
   171 specified - e.g. 'queue.declare'. If parameters need to be set then
   172 the method should be given as a tuple, with the right hand side a
   173 proplist specifying which fields need altering from their default
   174 values. E.g:
   175     {'exchange.declare',[{exchange, <<"my_exchange">>},
   176                          {type, <<"direct">>},
   177                          durable]},
   178 
   179 One very useful feature here is the Most-Recently-Declared-Queue
   180 feature, in which RabbitMQ remembers the name of the most recently
   181 declared queue. This means that you can declare a private queue, and
   182 then bind it to exchanges without ever needing to know its name.
   183 
   184 
   185 queue :: binary
   186 ---------------
   187 
   188 This parameter specifies the name of the queue on the source brokers
   189 to consume from. This queue must exist. Use the resource declarations
   190 to create the queue (or ensure it exists) first. Note again that the
   191 Most-Recently-Declared-Queue feature can be used here, thus an
   192 anonymous queue can be used: use <<>> to indicate the
   193 Most-Recently-Declared-Queue.
   194 
   195 
   196 prefetch_count :: non-negative-integer
   197 --------------------------------------
   198 
   199 The shovel consumes from a queue. This parameter imposes a limit on
   200 the number of messages which are sent to the shovel in advance of the
   201 message the shovel is currently processing.
   202 
   203 
   204 auto_ack :: boolean
   205 -------------------
   206 
   207 Setting this to 'true' turns on the no_ack flag when subscribing to
   208 the source queue.
   209 
   210 
   211 tx_size :: non-negative-integer
   212 -------------------------------
   213 
   214 When set to 0, transactions are not used. Other values make publishes
   215 transactional, with a commit every N messages. In lieu of the auto-ack
   216 option, when transactions are not used, messages are acknowledged to
   217 the source immediately after every publish. When transactions are
   218 used, acks are only issued to the source on receipt of the commit-ok
   219 message from the destination. This can thus be used to guarantee that
   220 messages are only acknowledged (and thus forgotten about by the source
   221 broker) when they are guaranteed to have been received by the
   222 destination broker.
   223 
   224 
   225 publish_properties
   226 ------------------
   227 
   228 This is a list of tuples which override fields in the basic class
   229 properties when publishing to the destination. This can be used to
   230 override any of the following fields: content_type, content_encoding,
   231 headers, delivery_mode, priority, correlation_id, reply_to,
   232 expiration, message_id, timestamp, type, user_id, app_id, cluster_id.
   233 
   234 By default, all the properties of the basic class that are received
   235 with the delivery are passed through to the destination, but this
   236 field can be used to override them.
   237 
   238 
   239 publish_fields
   240 --------------
   241 
   242 This is a list of tuples which override fields in the publish method
   243 when publishing to the destination. This can be used to direct
   244 messages to a particular exchange on the destination, for example, or
   245 change the routing key. By default, the exchange and the routing key
   246 of the message as it is received by the shovel is passed through, but
   247 this can be overridden as necessary.
   248 
   249 
   250 reconnect_delay :: non-negative-number
   251 --------------------------------------
   252 
   253 When an error occurs, the shovel will disconnect from both the source
   254 and destination broker immediately. This will force uncommitted
   255 transactions at the destination to be rolled back, and delivered but
   256 unacknowledged messages from the source to be requeued. The shovel
   257 will then try connecting again. If this is unsuccessful, then it's not
   258 a good idea for the shovel to very quickly and repeatedly try to
   259 reconnect. The value specified here is determines the delay, in
   260 seconds, between each connection attempt.
   261 
   262 Note that if set to 0, the shovel will never try to reconnect: it'll
   263 stop after the first error.
   264 
   265 Also, the value can be a floating point number, thus permitting the
   266 specification of delays at a granularity smaller than whole seconds.
   267 
   268 
   269 Obtaining shovel statuses
   270 -------------------------
   271 
   272 From the broker Erlang prompt, call
   273 rabbit_shovel_status:status(). This will return a list, with one row
   274 for each configured shovel. Each row has three fields: the shovel
   275 name, the shovel status, and the timestamp (a local calendar time of
   276 {{YYYY,MM,DD},{HH,MM,SS}}). There are 3 possible statuses:
   277 
   278 'starting': The shovel is starting up, connecting and creating
   279     resources.
   280 
   281 {'running'|'blocked', {'source', Source},
   282                       {'destination', Destination}}:
   283 
   284     When 'running', the shovel is up and running, shovelling
   285     messages. When 'blocked', the destination has raised channel.flow,
   286     preventing the shovel from sending messages to the
   287     destination. The shovel will raise channel.flow to the source,
   288     asking the source to stop sending further messages to the
   289     shovel. Any messages that are received by the shovel before the
   290     source observes the channel.flow are correctly buffered and
   291     maintained in order, and are published to the destination as soon
   292     as the destination drops the channel.flow block.
   293 
   294     Source and Destination give the connection parameters used to
   295     connect to the endpoints.
   296 
   297 {'terminated', Reason}: Something's gone wrong. The Reason should give
   298     a further indication of where the fault lies.