Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
comb:rabbitmq [2014/07/15 10:26] alfred [Message acknowledgment and persistent queues] |
comb:rabbitmq [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 34: | Línea 34: | ||
| $ sudo rabbitmqctl list_bindings | $ sudo rabbitmqctl list_bindings | ||
| </code> | </code> | ||
| - | ==== Exchanges ==== | + | ==== Concepts ==== |
| - | A producer can only send messages to an exchange. It receives messages from producers and it pushes them to queues. | + | === Exchanges === |
| + | A producer can only send messages to an exchange. The exchange receives messages from producers and it pushes them to queues. | ||
| * direct | * direct | ||
| * topic | * topic | ||
| Línea 41: | Línea 42: | ||
| * fanout: it broadcasts all the messages it receives to all the queues it knows. | * fanout: it broadcasts all the messages it receives to all the queues it knows. | ||
| - | Some amq.* exchanges and the default (unnamed) exchange are created by default, but it is unlikely you'll need to use them at the moment. We identify the default exchange by the empty string. | + | Some amq.* exchanges and the default (unnamed) exchange are created by default, we identify the default exchange by the empty string. |
| + | To declare an exchange it's used: | ||
| + | <code python> | ||
| + | channel.exchange_declare(exchange='logs', type='fanout') | ||
| + | </code> | ||
| + | === Bindings === | ||
| + | The relationship between exchange and a queue is called a binding. | ||
| + | <code python> | ||
| + | channel.queue_bind(exchange='logs', queue=result.method.queue) | ||
| + | </code> | ||
| + | === Temporary queues === | ||
| + | Whe we want to hear about all messages and not just a subset of them. We need to connect to Rabbit with an empty queue. To do it we could let the server choose a random queue name for us. We can do this by not supplying the queue parameter to queue_declare: | ||
| + | <code python> | ||
| + | result = channel.queue_declare() | ||
| + | </code> | ||
| + | Also we need that once we disconnect the consumer the queue should be deleted. There's an exclusive flag for that: | ||
| + | <code python> | ||
| + | result = channel.queue_declare(exclusive=True) | ||
| + | </code> | ||
| ===== Use ===== | ===== Use ===== | ||
| ==== Producer & consumer ==== | ==== Producer & consumer ==== | ||
| Línea 131: | Línea 150: | ||
| </code> | </code> | ||
| - | ===== Publish\Subscriber ===== | + | ==== Publish\Subscriber ==== |
| - | * | + | |
| <code python> | <code python> | ||
| Línea 169: | Línea 187: | ||
| print " [x] Sent %r" % (message,) | print " [x] Sent %r" % (message,) | ||
| connection.close() | connection.close() | ||
| + | </code> | ||
| + | ===== Others ===== | ||
| + | ==== Plugins ==== | ||
| + | === Management === | ||
| + | <code> | ||
| + | $ rabbitmq-plugins enable rabbitmq_management | ||
| + | </code> | ||
| + | Will enable the web management server. You'll find at: [[http://server:15672]] (p.eg. [[http://127.0.0.1:15672/]]). Username ''guest'' and password ''guest'' is the authentication by default. | ||
| + | |||
| + | Para añadir usuarios: | ||
| + | |||
| + | - you need to create a user for any vhost on that system (here I use default vhost "/") | ||
| + | <code> | ||
| + | $ rabbitmqctl add_user yourName yourPass | ||
| + | </code> | ||
| + | - Set the permissions for that user for default vhost | ||
| + | <code> | ||
| + | $ rabbitmqctl set_permissions -p / yourName ".*" ".*" ".*" | ||
| + | </code> | ||
| + | - Set the administrator tag for this user (to enable him access the management pluggin) | ||
| + | <code> | ||
| + | $ rabbitmqctl set_user_tags yourName administrator | ||
| + | </code> | ||
| + | ==== Notes ==== | ||
| + | === Reset RabbitMQ === | ||
| + | ... Queues, config, everything! | ||
| + | <code> | ||
| + | $ rabbitmqctl stop_app | ||
| + | $ rabbitmqctl reset | ||
| + | $ rabbitmqctl start_app | ||
| </code> | </code> | ||