Skip to content

Creating New Producing Applications

Kyle edited this page Feb 27, 2015 · 3 revisions

In order to create a new producing application, the application will require:

  1. A config file pointing at the message service. An example for a RabbitMQ environment would be: amqp://username:[email protected]:5672.

  2. Some manner of initialization. An example initializer for a Rails app might be:

require "emque-producing"
config = YAML.load_file(Rails.root.join("config/queue.yml"))[Rails.env]
Emque::Producing.configure do |c|
  c.app_name = config["app_name"]
end
  1. Some method of quickly testing that the config and initialization are wiring the producing application up to the queue correctly. While it's beyond the scope of this page to fully instruct a message infrastructure, an example (using a ruby web app and RabbitMQ) might be a rake task:
  desc "Fire tracer bullet to test queue"
  task :send_tracer_bullet => :environment do
    message = "{\"metadata\":{\"topic\":\"consuming_app\",\"type\":\"consuming_app.tracer_bullet\"},\"email_address\":\"[email protected]\"}"
    Emque::Producing.publisher.publish("consuming_app", "tracer_bullet", message)
  end

Running the example above will very like raise a MessageNotSent error. Why? Well, it's sort of a chicken and egg problem. Emque-producing, by default with the rabbitmq producer, is configured with a default setting requiring that all messages are "mandatory". This effectively means that if RabbitMQ can't accept your message, the producing application will error. This is a strict rule, but is helpful if you desire confirmation that the messages you think you're producing are actually being placed onto Rabbit. So, how to fix?

  1. You need to either relax the mandatory constraint for your messages (not currently supported in emque-producing, though PR's are welcome!) or you can define an exchange and queue for your messages. There are two ways to do this:
  1. Create and exchange and queue via the RabbitMQ management panel
  2. Create a message consuming service (with emque-consuming) that has a route defined for the message you are producing.

Practically speaking, most folks will have a consumer for a given message they are producing, so it makes most sense to follow that option. Define your consumer, start the service so that it creates the exchange in your local RabbitMQ installation, then start firing off your producer!

Clone this wiki locally