message-sqs 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/message-sqs.rb +22 -7
  3. metadata +9 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d088a20f4518bdd6126ad3965f79d57db2d6136
4
- data.tar.gz: 67579f42d7297f4ecd0764b8db158727e33b5bef
3
+ metadata.gz: 5f20c334a51903533a4750205b6a4715e693365f
4
+ data.tar.gz: 08ecaf9eb782ef294708b7262edba16c801b5072
5
5
  SHA512:
6
- metadata.gz: f464d2db206111d716cbd4aa9d50a43ba3cb9914d6c6eb0cb16b41b81eb8cd088cf76cd907a97e88cbdb98d0643984e01430262969e45d66be4fadf202a5ca35
7
- data.tar.gz: d5ebf3f905b12d38158ad321f25c1cb9d8173c4b8b6af1b3824ed671719a225c259a6d176bd746d384ce66e948830bfd0637c7bfa2a8fd1b7b8a8519f1fc2ed5
6
+ metadata.gz: 0f2215267b1e8677573b26451849b0d1814d9f664c278159d0dceea98fc2cf0316661b7eb1a8adb5fd2799c46f7818de1997b8c8206e01e2629c1d00502db613
7
+ data.tar.gz: bab4cdb1db2313563c4d736ca98a9ce323440f8f13e8d7938ebc86795b90a41bc2fcbaa702a105873a7ea72129d437e6233e7588094b7c9793d732ee0357c123
@@ -1,27 +1,42 @@
1
- require 'aws/sqs'
1
+ require 'aws-sdk'
2
2
  require 'message'
3
3
 
4
4
  class MessageSqs
5
5
 
6
6
  attr_reader :name
7
- def initialize(name)
7
+ # options:
8
+ # => :create_queue, default true
9
+ def initialize(name, options={})
8
10
  @name = name
9
- @queue = AWS::SQS.new.queues.create(@name)
11
+ @client = Aws::SQS::Client.new
12
+ @queue_url = options[:queue_url] || @client.create_queue(:queue_name => @name)[:queue_url]
10
13
  end
11
14
 
12
15
  def enq(msg)
13
- @queue.send_message(msg)
16
+ @client.send_message(req_params(:message_body => msg))
14
17
  end
15
18
  alias :<< :enq
16
19
 
17
20
  def deq(size=1, &block)
18
- @queue.receive_message(:limit => size) do |msg|
19
- block.call(msg.body)
21
+ msgs = @client.receive_message(req_params(:max_number_of_messages => size))
22
+ Array(msgs[:messages]).each do |msg|
23
+ begin
24
+ block.call(msg[:body])
25
+ ensure
26
+ @client.delete_message(req_params(:receipt_handle => msg[:receipt_handle]))
27
+ end
20
28
  end
21
29
  end
22
30
 
23
31
  def size
24
- @queue.approximate_number_of_messages
32
+ attr_name = 'ApproximateNumberOfMessages'
33
+ ret = @client.get_queue_attributes(req_params(:attribute_names => [attr_name]))
34
+ ret[:attributes][attr_name].to_i
35
+ end
36
+
37
+ private
38
+ def req_params(params)
39
+ {:queue_url => @queue_url}.merge(params)
25
40
  end
26
41
  end
27
42
 
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: message-sqs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiao Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-10 00:00:00.000000000 Z
11
+ date: 2015-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.43.3
19
+ version: '2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.43.3
26
+ version: '2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: message
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.1
33
+ version: 0.0.8
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.0.1
40
+ version: 0.0.8
41
41
  description: |
42
42
  Hook up AWS SQS with Message background/asynchronous job processing mechanism.
43
43
  email:
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  version: '0'
69
69
  requirements: []
70
70
  rubyforge_project:
71
- rubygems_version: 2.2.0
71
+ rubygems_version: 2.2.2
72
72
  signing_key:
73
73
  specification_version: 4
74
74
  summary: Message SQS queue adapter.