Skip to content

Instantly share code, notes, and snippets.

@rbnpercy
Created July 23, 2018 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbnpercy/5cc274b92513a2c94337efdb7dadfaae to your computer and use it in GitHub Desktop.
Save rbnpercy/5cc274b92513a2c94337efdb7dadfaae to your computer and use it in GitHub Desktop.
require "rubygems"
require "bunny"
require "json"
# Returns a connection instance
conn = Bunny.new ENV['CLOUDAMQP_URL']
# The connection will be established when start is called
conn.start
# Create a channel in the TCP connection
ch = conn.create_channel
# Declare a queue with a given name, examplequeue. In this example is a durable shared queue used.
q = ch.queue("examplequeue", :durable => true)
# Method for the PDF processing
def pdf_processing(json_information_message)
puts "Handling pdf processing for:"
puts json_information_message['email']
sleep 5.0
puts "pdf processing done"
end
# Set up the consumer to subscribe from the queue
q.subscribe(:block => true) do |delivery_info, properties, payload|
json_information_message = JSON.parse(payload)
pdf_processing(json_information_message)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment