Class: RServiceBus2::MQRedis

Inherits:
MQ
  • Object
show all
Defined in:
lib/rservicebus2/mq/redis.rb

Overview

Redis client implementation.

Instance Attribute Summary

Attributes inherited from MQ

#local_queue_name

Instance Method Summary collapse

Methods inherited from MQ

get, #initialize

Constructor Details

This class inherits a constructor from RServiceBus2::MQ

Instance Method Details

#ackObject

“Commit” queue



43
44
45
# File 'lib/rservicebus2/mq/redis.rb', line 43

def ack
  @redis.lpop @queuename
end

#connect(host, port) ⇒ Object

Connect to the broker rubocop:disable Metrics/AbcSize,Metrics/MethodLength



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rservicebus2/mq/redis.rb', line 9

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



30
31
32
33
34
35
36
37
# File 'lib/rservicebus2/mq/redis.rb', line 30

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

  return @redis.lindex @queuename, 0
end

#returnToQueueObject



39
40
# File 'lib/rservicebus2/mq/redis.rb', line 39

def returnToQueue
end

#send(queueName, msg) ⇒ Object

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



48
49
50
# File 'lib/rservicebus2/mq/redis.rb', line 48

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

#subscribe(queuename) ⇒ Object

Connect to the queue



25
26
27
# File 'lib/rservicebus2/mq/redis.rb', line 25

def subscribe( queuename )
  @queuename = queuename
end