http://twitter.com/GianArb
Queue system
gianarb92@gmail.com Gianluca Arbezzano 1
Gianluca Arbezzano
@GianArb
http://github...
http://twitter.com/GianArb
TODO
• Send a mail
• Upload big file
• Imports
• Messagging
• …
gianarb92@gmail.com Gianluca Ar...
http://twitter.com/GianArb
Only one Role
gianarb92@gmail.com Gianluca Arbezzano 3
You DON’T MAKE to user wait
http://twitter.com/GianArb
The solution is…
gianarb92@gmail.com Gianluca Arbezzano 4
http://twitter.com/GianArb
Queue System
gianarb92@gmail.com Gianluca Arbezzano 5
• Queue
• Producer
• Consumer
• Message
http://twitter.com/GianArb
Queue
gianarb92@gmail.com Gianluca Arbezzano 6
ZendQueueQueue
// Create an array queue adapter
...
http://twitter.com/GianArb
Message Queue
Message queues provide an asynchronous
communications protocol, meaning that the
...
http://twitter.com/GianArb
Producer
• Send messages quickly
gianarb92@gmail.com Gianluca Arbezzano 8
Consumer
• Receive me...
http://twitter.com/GianArb
Queue System, when?
gianarb92@gmail.com Gianluca Arbezzano 9
Registration Query Mail
• Time-shi...
http://twitter.com/GianArb
Workflow
gianarb92@gmail.com Gianluca Arbezzano 10
Registration Query
Send Message
in queue
Sen...
http://twitter.com/GianArb
Worker (old way)
use ZendQueueQueue;
do {
$messages = $queue->receive();
//do some work
sleep(1...
http://twitter.com/GianArb
WORKERS!
gianarb92@gmail.com Gianluca Arbezzano 12
http://twitter.com/GianArb
Await
gianarb92@gmail.com Gianluca Arbezzano 13
$queue->await()
http://twitter.com/GianArb
Role
• Your adapter implement awaitMessage()
• || your queue can emulate await
gianarb92@gmail....
http://twitter.com/GianArb
*callback
gianarb92@gmail.com Gianluca Arbezzano 15
http://twitter.com/GianArb
Worker
use ZendQueueQueue;
use ZendQueueQueueEvent;
$queue->getEventManager()-
>attach(QueueEve...
http://twitter.com/GianArb
Use case overview
• Short run jobs
• Long run jobs
• Schedule jobs (like cron jobs)
• Enterpris...
http://twitter.com/GianArb
Links!
• Use case
https://github.com/ripaclub/ZendQueue/wiki/
Example-Usage
• Proposal
https://...
http://twitter.com/GianArb
Ripa Club
gianarb92@gmail.com Gianluca Arbezzano 19
Powered by
http://github.com/ripaclub
Upcoming SlideShare
Loading in …5
×

Queue System and Zend\Queue implementation

2,085 views

Published on

PugMi for Queue System and implementation in PHP with Zend\Queue

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,085
On SlideShare
0
From Embeds
0
Number of Embeds
122
Actions
Shares
0
Downloads
8
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Queue System and Zend\Queue implementation

  1. 1. http://twitter.com/GianArb Queue system gianarb92@gmail.com Gianluca Arbezzano 1 Gianluca Arbezzano @GianArb http://github.com/gianarb
  2. 2. http://twitter.com/GianArb TODO • Send a mail • Upload big file • Imports • Messagging • … gianarb92@gmail.com Gianluca Arbezzano 2
  3. 3. http://twitter.com/GianArb Only one Role gianarb92@gmail.com Gianluca Arbezzano 3 You DON’T MAKE to user wait
  4. 4. http://twitter.com/GianArb The solution is… gianarb92@gmail.com Gianluca Arbezzano 4
  5. 5. http://twitter.com/GianArb Queue System gianarb92@gmail.com Gianluca Arbezzano 5 • Queue • Producer • Consumer • Message
  6. 6. http://twitter.com/GianArb Queue gianarb92@gmail.com Gianluca Arbezzano 6 ZendQueueQueue // Create an array queue adapter $adapter = new ArrayAdapter(); // Create a queue object $queue = new Queue('queue1', $adapter); Adapter • Db • MongoDb • MongoCappedCollection • ArrayAdapter • TODO: Redis • TODO: RabbitMQ
  7. 7. http://twitter.com/GianArb Message Queue Message queues provide an asynchronous communications protocol, meaning that the sender and receiver of the message do not need to interact with the message queue at the same time. Cit. Wikipedia gianarb92@gmail.com Gianluca Arbezzano 7 ZendQueueMessageMessage implement ZendStdlibMessage
  8. 8. http://twitter.com/GianArb Producer • Send messages quickly gianarb92@gmail.com Gianluca Arbezzano 8 Consumer • Receive messages • Usually it’s a worker that consumes one message at time.
  9. 9. http://twitter.com/GianArb Queue System, when? gianarb92@gmail.com Gianluca Arbezzano 9 Registration Query Mail • Time-shifts job processing when the “CPU” is less busy • Distributed computing • In a web app allows to run tasks in background reducing the http request time
  10. 10. http://twitter.com/GianArb Workflow gianarb92@gmail.com Gianluca Arbezzano 10 Registration Query Send Message in queue Send mail Send mail Send mail Send mail Send mailWORKER
  11. 11. http://twitter.com/GianArb Worker (old way) use ZendQueueQueue; do { $messages = $queue->receive(); //do some work sleep(1); } while (…) gianarb92@gmail.com Gianluca Arbezzano 11
  12. 12. http://twitter.com/GianArb WORKERS! gianarb92@gmail.com Gianluca Arbezzano 12
  13. 13. http://twitter.com/GianArb Await gianarb92@gmail.com Gianluca Arbezzano 13 $queue->await()
  14. 14. http://twitter.com/GianArb Role • Your adapter implement awaitMessage() • || your queue can emulate await gianarb92@gmail.com Gianluca Arbezzano 14 $adapter->awaitMessages(Queue $queue, $callback, ReceiveParameters $params = null)
  15. 15. http://twitter.com/GianArb *callback gianarb92@gmail.com Gianluca Arbezzano 15
  16. 16. http://twitter.com/GianArb Worker use ZendQueueQueue; use ZendQueueQueueEvent; $queue->getEventManager()- >attach(QueueEvent::EVENT_RECEIVE, function (QueueEvent $e) use ($queue) { $message = $e->getMessages()->current(); //do some work $queue->delete($message); }); //Wait for incoming messages $queue->await(); gianarb92@gmail.com Gianluca Arbezzano 16
  17. 17. http://twitter.com/GianArb Use case overview • Short run jobs • Long run jobs • Schedule jobs (like cron jobs) • Enterprise service bus gianarb92@gmail.com Gianluca Arbezzano 17
  18. 18. http://twitter.com/GianArb Links! • Use case https://github.com/ripaclub/ZendQueue/wiki/ Example-Usage • Proposal https://github.com/ripaclub/ZendQueue/wiki/ ZendQueue-Proposal gianarb92@gmail.com Gianluca Arbezzano 18
  19. 19. http://twitter.com/GianArb Ripa Club gianarb92@gmail.com Gianluca Arbezzano 19 Powered by http://github.com/ripaclub

×