Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 56 lines (38 sloc) 3.735 kb
b7a0c31 @dylanegan Faqueue, you know it makes sense.
authored
1 = Faqueue
2 Faqueue is a library for mocking the various objects that make up the ruby AMQP[http://github.com/tmm1/amqp] library. It allows you to use the AMQP library naturally and test your code easily without running an AMQP broker. If you want a higher level of control, you can use your favorite mocking and stubbing library to modify individual calls to MQ.queue and the like so that they return Faqueue's mock up versions. If you want to go all-in, you can tell Faqueue to overload the MQ and AMQP. This allows you to use MQ and AMQP as normal, while Faqueue works behind the scenes to wire everything together.
3c6ec65 @danielsdeleo README!
danielsdeleo authored
3
4 = Getting started
5
b7a0c31 @dylanegan Faqueue, you know it makes sense.
authored
6 require "faqueue"
3c6ec65 @danielsdeleo README!
danielsdeleo authored
7 overload_amqp
8
9 mq = MQ.new
10 => #<MQ:0x1197ae8>
073bcb3 @danielsdeleo Add example usage in spec/examples/basic_usage + minor fixes
danielsdeleo authored
11
3c6ec65 @danielsdeleo README!
danielsdeleo authored
12 queue = mq.queue("mocktacular")
b7a0c31 @dylanegan Faqueue, you know it makes sense.
authored
13 => #<Faqueue::MockQueue:0x1194550 @name="mocktacular">
073bcb3 @danielsdeleo Add example usage in spec/examples/basic_usage + minor fixes
danielsdeleo authored
14
3c6ec65 @danielsdeleo README!
danielsdeleo authored
15 topic = mq.topic("lolz")
b7a0c31 @dylanegan Faqueue, you know it makes sense.
authored
16 => #<Faqueue::MockExchange:0x11913dc @topic="lolz">
073bcb3 @danielsdeleo Add example usage in spec/examples/basic_usage + minor fixes
danielsdeleo authored
17
3c6ec65 @danielsdeleo README!
danielsdeleo authored
18 queue.bind(topic, :key=> "cats.*")
b7a0c31 @dylanegan Faqueue, you know it makes sense.
authored
19 => #<Faqueue::MockQueue:0x1194550 @name="mocktacular">
073bcb3 @danielsdeleo Add example usage in spec/examples/basic_usage + minor fixes
danielsdeleo authored
20
3c6ec65 @danielsdeleo README!
danielsdeleo authored
21 queue.subscribe {|header, msg| puts [header.routing_key, msg]}
22 => nil
073bcb3 @danielsdeleo Add example usage in spec/examples/basic_usage + minor fixes
danielsdeleo authored
23
3c6ec65 @danielsdeleo README!
danielsdeleo authored
24 topic.publish("eatin ur foodz", :key => "cats.inUrFridge")
25 # cats.inUrFridge
26 # eatin ur foodz
27
b7a0c31 @dylanegan Faqueue, you know it makes sense.
authored
28 Note that in this example, we didn't have to deal with <tt>AMQP.start</tt> or <tt>EM.run</tt>. This should be ample evidence that you should run higher level tests without any mocks or stubs so you can be sure everything works with real MQ objects. With that said, <tt>#overload_amqp</tt> does overload the <tt>AMQP.start</tt> method, so you can use Faqueue for mid-level testing if desired. Have a look at the spec/examples directory to see Faqueue running some of AMQP's examples in overload mode for more demonstration of this.
3c6ec65 @danielsdeleo README!
danielsdeleo authored
29
a7c4ab6 @danielsdeleo Update readme for custom rspec matchers
danielsdeleo authored
30 = Custom Rspec Matchers
b7a0c31 @dylanegan Faqueue, you know it makes sense.
authored
31 For Test::Unit users, Faqueue's default syntax should be a good fit with <tt>assert()</tt>:
a7c4ab6 @danielsdeleo Update readme for custom rspec matchers
danielsdeleo authored
32 assert(queue.received_message?("eatin ur foodz"))
33 Rspec users will probably want something a bit more natural language-y. You got it:
34 queue.should have_received("a message")
35 queue.should have_ack_for("a different message")
36
6d34afa @danielsdeleo README fixes
danielsdeleo authored
37 = What's Working? What's Not?
ed8ced5 @danielsdeleo update readme and basic usage spec to reflect fanout capabilities
danielsdeleo authored
38 As you can tell from the example above, quite a bit is working. This includes direct exchanges where you call <tt>#publish</tt> and <tt>#subscribe</tt> on the same queue, acknowledgements, topic exchanges, and fanout exchanges.
3c6ec65 @danielsdeleo README!
danielsdeleo authored
39
ed8ced5 @danielsdeleo update readme and basic usage spec to reflect fanout capabilities
danielsdeleo authored
40 What's not working:
41 * RPC exchanges.
b7a0c31 @dylanegan Faqueue, you know it makes sense.
authored
42 * The routing key matching algorithm works for common cases, including "*" and "#" wildcards in the binding key. If you need anything more complicated than that, Faqueue is not guaranteed to do the right thing.
ed8ced5 @danielsdeleo update readme and basic usage spec to reflect fanout capabilities
danielsdeleo authored
43 * Receiving acks when using topic exchanges works only if you subscribe before publishing.
3c6ec65 @danielsdeleo README!
danielsdeleo authored
44
b7a0c31 @dylanegan Faqueue, you know it makes sense.
authored
45 There are some things that Faqueue may never be able to do. As one prominent example, for queues that are configured to expect acknowledgements (the <tt>:ack=>true</tt> option), the behavior on shutdown is not emulated correctly.
6d34afa @danielsdeleo README fixes
danielsdeleo authored
46
981d7a4 @danielsdeleo hacking == awesome; todo == also ran iPhone app QED.
danielsdeleo authored
47 == Hacking
b7a0c31 @dylanegan Faqueue, you know it makes sense.
authored
48 Faqueue is at a stage where it "works for me." That said, there may be methods or method signatures that aren't correct/ aren't supported. If this happens to you, fork me and send a pull request when you're done. Patches and feedback welcome.
ed8ced5 @danielsdeleo update readme and basic usage spec to reflect fanout capabilities
danielsdeleo authored
49
50 == Moar
b7a0c31 @dylanegan Faqueue, you know it makes sense.
authored
51 I wrote an introductory post on my blog, it's probably the best source of high-level discussion right now. Visit: http://kallistec.com/2009/06/21/introducing-faqueue/
ed8ced5 @danielsdeleo update readme and basic usage spec to reflect fanout capabilities
danielsdeleo authored
52
b7a0c31 @dylanegan Faqueue, you know it makes sense.
authored
53 If you prefer code over drivel, look at the specs under spec/examples. There you'll find some of the examples from the amqp library running completely Faqueue-ified; the basic_usage_spec.rb shows some lower-level use.
073bcb3 @danielsdeleo Add example usage in spec/examples/basic_usage + minor fixes
danielsdeleo authored
54
b7a0c31 @dylanegan Faqueue, you know it makes sense.
authored
55 As always, you're invited to git yer fork on if you want to work on any of these. If you find a bug that you can't source or want to send love or hate mail, you can contact me directly at dan@kallistec.com
Something went wrong with that request. Please try again.