Class: RServiceBus::MQ_Redis

Inherits:
MQ
  • Object
show all
Defined in:
lib/rservicebus/MQ/Redis.rb

Overview

Beanstalk client implementation.

Instance Attribute Summary

Attributes inherited from MQ

#localQueueName

Instance Method Summary collapse

Methods inherited from MQ

get, #initialize

Constructor Details

This class inherits a constructor from RServiceBus::MQ

Instance Method Details

#ackObject

“Commit” queue



47
48
49
# File 'lib/rservicebus/MQ/Redis.rb', line 47

def ack
    @redis.lpop @queuename
end

#connect(host, port) ⇒ Object

Connect to the broker



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rservicebus/MQ/Redis.rb', line 12

def connect( host, port )
    port ||= 6379
    string = "#{host}:#{port}"

    begin
        @redis = Redis.new(:host => host, :port => port)

        rescue Exception => e
        puts e.message
        puts 'Error connecting to Redis for mq'
        puts "Host string, #{string}"
        abort()
    end
end

#popObject

Get next msg from queue



34
35
36
37
38
39
40
41
# File 'lib/rservicebus/MQ/Redis.rb', line 34

def pop
        if @redis.llen( @queuename ) == 0 then
            sleep @timeout
            raise NoMsgToProcess.new
        end
        
        return @redis.lindex @queuename, 0
end

#returnToQueueObject



43
44
# File 'lib/rservicebus/MQ/Redis.rb', line 43

def returnToQueue
end

#send(queueName, msg) ⇒ Object

At least called in the Host rescue block, to ensure all network links are healthy



52
53
54
# File 'lib/rservicebus/MQ/Redis.rb', line 52

def send( queueName, msg )
    @redis.rpush queueName, msg
end

#subscribe(queuename) ⇒ Object

Connect to the queue



29
30
31
# File 'lib/rservicebus/MQ/Redis.rb', line 29

def subscribe( queuename )
    @queuename = queuename
end