File: consumer.rb

package info (click to toggle)
ruby-stomp 1.4.10-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 832 kB
  • sloc: ruby: 8,595; sh: 77; makefile: 3
file content (34 lines) | stat: -rw-r--r-- 735 bytes parent folder | download | duplicates (6)
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
# -*- encoding: utf-8 -*-

require 'rubygems'
require 'stomp'
#
# == Example message consumer.
#
class ExampleConsumer
  # Initialize.
  def initialize
  end
  # Run example.
  def run
  client = Stomp::Client.new("failover://(stomp://:@localhost:61613,stomp://:@remotehost:61613)?initialReconnectDelay=5000&randomize=false&useExponentialBackOff=false")
  puts "Subscribing ronaldo"
  client.subscribe("/queue/ronaldo", {:ack => "client", "activemq.prefetchSize" => 1, "activemq.exclusive" => true }) do |msg|
    File.open("file", "a") do |f|
      f.write(msg.body)
      f.write("\n----------------\n")
    end

    client.acknowledge(msg)
  end

  loop do
    sleep(1)
    puts "."
  end
  end
end
#
e = ExampleConsumer.new
e.run