Successfully reported this slideshow.

RabbitMQ for Perl mongers

10

Share

1 of 34
1 of 34

RabbitMQ for Perl mongers

10

Share

Download to read offline

A talk I held at perl mongers Wellington about RabbitMQ and Net::AMQP. A brief introduction to RabbitMQ and some basic code samples on how to use it from perl.

A talk I held at perl mongers Wellington about RabbitMQ and Net::AMQP. A brief introduction to RabbitMQ and some basic code samples on how to use it from perl.

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

RabbitMQ for Perl mongers

  1. 1. RabbitMQ for perl mongers
  2. 2. __ / ` __ | ` /`/ _/` -"-/` / | | | (d b) _/ / ,".|.'._/.'.|.", / /' _|_ '/ | / '-`"`-' | | | | | | / / | jgs / / / `"` : /'"` `""`""`
  3. 3. AMQP Advanced Message Queuing Protocol
  4. 4. message flow in RabbitMQ
  5. 5. RabbitMQ Exchange Queue Queue
  6. 6. RabbitMQ RabbitMQ Queue
  7. 7. RabbitMQ Queue
  8. 8. AMQP XMPP STOMP HTTP RabbitMQ AMQP XMPP STOMP HTTP
  9. 9. AMQP XMPP STOMP HTTP RabbitMQ AMQP XMPP STOMP HTTP AMQP XMPP STOMP HTTP RabbitMQ AMQP XMPP STOMP HTTP
  10. 10. nice pictures but how does it look like?
  11. 11. Net::AMQP(::Simple)
  12. 12. boilerplate
  13. 13. my $spec = { RemoteAddress => '127.0.0.1', RemotePort => { default => 5672 }, Username => { default => 'guest' }, Password => { default => 'guest' }, VirtualHost => { default => '/' }, Logger => 0, Debug => { default => {} }, Alias => { default => 'amqp_client' }, AliasTCP => { default => 'tcp_client' }, Callbacks => { default => {} }, channels => { default => {} }, is_started => { default => 0 }, };
  14. 14. send a hash
  15. 15. # conect to the server Net::AMQP::Simple::connect($spec); # push the message Net::AMQP::Simple::pub( $queue, to_json($hash) );
  16. 16. receive a message
  17. 17. while ( !$done ) { check( Net::AMQP::Simple::poll() ); } sub check { foreach my $_req (@_) { my $req = from_json($_req); print Dumper($req); $done = 1; } }
  18. 18. typical messaging flow
  19. 19. the “server”
  20. 20. Net::AMQP::Simple::connect($spec); Net::AMQP::Simple::queue("web.domaindb.up"); while (1) { process( Net::AMQP::Simple::poll() ); } sub process { foreach my $_req (@_) { my $req = from_json( $_req, { allow_nonref => 1 } ); ... }
  21. 21. the “client”
  22. 22. Net::AMQP::Simple::connect($spec); Net::AMQP::Simple::pub( $queue, to_json($hash) ); Net::AMQP::Simple::queue( $uuid, 'autodelete' ); while ( !$done ) { check( Net::AMQP::Simple::poll() ); } sub check { foreach my $_req (@_) { my $req = from_json($_req); print Dumper($req); $done = 1; } }
  23. 23. in plain english • start a service that listens on a queue • push a message to the service and tell the service how to reply (if needed) • listen on a temp queue for the response (if needed)
  24. 24. how to reply? • use AMQP header fields • roll your own protocol (JSON, XML, ...)
  25. 25. ... roll your own if you want to use the full power of RabbitMQ
  26. 26. AMQP XMPP STOMP HTTP RabbitMQ AMQP XMPP STOMP HTTP
  27. 27. how to get started?
  28. 28. • http://rabbitmq.com (get rabbit here) • http://github.com/norbu09/ • net_amqp (has the Simple.pm) • RabbitIntro (some samples) • Net_RabbitMQ_HTTP
  29. 29. or ask me lenz@ideegeo.com @norbu09
  30. 30. thanks
  31. 31. credits • the RabbitMQ guys for an awesome product • iWantMyName for letting me play with all that stuff • many guys on the mailing list for helping me out when i got stuck • Catalyst IT for the beers
  32. 32. more credits • http://www.ascii-art.com • http://www.flickr.com/photos/revengingangel/ • http://www.flickr.com/photos/jeff62138/

×