@lornajane QUEUES WITH RABBITMQ Lorna Mitchell, IBM Cloud Data Services PHPNW, September 2016 (slides are available: ) http://lornajane.net/resources 1
@lornajane WHY USE RABBITMQ? Homepage: Open source, uses AMQP standard. Scalable, robust and written in Erlang. Alternatives could be: Gearman Beanstalkd A lot of the theory applies regardless https://www.rabbitmq.com/ 3
@lornajane RABBITMQ CHANNELS When we want to talk to RabbitMQ, we establish a channel Channels allow multiple connections between servers over a single TCP connection, but each is isolated from the others. 5
@lornajane DECLARING THE QUEUE We declare a queue before we write to it. if it doesn't exist, it is created if it does exist, cool to check if a queue exists but not create it, use passive mode Our example uses the default exchange, more on exchanges in a bit 6
@lornajane WRITING WORKERS Workers are long-running processes, beware scope issues and memory leaks. There can be many workers attached to one queue, each one independent. They need to be robust and handle failures. 13
@lornajane HANDLING FAILURE: RETRIES Implement your own logic to handle retries Create a new message with: all the existing message contents plus some metadata such as retry count or backoff time 16
@lornajane RABBITMQ EXCHANGES Exchanges are the routing logic of RabbitMQ Messages go to exchanges and the exchanges put them into the correct queues for storage (our first example used the empty-named default exchange) 17
@lornajane TYPES OF EXCHANGE Direct: a given routing key puts messages onto the matching queue(s) Topic: queues are bound by key, and messages are routed to as many queues as their routing key matches Fanout: messages go to all queues bound to this exchange 18
@lornajane FEEDBACK MECHANISMS Rabbit is fire-and-forget; work is delegated Common pattern: return queue to put updates into for the original producer then to consume. 27
@lornajane QUEUES WITH RABBITMQ Queues are awesome for scalability and robustness RabbitMQ is open source, lightweight and fast Queues help us meet the requirements for modern applications 29