semq-client 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/semq_client.rb +46 -0
- metadata +66 -0
data/lib/semq_client.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
class SemqClient
|
4
|
+
|
5
|
+
def initialize(server, queue)
|
6
|
+
@server = server
|
7
|
+
@queue = queue
|
8
|
+
end
|
9
|
+
|
10
|
+
def pop(timeout_in_seconds = 0)
|
11
|
+
startTime = Time.now
|
12
|
+
result = getNextItem
|
13
|
+
while result.nil? and (timeout_in_seconds == 0 or Time.now - startTime < timeout_in_seconds)
|
14
|
+
result = getNextItem
|
15
|
+
end
|
16
|
+
return result
|
17
|
+
end
|
18
|
+
|
19
|
+
def push(message)
|
20
|
+
url = constructQueueUrl
|
21
|
+
http = Net::HTTP.new(url.host, url.port)
|
22
|
+
http.post(url.path, message)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def constructQueueUrl
|
28
|
+
URI.parse(@server + '/' + @queue)
|
29
|
+
end
|
30
|
+
|
31
|
+
def getNextItem
|
32
|
+
url = constructQueueUrl
|
33
|
+
req = Net::HTTP::Get.new(url.path)
|
34
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
35
|
+
http.request(req)
|
36
|
+
}
|
37
|
+
case res
|
38
|
+
when Net::HTTPSuccess
|
39
|
+
return res.body
|
40
|
+
else
|
41
|
+
return nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: semq-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: "1.0"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Ian Calvert
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-08-11 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: A simple client for using semq message servers. Supports push and pop methods to named queues. Pop can wait indefinitely, using long polling to remain lightweight.
|
22
|
+
email:
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/semq_client.rb
|
31
|
+
has_rdoc: true
|
32
|
+
homepage:
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.6.2
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: A ruby client for the semq message queue service.
|
65
|
+
test_files: []
|
66
|
+
|