hassox (owner)

Revisions

gist: 159049 Download_button fork
public
Public Clone URL: git://gist.github.com/159049.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env ruby
 
require 'rubygems'
gem 'tmm1-amqp'
require 'mq'
 
EM.run do
  puts "Creating the headers exchange"
  headers_exch = MQ.headers("headers-test", :auto_delete => true)
  
  q1 = MQ.queue("headers-test-q1", :auto_delete => true).bind(headers_exch, :arguments => {"matchable" => "true", "test" => "false", "x-match" => "all"})
  q2 = MQ.queue("headers-test-q2", :auto_delete => true).bind(headers_exch, :arguments => {"matchable" => "true", "test" => "true", "x-match" => "any"})
  q3 = MQ.queue("headers-test-q3", :auto_delete => true).bind(headers_exch, :arguments => {"test" => "false", "x-match" => "all"})
 
  
  q1.subscribe do |hdr, msg|
    puts "In q1"
    puts "Msg: #{msg.inspect}"
    puts("\n" * 2)
  end
  
  q2.subscribe do |hdr, msg|
    puts "In q2"
    puts "Msg: #{msg.inspect}"
    puts("\n" * 2)
  end
  
  q3.subscribe do |hdr, msg|
    puts "In q3"
    puts "Msg: #{msg.inspect}"
    puts("\n" * 2)
  end
  
  EM.add_periodic_timer(1) { headers_exch.publish("Match q1, q2, q3", :headers => {:matchable => "true", :test => "false"})}
  EM.add_periodic_timer(1.5){ headers_exch.publish("Match q2, q3", :headers => {:matchable => "true", :test => "true"})}
  EM.add_periodic_timer(2) { headers_exch.publish("Match q1, q3", :headers => {:test => "false"})}
end