SlideShare a Scribd company logo
1 of 37
Download to read offline
On Rabbits and Elephants
      Data Distribution with pg_amqp and RabbitMQ




               Gavin M. Roy @crad - pgConf.eu 2011
myYearbook.com
• #1 Comscore Teen Destination, Top Trafficked Sites in
  US who is hiring

• Use of PostgreSQL predates my joining as CTO in
  2007 and we’re hiring

• Use of RabbitMQ goes back to 2009, we were hiring
  then too

• Awesome place to work, have been known to sponsor
  Europeans for work in the US and we’re hiring

                    Gavin M. Roy @crad - pgConf.eu 2011
Don't try this at home.
   (try it at work or at least on your laptop)




                Gavin M. Roy @crad - pgConf.eu 2011
Audience Participation
• You’ll need PostgreSQL 9.1rc1 with pgbench
  installed

• Python 2.6 or Python 2.7

• Tarball from http://192.168.103.135/~gmr/

 • Untar and then ./setup-client.py


                 Gavin M. Roy @crad - pgConf.eu 2011
Use Cases
• Adding complexity to your environment

• Ensuring data inconsistency between
  canonical data sources and data warehouses

• Impressing your hipster Ruby programmer
  friends

• Replace your Slony replication setup


                 Gavin M. Roy @crad - pgConf.eu 2011
Use Cases
• Write distributed map-reduce functions in
  Erlang




                  Gavin M. Roy @crad - pgConf.eu 2011
What is PostgreSQL?
          (just kidding)




      Gavin M. Roy @crad - pgConf.eu 2011
What is RabbitMQ?
  (don’t let the cloud based marketing deter you)




               Gavin M. Roy @crad - pgConf.eu 2011
About AMPQ
• Platform, Vendor Neutral Messaging format

• 0.9.1 finalized in November 2008

  • JP Morgan Chase, Red Hat, Rabbit Technologies,
    iMatrix, IONA Technologies, Cisco Systems, Envoy
    Technologies, Twist Process Innovations

• Members now include Bank of America, Barclays
  Banks, Microsoft Corporation, Novell, VMWare

• 1.0 Final: October 2011 “Changes some stuff”


                    Gavin M. Roy @crad - pgConf.eu 2011
RabbitMQ & AMQP
    Concepts
   Going to only scratch the surface




            Gavin M. Roy @crad - pgConf.eu 2011
Management Plugin




      Gavin M. Roy @crad - pgConf.eu 2011
Publishers




  Gavin M. Roy @crad - pgConf.eu 2011
Message Broker




    Gavin M. Roy @crad - pgConf.eu 2011
Consumers




  Gavin M. Roy @crad - pgConf.eu 2011
Message Routing
   It’s not just about Queues.


        Gavin M. Roy @crad - pgConf.eu 2011
Routing Key
Helps Determine Message Destination
          (in most cases)




          Gavin M. Roy @crad - pgConf.eu 2011
Queues
• Durability: Queue survives reboot

• Auto-Delete: Delete the queue when consumer
  goes away

• Exclusive: Only one consumer may consume

• x-expires: Auto-Delete after given duration

• x-message-ttl: Auto-discard a message after ttl

                  Gavin M. Roy @crad - pgConf.eu 2011
Declaring a Queue




     Gavin M. Roy @crad - pgConf.eu 2011
Exchanges
(The ones we care about for this talk)




           Gavin M. Roy @crad - pgConf.eu 2011
Direct exchanges

• 1:1 Message Delivery Pattern

• Routing Keys are direct, no wildcarding

• All queues bound to a routing key get the
  message



                 Gavin M. Roy @crad - pgConf.eu 2011
Topic exchanges
• Pattern Matching in Routing Keys

• Publish one message type to
  public.pgbench_accounts another
  public.pgbench_history

• Period delimiter, * stays within the period scope,
  # does not

• Example patterns: *.pgbench_accounts, public.*

                   Gavin M. Roy @crad - pgConf.eu 2011
Other Exchange Types
• Built-In: Fanout, Headers

• 3rd Party or Plugin Types:

  • Consistent Hash Exchange: Round-robin distribution to queues

  • External: RPC Exchange Plugin

  • Riak

  • Last-Value Cache

  • Recent History Exchange: Keeps last 20 messages routed

  • Global Fanout: Sends to all queues, regardless of routing key


                          Gavin M. Roy @crad - pgConf.eu 2011
One More thing...
  Exchange-to-Exchange Bindings




          Gavin M. Roy @crad - pgConf.eu 2011
Messages
• Have client specified properties:

 • Content type, Encoding, Timestamp, App-Id,
   User-Id, Headers

 • Delivery Mode:

   • 1: Non-Persistent

   • 2: Persistent

                     Gavin M. Roy @crad - pgConf.eu 2011
Step-By-Step Instructions
1. Install your Erlang on the machine you into intend to run your RabbitMQ broker on. My preference is for Erlang R14b2, which almost makes me think they name Erlang releases after Star Wars characters, but they
   don't. Erlang is not as fun as Debian is. It doesn't need to be a beefy machine but it should have enough ram that if you don't have an active consumer it won't run out of memory.



2. Install RabbitMQ. This is a multistep process involving black magic. Depending on your distribution you can either download a package, or if your *nix impaired there is a windows installer too. Oh and don't forget
   to install the management plugin. You can download the management plugin from the RqbbitMQ site pretty easy. After you have downloaded it you put it in the RabbitMQ plugins directory. Kind of makes sense
   doesn't it?



3. Go to the store and buy RabbitMQ in Action and RabbitMQ in Detail. What do you mean you can't? No pre-order either? Well there are plenty of good blogs on the intarwebs that have good information such as
   *cough* mine. Seriously though if you are crazy enough to follow my advice and get this far out of actual interest in the subject, make sure you verse yourself in the operation of and the flexibility that is RabbitMQ.



4. Install one of the following: pl/Python, pl/Perl, pl/Ruby, pl/PHP, pl/PGSQL and pg_amqp, or write your own damn addon in c using librabbitmq and then distribute it using the very cool pgxn service. Buoy only need
   this on the databases your going to be writing triggers on. Are you still reading this? Seriously? I would have thought I had lost you by now. Either that or you are skipping ahead because I should have changed
   the slide by now. It could be that Selena is operating the slides, in which case I have no control over these slides which is a terrifying thought. You see there is very little content on the slides, a real lack of
   substance. If I stay on any one slide for too long then you'll realize I really don't know what I am talking about and then I'd not be asked back to give one of the most important talks of the conference.



5. It's almost time to write your publisher, but don't get too far ahead of yourself. You first need to make sure that you have figured out a routing paradigm to use. Don't you like that word? Paradigm. I hear it in my
   head as para dig'um. Anyway, back to routing paradigms. Depending on your use case you will have the ability to broadcast your events to a whole slew of databases that care about what you have to send, or
   just one. You can implement a 1-to-1 type of scenario where a "direct" exchange is setup and your data will be queued in a way that no message is duplicated to your client and there is transactional guarantees in
   RabbitMQ. You probably don't want that thou, as you're a fly -by-the-seat-of-your-pants type of person, aren't you? For that you'll want to turn on noAck mode in your consumers. Rabbit will just fling your
   messages to your consumers as fast as possible, just like an ape at a zoo and his favorite projectile.



6. This is where things get fun,. We are going to quite. Stored procedure in the language of your choice and have it publish to RabbitMQ using an exchange and a routing key, now at this point if you are still reading
   this, I have to question your sanity. This was a one off gag slide to make people at the conference think that I wax going to read all of this. Anyway, wirte your function that publishes and you are almost done. No
   seriously. Well not quite done because you still need the part that calls this function and then the consumer app that reads the data from RabbitMQ and then doe the actions in PostgreSQL that you want it to do.



7. Now, basically you're going to add after insert, update, delete triggers to the tables you care about. I'm. Not going to go into detail about how to do that since you are at a PostgreSQL. Conference and should
   know how to do that already. Instead I am going to assume you know what I am writing about and say that in these triggers you will want to call the function we wrote in step 6 from these trigger events,



8. Go to http://github.com/gmr/On-Rabbits-and-Elephants/ and download the sample code and use that instead of all of this nonsense.




                                                                                 Gavin M. Roy @crad - pgConf.eu 2011
pg_amqp
• Is a publisher only PostgreSQL extension

• Transactional if you use amqp.publish

• Not if you use amqp.autonomous_publish

• Needs some <3 for more advanced features
  like delivery mode changing and message
  properties.


                 Gavin M. Roy @crad - pgConf.eu 2011
Use a Trigger
 (benefit from the value of a trigger?)




         Gavin M. Roy @crad - pgConf.eu 2011
Not that kind of trigger.

     Gavin M. Roy @crad - pgConf.eu 2011
Maybe this kind.

 Gavin M. Roy @crad - pgConf.eu 2011
Really this kind.
   (pretty boring, I know)
 Gavin M. Roy @crad - pgConf.eu 2011
Stop. Demo Time.
     Gavin M. Roy @crad - pgConf.eu 2011
Demo
• Using pgbench

• PostgreSQL 9.1rc1

• pg_amqp and plpythonu

• RabbitMQ 2.6.1

• Python 2.7 (Should work in 2.5 or 2.6 too)


                   Gavin M. Roy @crad - pgConf.eu 2011
Generic Trigger


• Publishes to schema.table_name

• Wraps the entire trigger data set into a JSON
  payload




                  Gavin M. Roy @crad - pgConf.eu 2011
consumer.py
Dynamically builds SQL based upon event type and
   executes on a remote PostgreSQL database



       ./consumer.py 192.168.103.135


                 Gavin M. Roy @crad - pgConf.eu 2011
Proof!
./watch-messages.py 192.168.103.135
         ./watch-db-client.py




          Gavin M. Roy @crad - pgConf.eu 2011
Interactive Demo
     Gavin M. Roy @crad - pgConf.eu 2011
Resources
                                                               ack: dback
• rabbitmq:
                                                      ive feedb u/fee
 http://www.rabbitmq.com                         se g pgconf.e
                                             Plea 011.
                                             http://2
• pg_amqp:
 easy_install pgxnclient
 USE_PGXS=1 pgxn install pg_amqp
 http://pgxn.org/dist/pg_amqp/


• example code:
 https://github.com/gmr/On-Rabbits-and-Elephants
 pgConf.eu Branch


• follow me on twitter: @crad

                                   Gavin M. Roy @crad - pgConf.eu 2011

More Related Content

What's hot

Alvaro Videla, Building a Distributed Data Ingestion System with RabbitMQ
Alvaro Videla, Building a Distributed Data Ingestion System with RabbitMQAlvaro Videla, Building a Distributed Data Ingestion System with RabbitMQ
Alvaro Videla, Building a Distributed Data Ingestion System with RabbitMQTanya Denisyuk
 
Scaling application with RabbitMQ
Scaling application with RabbitMQScaling application with RabbitMQ
Scaling application with RabbitMQNahidul Kibria
 
Messaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQMessaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQAll Things Open
 
Introduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQIntroduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQDmitriy Samovskiy
 
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)James Titcumb
 
The Future of Messaging: RabbitMQ and AMQP
The Future of Messaging: RabbitMQ and AMQP The Future of Messaging: RabbitMQ and AMQP
The Future of Messaging: RabbitMQ and AMQP Eberhard Wolff
 
Messaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQMessaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQPOSSCON
 
An update from the RabbitMQ team - Michael Klishin
An update from the RabbitMQ team - Michael KlishinAn update from the RabbitMQ team - Michael Klishin
An update from the RabbitMQ team - Michael KlishinRabbitMQ Summit
 
Messaging with RabbitMQ and AMQP
Messaging with RabbitMQ and AMQPMessaging with RabbitMQ and AMQP
Messaging with RabbitMQ and AMQPEberhard Wolff
 
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard WolffArchitecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard WolffJAX London
 
Full Stack Bus with Javascript, RabbitMQ and Postal.js
Full Stack Bus with Javascript, RabbitMQ and Postal.jsFull Stack Bus with Javascript, RabbitMQ and Postal.js
Full Stack Bus with Javascript, RabbitMQ and Postal.jsJavier Arias Losada
 
Real time system_performance_mon
Real time system_performance_monReal time system_performance_mon
Real time system_performance_monTomas Doran
 
RabbitMQ Data Ingestion
RabbitMQ Data IngestionRabbitMQ Data Ingestion
RabbitMQ Data IngestionAlvaro Videla
 
Dissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal ArchitectureDissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal ArchitectureAlvaro Videla
 
XMPP & AMQP
XMPP & AMQPXMPP & AMQP
XMPP & AMQPvoluntas
 

What's hot (20)

Alvaro Videla, Building a Distributed Data Ingestion System with RabbitMQ
Alvaro Videla, Building a Distributed Data Ingestion System with RabbitMQAlvaro Videla, Building a Distributed Data Ingestion System with RabbitMQ
Alvaro Videla, Building a Distributed Data Ingestion System with RabbitMQ
 
Scaling application with RabbitMQ
Scaling application with RabbitMQScaling application with RabbitMQ
Scaling application with RabbitMQ
 
Messaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQMessaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQ
 
Spring RabbitMQ
Spring RabbitMQSpring RabbitMQ
Spring RabbitMQ
 
AMQP with RabbitMQ
AMQP with RabbitMQAMQP with RabbitMQ
AMQP with RabbitMQ
 
Introduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQIntroduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQ
 
Message Broker System and RabbitMQ
Message Broker System and RabbitMQMessage Broker System and RabbitMQ
Message Broker System and RabbitMQ
 
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
 
Spring RabbitMQ
Spring RabbitMQSpring RabbitMQ
Spring RabbitMQ
 
RabbitMQ
RabbitMQRabbitMQ
RabbitMQ
 
The Future of Messaging: RabbitMQ and AMQP
The Future of Messaging: RabbitMQ and AMQP The Future of Messaging: RabbitMQ and AMQP
The Future of Messaging: RabbitMQ and AMQP
 
Messaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQMessaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQ
 
An update from the RabbitMQ team - Michael Klishin
An update from the RabbitMQ team - Michael KlishinAn update from the RabbitMQ team - Michael Klishin
An update from the RabbitMQ team - Michael Klishin
 
Messaging with RabbitMQ and AMQP
Messaging with RabbitMQ and AMQPMessaging with RabbitMQ and AMQP
Messaging with RabbitMQ and AMQP
 
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard WolffArchitecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
 
Full Stack Bus with Javascript, RabbitMQ and Postal.js
Full Stack Bus with Javascript, RabbitMQ and Postal.jsFull Stack Bus with Javascript, RabbitMQ and Postal.js
Full Stack Bus with Javascript, RabbitMQ and Postal.js
 
Real time system_performance_mon
Real time system_performance_monReal time system_performance_mon
Real time system_performance_mon
 
RabbitMQ Data Ingestion
RabbitMQ Data IngestionRabbitMQ Data Ingestion
RabbitMQ Data Ingestion
 
Dissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal ArchitectureDissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal Architecture
 
XMPP & AMQP
XMPP & AMQPXMPP & AMQP
XMPP & AMQP
 

Similar to On Rabbits and Elephants

Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pieTomas Doran
 
Run Fast, Try Not to Break S**t
Run Fast, Try Not to Break S**tRun Fast, Try Not to Break S**t
Run Fast, Try Not to Break S**tMichael Schmidt
 
Kubernetes - State of the Union (Q1-2016)
Kubernetes - State of the Union (Q1-2016)Kubernetes - State of the Union (Q1-2016)
Kubernetes - State of the Union (Q1-2016)DoiT International
 
Go After 4 Years in Production - QCon 2015
Go After 4 Years in Production - QCon 2015Go After 4 Years in Production - QCon 2015
Go After 4 Years in Production - QCon 2015Travis Reeder
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesHiroshi SHIBATA
 
Migrating to Puppet 5
Migrating to Puppet 5Migrating to Puppet 5
Migrating to Puppet 5Kris Buytaert
 
Journeys with Transmogrifier and friends or How not to get stuck in the Plone...
Journeys with Transmogrifier and friends or How not to get stuck in the Plone...Journeys with Transmogrifier and friends or How not to get stuck in the Plone...
Journeys with Transmogrifier and friends or How not to get stuck in the Plone...Daniel Jowett
 
Open Source Monitoring in 2019
Open Source Monitoring in 2019 Open Source Monitoring in 2019
Open Source Monitoring in 2019 Kris Buytaert
 
PuppetConf 2014 Killer R10K Workflow With Notes
PuppetConf 2014 Killer R10K Workflow With NotesPuppetConf 2014 Killer R10K Workflow With Notes
PuppetConf 2014 Killer R10K Workflow With NotesPhil Zimmerman
 
How fast can you onboard a new team member with VAGRANT ?
How fast can you onboard a new team member with VAGRANT ?How fast can you onboard a new team member with VAGRANT ?
How fast can you onboard a new team member with VAGRANT ?Vivek Parihar
 
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling StoryPHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Storyvanphp
 
OSDC 2015: Kris Buytaert | From ConfigManagementSucks to ConfigManagementLove
OSDC 2015: Kris Buytaert | From ConfigManagementSucks to ConfigManagementLoveOSDC 2015: Kris Buytaert | From ConfigManagementSucks to ConfigManagementLove
OSDC 2015: Kris Buytaert | From ConfigManagementSucks to ConfigManagementLoveNETWAYS
 
Puppet Development Workflow
Puppet Development WorkflowPuppet Development Workflow
Puppet Development WorkflowJeffery Smith
 
Care and Feeding of Large Scale Graphite Installations - DevOpsDays Austin 2013
Care and Feeding of Large Scale Graphite Installations - DevOpsDays Austin 2013Care and Feeding of Large Scale Graphite Installations - DevOpsDays Austin 2013
Care and Feeding of Large Scale Graphite Installations - DevOpsDays Austin 2013Nick Galbreath
 
PHP Backends for Real-Time User Interaction using Apache Storm.
PHP Backends for Real-Time User Interaction using Apache Storm.PHP Backends for Real-Time User Interaction using Apache Storm.
PHP Backends for Real-Time User Interaction using Apache Storm.DECK36
 
Puppet Camp New York 2014: Streamlining Puppet Development Workflow
Puppet Camp New York 2014: Streamlining Puppet Development Workflow Puppet Camp New York 2014: Streamlining Puppet Development Workflow
Puppet Camp New York 2014: Streamlining Puppet Development Workflow Puppet
 
Steamlining your puppet development workflow
Steamlining your puppet development workflowSteamlining your puppet development workflow
Steamlining your puppet development workflowTomas Doran
 
Silverlight vs HTML5 - Lessons learned from the real world...
Silverlight vs HTML5 - Lessons learned from the real world...Silverlight vs HTML5 - Lessons learned from the real world...
Silverlight vs HTML5 - Lessons learned from the real world...Peter Gfader
 
All about that reactive ui
All about that reactive uiAll about that reactive ui
All about that reactive uiPaul van Zyl
 

Similar to On Rabbits and Elephants (20)

Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pie
 
Run Fast, Try Not to Break S**t
Run Fast, Try Not to Break S**tRun Fast, Try Not to Break S**t
Run Fast, Try Not to Break S**t
 
Kubernetes - State of the Union (Q1-2016)
Kubernetes - State of the Union (Q1-2016)Kubernetes - State of the Union (Q1-2016)
Kubernetes - State of the Union (Q1-2016)
 
Go After 4 Years in Production - QCon 2015
Go After 4 Years in Production - QCon 2015Go After 4 Years in Production - QCon 2015
Go After 4 Years in Production - QCon 2015
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 Minutes
 
Migrating to Puppet 5
Migrating to Puppet 5Migrating to Puppet 5
Migrating to Puppet 5
 
Journeys with Transmogrifier and friends or How not to get stuck in the Plone...
Journeys with Transmogrifier and friends or How not to get stuck in the Plone...Journeys with Transmogrifier and friends or How not to get stuck in the Plone...
Journeys with Transmogrifier and friends or How not to get stuck in the Plone...
 
Open Source Monitoring in 2019
Open Source Monitoring in 2019 Open Source Monitoring in 2019
Open Source Monitoring in 2019
 
PuppetConf 2014 Killer R10K Workflow With Notes
PuppetConf 2014 Killer R10K Workflow With NotesPuppetConf 2014 Killer R10K Workflow With Notes
PuppetConf 2014 Killer R10K Workflow With Notes
 
How fast can you onboard a new team member with VAGRANT ?
How fast can you onboard a new team member with VAGRANT ?How fast can you onboard a new team member with VAGRANT ?
How fast can you onboard a new team member with VAGRANT ?
 
Nodeconf npm 2011
Nodeconf npm 2011Nodeconf npm 2011
Nodeconf npm 2011
 
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling StoryPHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
 
OSDC 2015: Kris Buytaert | From ConfigManagementSucks to ConfigManagementLove
OSDC 2015: Kris Buytaert | From ConfigManagementSucks to ConfigManagementLoveOSDC 2015: Kris Buytaert | From ConfigManagementSucks to ConfigManagementLove
OSDC 2015: Kris Buytaert | From ConfigManagementSucks to ConfigManagementLove
 
Puppet Development Workflow
Puppet Development WorkflowPuppet Development Workflow
Puppet Development Workflow
 
Care and Feeding of Large Scale Graphite Installations - DevOpsDays Austin 2013
Care and Feeding of Large Scale Graphite Installations - DevOpsDays Austin 2013Care and Feeding of Large Scale Graphite Installations - DevOpsDays Austin 2013
Care and Feeding of Large Scale Graphite Installations - DevOpsDays Austin 2013
 
PHP Backends for Real-Time User Interaction using Apache Storm.
PHP Backends for Real-Time User Interaction using Apache Storm.PHP Backends for Real-Time User Interaction using Apache Storm.
PHP Backends for Real-Time User Interaction using Apache Storm.
 
Puppet Camp New York 2014: Streamlining Puppet Development Workflow
Puppet Camp New York 2014: Streamlining Puppet Development Workflow Puppet Camp New York 2014: Streamlining Puppet Development Workflow
Puppet Camp New York 2014: Streamlining Puppet Development Workflow
 
Steamlining your puppet development workflow
Steamlining your puppet development workflowSteamlining your puppet development workflow
Steamlining your puppet development workflow
 
Silverlight vs HTML5 - Lessons learned from the real world...
Silverlight vs HTML5 - Lessons learned from the real world...Silverlight vs HTML5 - Lessons learned from the real world...
Silverlight vs HTML5 - Lessons learned from the real world...
 
All about that reactive ui
All about that reactive uiAll about that reactive ui
All about that reactive ui
 

Recently uploaded

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Recently uploaded (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

On Rabbits and Elephants

  • 1. On Rabbits and Elephants Data Distribution with pg_amqp and RabbitMQ Gavin M. Roy @crad - pgConf.eu 2011
  • 2. myYearbook.com • #1 Comscore Teen Destination, Top Trafficked Sites in US who is hiring • Use of PostgreSQL predates my joining as CTO in 2007 and we’re hiring • Use of RabbitMQ goes back to 2009, we were hiring then too • Awesome place to work, have been known to sponsor Europeans for work in the US and we’re hiring Gavin M. Roy @crad - pgConf.eu 2011
  • 3. Don't try this at home. (try it at work or at least on your laptop) Gavin M. Roy @crad - pgConf.eu 2011
  • 4. Audience Participation • You’ll need PostgreSQL 9.1rc1 with pgbench installed • Python 2.6 or Python 2.7 • Tarball from http://192.168.103.135/~gmr/ • Untar and then ./setup-client.py Gavin M. Roy @crad - pgConf.eu 2011
  • 5. Use Cases • Adding complexity to your environment • Ensuring data inconsistency between canonical data sources and data warehouses • Impressing your hipster Ruby programmer friends • Replace your Slony replication setup Gavin M. Roy @crad - pgConf.eu 2011
  • 6. Use Cases • Write distributed map-reduce functions in Erlang Gavin M. Roy @crad - pgConf.eu 2011
  • 7. What is PostgreSQL? (just kidding) Gavin M. Roy @crad - pgConf.eu 2011
  • 8. What is RabbitMQ? (don’t let the cloud based marketing deter you) Gavin M. Roy @crad - pgConf.eu 2011
  • 9. About AMPQ • Platform, Vendor Neutral Messaging format • 0.9.1 finalized in November 2008 • JP Morgan Chase, Red Hat, Rabbit Technologies, iMatrix, IONA Technologies, Cisco Systems, Envoy Technologies, Twist Process Innovations • Members now include Bank of America, Barclays Banks, Microsoft Corporation, Novell, VMWare • 1.0 Final: October 2011 “Changes some stuff” Gavin M. Roy @crad - pgConf.eu 2011
  • 10. RabbitMQ & AMQP Concepts Going to only scratch the surface Gavin M. Roy @crad - pgConf.eu 2011
  • 11. Management Plugin Gavin M. Roy @crad - pgConf.eu 2011
  • 12. Publishers Gavin M. Roy @crad - pgConf.eu 2011
  • 13. Message Broker Gavin M. Roy @crad - pgConf.eu 2011
  • 14. Consumers Gavin M. Roy @crad - pgConf.eu 2011
  • 15. Message Routing It’s not just about Queues. Gavin M. Roy @crad - pgConf.eu 2011
  • 16. Routing Key Helps Determine Message Destination (in most cases) Gavin M. Roy @crad - pgConf.eu 2011
  • 17. Queues • Durability: Queue survives reboot • Auto-Delete: Delete the queue when consumer goes away • Exclusive: Only one consumer may consume • x-expires: Auto-Delete after given duration • x-message-ttl: Auto-discard a message after ttl Gavin M. Roy @crad - pgConf.eu 2011
  • 18. Declaring a Queue Gavin M. Roy @crad - pgConf.eu 2011
  • 19. Exchanges (The ones we care about for this talk) Gavin M. Roy @crad - pgConf.eu 2011
  • 20. Direct exchanges • 1:1 Message Delivery Pattern • Routing Keys are direct, no wildcarding • All queues bound to a routing key get the message Gavin M. Roy @crad - pgConf.eu 2011
  • 21. Topic exchanges • Pattern Matching in Routing Keys • Publish one message type to public.pgbench_accounts another public.pgbench_history • Period delimiter, * stays within the period scope, # does not • Example patterns: *.pgbench_accounts, public.* Gavin M. Roy @crad - pgConf.eu 2011
  • 22. Other Exchange Types • Built-In: Fanout, Headers • 3rd Party or Plugin Types: • Consistent Hash Exchange: Round-robin distribution to queues • External: RPC Exchange Plugin • Riak • Last-Value Cache • Recent History Exchange: Keeps last 20 messages routed • Global Fanout: Sends to all queues, regardless of routing key Gavin M. Roy @crad - pgConf.eu 2011
  • 23. One More thing... Exchange-to-Exchange Bindings Gavin M. Roy @crad - pgConf.eu 2011
  • 24. Messages • Have client specified properties: • Content type, Encoding, Timestamp, App-Id, User-Id, Headers • Delivery Mode: • 1: Non-Persistent • 2: Persistent Gavin M. Roy @crad - pgConf.eu 2011
  • 25. Step-By-Step Instructions 1. Install your Erlang on the machine you into intend to run your RabbitMQ broker on. My preference is for Erlang R14b2, which almost makes me think they name Erlang releases after Star Wars characters, but they don't. Erlang is not as fun as Debian is. It doesn't need to be a beefy machine but it should have enough ram that if you don't have an active consumer it won't run out of memory. 2. Install RabbitMQ. This is a multistep process involving black magic. Depending on your distribution you can either download a package, or if your *nix impaired there is a windows installer too. Oh and don't forget to install the management plugin. You can download the management plugin from the RqbbitMQ site pretty easy. After you have downloaded it you put it in the RabbitMQ plugins directory. Kind of makes sense doesn't it? 3. Go to the store and buy RabbitMQ in Action and RabbitMQ in Detail. What do you mean you can't? No pre-order either? Well there are plenty of good blogs on the intarwebs that have good information such as *cough* mine. Seriously though if you are crazy enough to follow my advice and get this far out of actual interest in the subject, make sure you verse yourself in the operation of and the flexibility that is RabbitMQ. 4. Install one of the following: pl/Python, pl/Perl, pl/Ruby, pl/PHP, pl/PGSQL and pg_amqp, or write your own damn addon in c using librabbitmq and then distribute it using the very cool pgxn service. Buoy only need this on the databases your going to be writing triggers on. Are you still reading this? Seriously? I would have thought I had lost you by now. Either that or you are skipping ahead because I should have changed the slide by now. It could be that Selena is operating the slides, in which case I have no control over these slides which is a terrifying thought. You see there is very little content on the slides, a real lack of substance. If I stay on any one slide for too long then you'll realize I really don't know what I am talking about and then I'd not be asked back to give one of the most important talks of the conference. 5. It's almost time to write your publisher, but don't get too far ahead of yourself. You first need to make sure that you have figured out a routing paradigm to use. Don't you like that word? Paradigm. I hear it in my head as para dig'um. Anyway, back to routing paradigms. Depending on your use case you will have the ability to broadcast your events to a whole slew of databases that care about what you have to send, or just one. You can implement a 1-to-1 type of scenario where a "direct" exchange is setup and your data will be queued in a way that no message is duplicated to your client and there is transactional guarantees in RabbitMQ. You probably don't want that thou, as you're a fly -by-the-seat-of-your-pants type of person, aren't you? For that you'll want to turn on noAck mode in your consumers. Rabbit will just fling your messages to your consumers as fast as possible, just like an ape at a zoo and his favorite projectile. 6. This is where things get fun,. We are going to quite. Stored procedure in the language of your choice and have it publish to RabbitMQ using an exchange and a routing key, now at this point if you are still reading this, I have to question your sanity. This was a one off gag slide to make people at the conference think that I wax going to read all of this. Anyway, wirte your function that publishes and you are almost done. No seriously. Well not quite done because you still need the part that calls this function and then the consumer app that reads the data from RabbitMQ and then doe the actions in PostgreSQL that you want it to do. 7. Now, basically you're going to add after insert, update, delete triggers to the tables you care about. I'm. Not going to go into detail about how to do that since you are at a PostgreSQL. Conference and should know how to do that already. Instead I am going to assume you know what I am writing about and say that in these triggers you will want to call the function we wrote in step 6 from these trigger events, 8. Go to http://github.com/gmr/On-Rabbits-and-Elephants/ and download the sample code and use that instead of all of this nonsense. Gavin M. Roy @crad - pgConf.eu 2011
  • 26. pg_amqp • Is a publisher only PostgreSQL extension • Transactional if you use amqp.publish • Not if you use amqp.autonomous_publish • Needs some <3 for more advanced features like delivery mode changing and message properties. Gavin M. Roy @crad - pgConf.eu 2011
  • 27. Use a Trigger (benefit from the value of a trigger?) Gavin M. Roy @crad - pgConf.eu 2011
  • 28. Not that kind of trigger. Gavin M. Roy @crad - pgConf.eu 2011
  • 29. Maybe this kind. Gavin M. Roy @crad - pgConf.eu 2011
  • 30. Really this kind. (pretty boring, I know) Gavin M. Roy @crad - pgConf.eu 2011
  • 31. Stop. Demo Time. Gavin M. Roy @crad - pgConf.eu 2011
  • 32. Demo • Using pgbench • PostgreSQL 9.1rc1 • pg_amqp and plpythonu • RabbitMQ 2.6.1 • Python 2.7 (Should work in 2.5 or 2.6 too) Gavin M. Roy @crad - pgConf.eu 2011
  • 33. Generic Trigger • Publishes to schema.table_name • Wraps the entire trigger data set into a JSON payload Gavin M. Roy @crad - pgConf.eu 2011
  • 34. consumer.py Dynamically builds SQL based upon event type and executes on a remote PostgreSQL database ./consumer.py 192.168.103.135 Gavin M. Roy @crad - pgConf.eu 2011
  • 35. Proof! ./watch-messages.py 192.168.103.135 ./watch-db-client.py Gavin M. Roy @crad - pgConf.eu 2011
  • 36. Interactive Demo Gavin M. Roy @crad - pgConf.eu 2011
  • 37. Resources ack: dback • rabbitmq: ive feedb u/fee http://www.rabbitmq.com se g pgconf.e Plea 011. http://2 • pg_amqp: easy_install pgxnclient USE_PGXS=1 pgxn install pg_amqp http://pgxn.org/dist/pg_amqp/ • example code: https://github.com/gmr/On-Rabbits-and-Elephants pgConf.eu Branch • follow me on twitter: @crad Gavin M. Roy @crad - pgConf.eu 2011