+ All Categories
Home > Technology > Integrating php withrabbitmq_zendcon

Integrating php withrabbitmq_zendcon

Date post: 08-May-2015
Category:
Upload: alvaro-videla
View: 40,761 times
Download: 3 times
Share this document with a friend
Description:
Talk given at Zendcon showing how to implement several messaging patterns with RabbitMQ and PHP
124
Integrating PHP With RabbitMQ Álvaro Videla | The NetCircle Zendcon 2010 Tuesday, November 2, 2010
Transcript
Page 1: Integrating php withrabbitmq_zendcon

Integrating PHPWith RabbitMQ

Álvaro Videla | The NetCircle

Zendcon 2010

Tuesday, November 2, 2010

Page 2: Integrating php withrabbitmq_zendcon

Who?

Tuesday, November 2, 2010

Page 3: Integrating php withrabbitmq_zendcon

About Me

• Development Manager at TheNetCircle.com

• Writing “RabbitMQ in Action” for Manning

• Blog: http://videlalvaro.github.com/

• Twitter: @old_sound

Tuesday, November 2, 2010

Page 4: Integrating php withrabbitmq_zendcon

Why Do I need RabbitMQ?

Tuesday, November 2, 2010

Page 5: Integrating php withrabbitmq_zendcon

The User

Tuesday, November 2, 2010

Page 6: Integrating php withrabbitmq_zendcon

I don’t want to waittill your app resizes

my image!

Tuesday, November 2, 2010

Page 7: Integrating php withrabbitmq_zendcon

The Product Owner

Tuesday, November 2, 2010

Page 8: Integrating php withrabbitmq_zendcon

Can we also notify the user friends when she uploads a new image?

Tuesday, November 2, 2010

Page 9: Integrating php withrabbitmq_zendcon

Can we also notify the user friends when she uploads a new image?

I forgot to mention we need it for tomorrow…

Tuesday, November 2, 2010

Page 10: Integrating php withrabbitmq_zendcon

The Sysadmin

Tuesday, November 2, 2010

Page 11: Integrating php withrabbitmq_zendcon

Dumb! You’re delivering full size images!

The bandwidth bill has tripled!

Tuesday, November 2, 2010

Page 12: Integrating php withrabbitmq_zendcon

Dumb! You’re delivering full size images!

The bandwidth bill has tripled!

We need this fixed for yesterday!

Tuesday, November 2, 2010

Page 13: Integrating php withrabbitmq_zendcon

The Developer in the other team

Tuesday, November 2, 2010

Page 14: Integrating php withrabbitmq_zendcon

I need to call your PHP stuff but from Python

Tuesday, November 2, 2010

Page 15: Integrating php withrabbitmq_zendcon

I need to call your PHP stuff but from Python

And also Java starting next week

Tuesday, November 2, 2010

Page 16: Integrating php withrabbitmq_zendcon

You

Tuesday, November 2, 2010

Page 17: Integrating php withrabbitmq_zendcon

FML!

Tuesday, November 2, 2010

Page 18: Integrating php withrabbitmq_zendcon

Is there a solution?

Tuesday, November 2, 2010

Page 19: Integrating php withrabbitmq_zendcon

RabbitMQ & AMQP

Tuesday, November 2, 2010

Page 20: Integrating php withrabbitmq_zendcon

AMQP

Tuesday, November 2, 2010

Page 21: Integrating php withrabbitmq_zendcon

AMQP

• Advanced Message Queuing Protocol

• Suits Interoperability

• Completely Open Protocol

• Binary Protocol

• AMQP Model

• AMQP Wire Format

Tuesday, November 2, 2010

Page 22: Integrating php withrabbitmq_zendcon

AMQP Model

• Exchanges

• Message Queues

• Bindings

• Rules for binding them

Tuesday, November 2, 2010

Page 23: Integrating php withrabbitmq_zendcon

AMQP Wire Protocol

• Functional Layer

• Transport Layer

Tuesday, November 2, 2010

Page 24: Integrating php withrabbitmq_zendcon

Message Flow

http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/chap-Messaging_Tutorial-Initial_Concepts.html

Tuesday, November 2, 2010

Page 25: Integrating php withrabbitmq_zendcon

Exchange Types

• Fanout

• Direct

• Topic

Tuesday, November 2, 2010

Page 29: Integrating php withrabbitmq_zendcon

Usage Scenarios

Tuesday, November 2, 2010

Page 30: Integrating php withrabbitmq_zendcon

Usage Scenarios

• Batch Processing

Tuesday, November 2, 2010

Page 31: Integrating php withrabbitmq_zendcon

Usage Scenarios

• Batch Processing

• Image Uploading

Tuesday, November 2, 2010

Page 32: Integrating php withrabbitmq_zendcon

Usage Scenarios

• Batch Processing

• Image Uploading

• Distributed Logging

Tuesday, November 2, 2010

Page 33: Integrating php withrabbitmq_zendcon

Scenario

Batch Processing

Tuesday, November 2, 2010

Page 34: Integrating php withrabbitmq_zendcon

Requirements

Tuesday, November 2, 2010

Page 35: Integrating php withrabbitmq_zendcon

Requirements

• Generate XML

Tuesday, November 2, 2010

Page 36: Integrating php withrabbitmq_zendcon

Requirements

• Generate XML

• Distribution Over a Cluster

Tuesday, November 2, 2010

Page 37: Integrating php withrabbitmq_zendcon

Requirements

• Generate XML

• Distribution Over a Cluster

• Elasticity - Add/Remove new workers

Tuesday, November 2, 2010

Page 38: Integrating php withrabbitmq_zendcon

Requirements

• Generate XML

• Distribution Over a Cluster

• Elasticity - Add/Remove new workers

• No Code Changes

Tuesday, November 2, 2010

Page 39: Integrating php withrabbitmq_zendcon

Design

Tuesday, November 2, 2010

Page 40: Integrating php withrabbitmq_zendcon

Publisher Code

$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);$channel = $conn->channel();

$channel->exchange_declare('video-desc-ex', 'direct', false, true, false);

$msg = new AMQPMessage($video_info, array('content_type' => 'text/plain',

'delivery_mode' => 2));

$channel->basic_publish($msg, 'video-desc-ex');

$channel->close();$conn->close();

Tuesday, November 2, 2010

Page 41: Integrating php withrabbitmq_zendcon

Publisher Code

$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);$channel = $conn->channel();

$channel->exchange_declare('video-desc-ex', 'direct', false, true, false);

$msg = new AMQPMessage($video_info, array('content_type' => 'text/plain',

'delivery_mode' => 2));

$channel->basic_publish($msg, 'video-desc-ex');

$channel->close();$conn->close();

Tuesday, November 2, 2010

Page 42: Integrating php withrabbitmq_zendcon

Publisher Code

$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);$channel = $conn->channel();

$channel->exchange_declare('video-desc-ex', 'direct', false, true, false);

$msg = new AMQPMessage($video_info, array('content_type' => 'text/plain',

'delivery_mode' => 2));

$channel->basic_publish($msg, 'video-desc-ex');

$channel->close();$conn->close();

Tuesday, November 2, 2010

Page 43: Integrating php withrabbitmq_zendcon

Publisher Code

$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);$channel = $conn->channel();

$channel->exchange_declare('video-desc-ex', 'direct', false, true, false);

$msg = new AMQPMessage($video_info, array('content_type' => 'text/plain',

'delivery_mode' => 2));

$channel->basic_publish($msg, 'video-desc-ex');

$channel->close();$conn->close();

Tuesday, November 2, 2010

Page 44: Integrating php withrabbitmq_zendcon

Publisher Code

$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);$channel = $conn->channel();

$channel->exchange_declare('video-desc-ex', 'direct', false, true, false);

$msg = new AMQPMessage($video_info, array('content_type' => 'text/plain',

'delivery_mode' => 2));

$channel->basic_publish($msg, 'video-desc-ex');

$channel->close();$conn->close();

Tuesday, November 2, 2010

Page 45: Integrating php withrabbitmq_zendcon

Publisher Code

$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);$channel = $conn->channel();

$channel->exchange_declare('video-desc-ex', 'direct', false, true, false);

$msg = new AMQPMessage($video_info, array('content_type' => 'text/plain',

'delivery_mode' => 2));

$channel->basic_publish($msg, 'video-desc-ex');

$channel->close();$conn->close();

Tuesday, November 2, 2010

Page 46: Integrating php withrabbitmq_zendcon

Consumer Code

$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);$channel = $conn->channel();

$channel->exchange_declare('video-desc-ex', 'direct', false, true, false);

$channel->queue_declare('video-desc-queue', false, true, false, false);

$channel->queue_bind('video-desc-queue', 'video-desc-ex');

$channel->basic_consume('video-desc-queue', $consumer_tag, false, false, false, false, $consumer);

while(count($channel->callbacks)) { $channel->wait();}

Tuesday, November 2, 2010

Page 47: Integrating php withrabbitmq_zendcon

Consumer Code

$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);$channel = $conn->channel();

$channel->exchange_declare('video-desc-ex', 'direct', false, true, false);

$channel->queue_declare('video-desc-queue', false, true, false, false);

$channel->queue_bind('video-desc-queue', 'video-desc-ex');

$channel->basic_consume('video-desc-queue', $consumer_tag, false, false, false, false, $consumer);

while(count($channel->callbacks)) { $channel->wait();}

Tuesday, November 2, 2010

Page 48: Integrating php withrabbitmq_zendcon

Consumer Code

$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);$channel = $conn->channel();

$channel->exchange_declare('video-desc-ex', 'direct', false, true, false);

$channel->queue_declare('video-desc-queue', false, true, false, false);

$channel->queue_bind('video-desc-queue', 'video-desc-ex');

$channel->basic_consume('video-desc-queue', $consumer_tag, false, false, false, false, $consumer);

while(count($channel->callbacks)) { $channel->wait();}

Tuesday, November 2, 2010

Page 49: Integrating php withrabbitmq_zendcon

Consumer Code

$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);$channel = $conn->channel();

$channel->exchange_declare('video-desc-ex', 'direct', false, true, false);

$channel->queue_declare('video-desc-queue', false, true, false, false);

$channel->queue_bind('video-desc-queue', 'video-desc-ex');

$channel->basic_consume('video-desc-queue', $consumer_tag, false, false, false, false, $consumer);

while(count($channel->callbacks)) { $channel->wait();}

Tuesday, November 2, 2010

Page 50: Integrating php withrabbitmq_zendcon

Consumer Code

$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);$channel = $conn->channel();

$channel->exchange_declare('video-desc-ex', 'direct', false, true, false);

$channel->queue_declare('video-desc-queue', false, true, false, false);

$channel->queue_bind('video-desc-queue', 'video-desc-ex');

$channel->basic_consume('video-desc-queue', $consumer_tag, false, false, false, false, $consumer);

while(count($channel->callbacks)) { $channel->wait();}

Tuesday, November 2, 2010

Page 51: Integrating php withrabbitmq_zendcon

Consumer Code

$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);$channel = $conn->channel();

$channel->exchange_declare('video-desc-ex', 'direct', false, true, false);

$channel->queue_declare('video-desc-queue', false, true, false, false);

$channel->queue_bind('video-desc-queue', 'video-desc-ex');

$channel->basic_consume('video-desc-queue', $consumer_tag, false, false, false, false, $consumer);

while(count($channel->callbacks)) { $channel->wait();}

Tuesday, November 2, 2010

Page 52: Integrating php withrabbitmq_zendcon

Consumer Code

$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);$channel = $conn->channel();

$channel->exchange_declare('video-desc-ex', 'direct', false, true, false);

$channel->queue_declare('video-desc-queue', false, true, false, false);

$channel->queue_bind('video-desc-queue', 'video-desc-ex');

$channel->basic_consume('video-desc-queue', $consumer_tag, false, false, false, false, $consumer);

while(count($channel->callbacks)) { $channel->wait();}

Tuesday, November 2, 2010

Page 53: Integrating php withrabbitmq_zendcon

Scenario

Upload Pictures

Tuesday, November 2, 2010

Page 54: Integrating php withrabbitmq_zendcon

Requirements

Tuesday, November 2, 2010

Page 55: Integrating php withrabbitmq_zendcon

Requirements

• Upload Picture

Tuesday, November 2, 2010

Page 56: Integrating php withrabbitmq_zendcon

Requirements

• Upload Picture

• Reward User

Tuesday, November 2, 2010

Page 57: Integrating php withrabbitmq_zendcon

Requirements

• Upload Picture

• Reward User

• Notify User Friends

Tuesday, November 2, 2010

Page 58: Integrating php withrabbitmq_zendcon

Requirements

• Upload Picture

• Reward User

• Notify User Friends

• Resize Picture

Tuesday, November 2, 2010

Page 59: Integrating php withrabbitmq_zendcon

Requirements

• Upload Picture

• Reward User

• Notify User Friends

• Resize Picture

• No Code Changes

Tuesday, November 2, 2010

Page 60: Integrating php withrabbitmq_zendcon

Design

Tuesday, November 2, 2010

Page 61: Integrating php withrabbitmq_zendcon

Design

Tuesday, November 2, 2010

Page 62: Integrating php withrabbitmq_zendcon

Design

Tuesday, November 2, 2010

Page 63: Integrating php withrabbitmq_zendcon

Publisher Code$channel->exchange_declare('upload-pictures', 'fanout', false, true, false);

$metadata = json_encode(array('image_id' => $image_id,'user_id' => $user_id,‘image_path' => $image_path));

$msg = new AMQPMessage($metadata, array('content_type' => 'application/json', 'delivery_mode' => 2));

$channel->basic_publish($msg, 'upload-pictures');

Tuesday, November 2, 2010

Page 64: Integrating php withrabbitmq_zendcon

Publisher Code$channel->exchange_declare('upload-pictures', 'fanout', false, true, false);

$metadata = json_encode(array('image_id' => $image_id,'user_id' => $user_id,‘image_path' => $image_path));

$msg = new AMQPMessage($metadata, array('content_type' => 'application/json', 'delivery_mode' => 2));

$channel->basic_publish($msg, 'upload-pictures');

Tuesday, November 2, 2010

Page 65: Integrating php withrabbitmq_zendcon

Publisher Code$channel->exchange_declare('upload-pictures', 'fanout', false, true, false);

$metadata = json_encode(array('image_id' => $image_id,'user_id' => $user_id,‘image_path' => $image_path));

$msg = new AMQPMessage($metadata, array('content_type' => 'application/json', 'delivery_mode' => 2));

$channel->basic_publish($msg, 'upload-pictures');

Tuesday, November 2, 2010

Page 66: Integrating php withrabbitmq_zendcon

Publisher Code$channel->exchange_declare('upload-pictures', 'fanout', false, true, false);

$metadata = json_encode(array('image_id' => $image_id,'user_id' => $user_id,‘image_path' => $image_path));

$msg = new AMQPMessage($metadata, array('content_type' => 'application/json', 'delivery_mode' => 2));

$channel->basic_publish($msg, 'upload-pictures');

Tuesday, November 2, 2010

Page 67: Integrating php withrabbitmq_zendcon

Publisher Code$channel->exchange_declare('upload-pictures', 'fanout', false, true, false);

$metadata = json_encode(array('image_id' => $image_id,'user_id' => $user_id,‘image_path' => $image_path));

$msg = new AMQPMessage($metadata, array('content_type' => 'application/json', 'delivery_mode' => 2));

$channel->basic_publish($msg, 'upload-pictures');

Tuesday, November 2, 2010

Page 68: Integrating php withrabbitmq_zendcon

Consumer Code$channel->exchange_declare('upload-pictures', 'fanout',

false, true, false);

$channel->queue_declare('resize-picture', false, true, false, false);

$channel->queue_bind('resize-picture', 'upload-pictures');

$channel->basic_consume('resize-picture', $consumer_tag, false, false, false, false, $consumer);

while(count($channel->callbacks)) {$channel->wait();

}

Tuesday, November 2, 2010

Page 69: Integrating php withrabbitmq_zendcon

Consumer Code$channel->exchange_declare('upload-pictures', 'fanout',

false, true, false);

$channel->queue_declare('resize-picture', false, true, false, false);

$channel->queue_bind('resize-picture', 'upload-pictures');

$channel->basic_consume('resize-picture', $consumer_tag, false, false, false, false, $consumer);

while(count($channel->callbacks)) {$channel->wait();

}

Tuesday, November 2, 2010

Page 70: Integrating php withrabbitmq_zendcon

Consumer Code$channel->exchange_declare('upload-pictures', 'fanout',

false, true, false);

$channel->queue_declare('resize-picture', false, true, false, false);

$channel->queue_bind('resize-picture', 'upload-pictures');

$channel->basic_consume('resize-picture', $consumer_tag, false, false, false, false, $consumer);

while(count($channel->callbacks)) {$channel->wait();

}

Tuesday, November 2, 2010

Page 71: Integrating php withrabbitmq_zendcon

Consumer Code$channel->exchange_declare('upload-pictures', 'fanout',

false, true, false);

$channel->queue_declare('resize-picture', false, true, false, false);

$channel->queue_bind('resize-picture', 'upload-pictures');

$channel->basic_consume('resize-picture', $consumer_tag, false, false, false, false, $consumer);

while(count($channel->callbacks)) {$channel->wait();

}

Tuesday, November 2, 2010

Page 72: Integrating php withrabbitmq_zendcon

Consumer Code$channel->exchange_declare('upload-pictures', 'fanout',

false, true, false);

$channel->queue_declare('resize-picture', false, true, false, false);

$channel->queue_bind('resize-picture', 'upload-pictures');

$channel->basic_consume('resize-picture', $consumer_tag, false, false, false, false, $consumer);

while(count($channel->callbacks)) {$channel->wait();

}

Tuesday, November 2, 2010

Page 73: Integrating php withrabbitmq_zendcon

Consumer Code$channel->exchange_declare('upload-pictures', 'fanout',

false, true, false);

$channel->queue_declare('resize-picture', false, true, false, false);

$channel->queue_bind('resize-picture', 'upload-pictures');

$channel->basic_consume('resize-picture', $consumer_tag, false, false, false, false, $consumer);

while(count($channel->callbacks)) {$channel->wait();

}

Tuesday, November 2, 2010

Page 74: Integrating php withrabbitmq_zendcon

Consumer Code

$consumer = function($msg){

$meta = json_decode($msg->body, true);

resize_picture($meta['image_id'], $meta['image_path']);

$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);

};

Tuesday, November 2, 2010

Page 75: Integrating php withrabbitmq_zendcon

Consumer Code

$consumer = function($msg){

$meta = json_decode($msg->body, true);

resize_picture($meta['image_id'], $meta['image_path']);

$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);

};

Tuesday, November 2, 2010

Page 76: Integrating php withrabbitmq_zendcon

Consumer Code

$consumer = function($msg){

$meta = json_decode($msg->body, true);

resize_picture($meta['image_id'], $meta['image_path']);

$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);

};

Tuesday, November 2, 2010

Page 77: Integrating php withrabbitmq_zendcon

Consumer Code

$consumer = function($msg){

$meta = json_decode($msg->body, true);

resize_picture($meta['image_id'], $meta['image_path']);

$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);

};

Tuesday, November 2, 2010

Page 78: Integrating php withrabbitmq_zendcon

Consumer Code

$consumer = function($msg){

$meta = json_decode($msg->body, true);

resize_picture($meta['image_id'], $meta['image_path']);

$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);

};

Tuesday, November 2, 2010

Page 79: Integrating php withrabbitmq_zendcon

Scenario

Distributed Logging

Tuesday, November 2, 2010

Page 80: Integrating php withrabbitmq_zendcon

Requirements

Tuesday, November 2, 2010

Page 81: Integrating php withrabbitmq_zendcon

Requirements

• Several Web Servers

Tuesday, November 2, 2010

Page 82: Integrating php withrabbitmq_zendcon

Requirements

• Several Web Servers

• Logic Separated by Module/Action

Tuesday, November 2, 2010

Page 83: Integrating php withrabbitmq_zendcon

Requirements

• Several Web Servers

• Logic Separated by Module/Action

• Several Log Levels:

Tuesday, November 2, 2010

Page 84: Integrating php withrabbitmq_zendcon

Requirements

• Several Web Servers

• Logic Separated by Module/Action

• Several Log Levels:

• Info, Warning, Error

Tuesday, November 2, 2010

Page 85: Integrating php withrabbitmq_zendcon

Requirements

• Several Web Servers

• Logic Separated by Module/Action

• Several Log Levels:

• Info, Warning, Error

• Add/Remove log listeners at will

Tuesday, November 2, 2010

Page 86: Integrating php withrabbitmq_zendcon

Design

Tuesday, November 2, 2010

Page 87: Integrating php withrabbitmq_zendcon

Design

Tuesday, November 2, 2010

Page 88: Integrating php withrabbitmq_zendcon

Design

Tuesday, November 2, 2010

Page 89: Integrating php withrabbitmq_zendcon

Design

Tuesday, November 2, 2010

Page 90: Integrating php withrabbitmq_zendcon

Design

Tuesday, November 2, 2010

Page 91: Integrating php withrabbitmq_zendcon

Publisher Code

$channel->exchange_declare('logs', 'topic', false, true, false);

$msg = new AMQPMessage('some log message',array('content_type' => 'text/plain'));

$channel->basic_publish($msg, 'logs', server1.user.profile.info');

Tuesday, November 2, 2010

Page 92: Integrating php withrabbitmq_zendcon

Publisher Code

$channel->exchange_declare('logs', 'topic', false, true, false);

$msg = new AMQPMessage('some log message',array('content_type' => 'text/plain'));

$channel->basic_publish($msg, 'logs', server1.user.profile.info');

Tuesday, November 2, 2010

Page 93: Integrating php withrabbitmq_zendcon

Publisher Code

$channel->exchange_declare('logs', 'topic', false, true, false);

$msg = new AMQPMessage('some log message',array('content_type' => 'text/plain'));

$channel->basic_publish($msg, 'logs', server1.user.profile.info');

Tuesday, November 2, 2010

Page 94: Integrating php withrabbitmq_zendcon

Publisher Code

$channel->exchange_declare('logs', 'topic', false, true, false);

$msg = new AMQPMessage('some log message',array('content_type' => 'text/plain'));

$channel->basic_publish($msg, 'logs', server1.user.profile.info');

Tuesday, November 2, 2010

Page 95: Integrating php withrabbitmq_zendcon

Consumer Code

Get messages sent by host:

server1

Tuesday, November 2, 2010

Page 96: Integrating php withrabbitmq_zendcon

Consumer Code

$channel->exchange_declare('logs', 'topic', false, true, false);

$channel->queue_declare('server1-logs', false, true, false, false);

$channel->queue_bind('server1-logs', 'logs', 'server1.#');

Tuesday, November 2, 2010

Page 97: Integrating php withrabbitmq_zendcon

Consumer Code

$channel->exchange_declare('logs', 'topic', false, true, false);

$channel->queue_declare('server1-logs', false, true, false, false);

$channel->queue_bind('server1-logs', 'logs', 'server1.#');

Tuesday, November 2, 2010

Page 98: Integrating php withrabbitmq_zendcon

Consumer Code

$channel->exchange_declare('logs', 'topic', false, true, false);

$channel->queue_declare('server1-logs', false, true, false, false);

$channel->queue_bind('server1-logs', 'logs', 'server1.#');

Tuesday, November 2, 2010

Page 99: Integrating php withrabbitmq_zendcon

Consumer Code

$channel->exchange_declare('logs', 'topic', false, true, false);

$channel->queue_declare('server1-logs', false, true, false, false);

$channel->queue_bind('server1-logs', 'logs', 'server1.#');

Tuesday, November 2, 2010

Page 100: Integrating php withrabbitmq_zendcon

Consumer Code

Get all error messages

Tuesday, November 2, 2010

Page 101: Integrating php withrabbitmq_zendcon

Consumer Code

$channel->exchange_declare('logs', 'topic', false, true, false);

$channel->queue_declare('error-logs', false, true, false, false);

$channel->queue_bind('error-logs', 'logs', '#.error');

Tuesday, November 2, 2010

Page 102: Integrating php withrabbitmq_zendcon

Consumer Code

$channel->exchange_declare('logs', 'topic', false, true, false);

$channel->queue_declare('error-logs', false, true, false, false);

$channel->queue_bind('error-logs', 'logs', '#.error');

Tuesday, November 2, 2010

Page 103: Integrating php withrabbitmq_zendcon

Consumer Code

$channel->exchange_declare('logs', 'topic', false, true, false);

$channel->queue_declare('error-logs', false, true, false, false);

$channel->queue_bind('error-logs', 'logs', '#.error');

Tuesday, November 2, 2010

Page 104: Integrating php withrabbitmq_zendcon

Consumer Code

$channel->exchange_declare('logs', 'topic', false, true, false);

$channel->queue_declare('error-logs', false, true, false, false);

$channel->queue_bind('error-logs', 'logs', '#.error');

Tuesday, November 2, 2010

Page 105: Integrating php withrabbitmq_zendcon

PHP Integration

Tuesday, November 2, 2010

Page 106: Integrating php withrabbitmq_zendcon

php-amqplib

• http://github.com/tnc/php-amqplib

Tuesday, November 2, 2010

Page 108: Integrating php withrabbitmq_zendcon

php-amqplib

• http://github.com/tnc/php-amqplib

• Fork of http://code.google.com/p/php-amqplib/

• PHP 5.3 Compatible

Tuesday, November 2, 2010

Page 109: Integrating php withrabbitmq_zendcon

php-amqplib

• http://github.com/tnc/php-amqplib

• Fork of http://code.google.com/p/php-amqplib/

• PHP 5.3 Compatible

• Improved performance

Tuesday, November 2, 2010

Page 110: Integrating php withrabbitmq_zendcon

php-amqplib

• http://github.com/tnc/php-amqplib

• Fork of http://code.google.com/p/php-amqplib/

• PHP 5.3 Compatible

• Improved performance

• Used in production one+ year

Tuesday, November 2, 2010

Page 111: Integrating php withrabbitmq_zendcon

php-amqplib

$ git clone http://github.com/tnc/php-amqplib.git

<?php

require_once('./php-amqplib/amqp.inc');

$conn = new AMQPConnection(‘localhost’, 5672, guest, guest);

$channel = $conn->channel();

?>

Tuesday, November 2, 2010

Page 112: Integrating php withrabbitmq_zendcon

Why RabbitMQ?

Tuesday, November 2, 2010

Page 113: Integrating php withrabbitmq_zendcon

RabbitMQ

• Enterprise Messaging System

• Open Source MPL

• Written in Erlang/OTP

• Commercial Support

Tuesday, November 2, 2010

Page 114: Integrating php withrabbitmq_zendcon

Features

• Reliable and High Scalable

• Easy To install

• Easy To Cluster

• Runs on: Windows, Solaris, Linux, OSX

• AMQP 0.8 - 0.9.1

Tuesday, November 2, 2010

Page 115: Integrating php withrabbitmq_zendcon

Client Libraries

• Java

• .NET/C#

• Erlang

• Ruby, Python, PHP, Perl, AS3, Lisp, Scala, Clojure, Haskell

Tuesday, November 2, 2010

Page 116: Integrating php withrabbitmq_zendcon

Docs/Support

• http://www.rabbitmq.com/documentation.html

• http://dev.rabbitmq.com/wiki/

• #rabbitmq at irc.freenode.net

• http://www.rabbitmq.com/email-archive.html

Tuesday, November 2, 2010

Page 117: Integrating php withrabbitmq_zendcon

One Setup for HA

Tuesday, November 2, 2010

Page 118: Integrating php withrabbitmq_zendcon

Conclusion

Tuesday, November 2, 2010

Page 119: Integrating php withrabbitmq_zendcon

Conclusion

• Flexibility

Tuesday, November 2, 2010

Page 120: Integrating php withrabbitmq_zendcon

Conclusion

• Flexibility

• Scalability

Tuesday, November 2, 2010

Page 121: Integrating php withrabbitmq_zendcon

Conclusion

• Flexibility

• Scalability

• Interoperability

Tuesday, November 2, 2010

Page 122: Integrating php withrabbitmq_zendcon

Conclusion

• Flexibility

• Scalability

• Interoperability

• Reduce Ops

Tuesday, November 2, 2010

Page 123: Integrating php withrabbitmq_zendcon

Questions?

Tuesday, November 2, 2010

Page 124: Integrating php withrabbitmq_zendcon

Thanks!Álvaro Videla

http://twitter.com/old_sound

http://github.com/videlalvaro

http://github.com/tnc

http://www.slideshare.net/old_sound

Tuesday, November 2, 2010


Recommended