Class: SemqClient
- Inherits:
-
Object
- Object
- SemqClient
- Defined in:
- lib/semq_client.rb
Instance Method Summary collapse
- #allQueuesOnServer ⇒ Object
- #clear ⇒ Object
-
#initialize(server, queue) ⇒ SemqClient
constructor
A new instance of SemqClient.
- #pop(timeout_in_seconds = 0) ⇒ Object
- #push(message) ⇒ Object
Constructor Details
#initialize(server, queue) ⇒ SemqClient
Returns a new instance of SemqClient.
5 6 7 8 |
# File 'lib/semq_client.rb', line 5 def initialize(server, queue) @server = server @queue = queue end |
Instance Method Details
#allQueuesOnServer ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/semq_client.rb', line 39 def allQueuesOnServer url = URI.parse(@server + "/queues") req = Net::HTTP::Get.new(url.path) res = Net::HTTP.start(url.host, url.port) {|http| http.request(req) } case res when Net::HTTPSuccess return res.body else return nil end end |
#clear ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/semq_client.rb', line 25 def clear url = constructQueueUrl req = Net::HTTP::Delete.new(url.path) res = Net::HTTP.start(url.host, url.port) {|http| http.request(req) } case res when Net::HTTPSuccess return true else return false end end |
#pop(timeout_in_seconds = 0) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/semq_client.rb', line 10 def pop(timeout_in_seconds = 0) startTime = Time.now result = getNextItem while result.nil? and (timeout_in_seconds == 0 or Time.now - startTime < timeout_in_seconds) result = getNextItem end return result end |
#push(message) ⇒ Object
19 20 21 22 23 |
# File 'lib/semq_client.rb', line 19 def push() url = constructQueueUrl http = Net::HTTP.new(url.host, url.port) http.post(url.path, ) end |