Class: JobQueue::StompAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/job_queue/adapters/stomp_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ StompAdapter

Returns a new instance of StompAdapter.



4
5
6
7
8
9
10
# File 'lib/job_queue/adapters/stomp_adapter.rb', line 4

def initialize(options = {})
  username = options[:username]
  password = options[:password]
  host = options[:host] || 'localhost'
  port = options[:port] || 61613
  @conn = Stomp::Connection.new(username, password, host, port, true)
end

Instance Method Details

#put(string) ⇒ Object



12
13
14
# File 'lib/job_queue/adapters/stomp_adapter.rb', line 12

def put(string)
  @conn.send("/queue/job_queue", string, :persistent => true)
end

#subscribe(error_report, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/job_queue/adapters/stomp_adapter.rb', line 16

def subscribe(error_report, &block)
    @conn.subscribe("/queue/job_queue")
    loop do
      begin
        job = @conn.receive
        JobQueue.logger.info "Stomp received #{job}"
        yield job.body
      rescue => e
        error_report.call(job, e)
      end
    end
end