rmsg 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 384ab1300d4295b580a206f3607756bb2f3dc54b
4
- data.tar.gz: 44032af1a2b53f8b9ec0aac81da5b255b3b01af4
3
+ metadata.gz: d584ea38af8db2b4492bc2f4ac94b2cb9688e489
4
+ data.tar.gz: 51cb5b1e0d85825525be13e078757caadb5a5009
5
5
  SHA512:
6
- metadata.gz: 358b8c438fcd876e91a25dfec69a0492893be5e65f3780e3d2394c9c4c085445ff1645394a40ab0b9afc1975ec469b44aeb197f7e9653401ce440b98c7764c3c
7
- data.tar.gz: 981c1c80528e67ca5f6c9ffb6ed38fa20a2b03cea470a145452bc9f805298fbec27a6e6ff48e381eede4d73d6a35e08ac328843bf1139f05b5c5c995df13fe28
6
+ metadata.gz: 27c5e065f5f75924352f4b1f774dcbcc0e26745a3854e07a6fab12162c313036070d5f14fe16ca1f3b0f773fcf8542c10dc55cd8b8d55dbf53cbffc0b2846cd5
7
+ data.tar.gz: 63703855f633d97edcc1d4a4b7db89aaf1ee5a36a4cc2ac07cae9cca6efe64e31bc881d526e0cedcd1328a5802cb8bccd9ef788f9034e2b7eb012c480c8f6c2b
@@ -1,13 +1,19 @@
1
1
  module Rmsg
2
2
  class Rabbit
3
- attr_reader :connection, :channel
3
+ # @return [Bunny::Connection]
4
+ attr_reader :connection
5
+ # @return [Bunny::Channel]
6
+ attr_reader :channel
4
7
 
8
+ # On creation holds references to RabbitMQ via
9
+ # a Bunny connection and a Bunny channel.
5
10
  def initialize
6
11
  @connection = Bunny.new
7
12
  @connection.start
8
13
  @channel = @connection.create_channel
9
14
  end
10
15
 
16
+ # Close the channel and the connection to RabbitMQ.
11
17
  def close
12
18
  @channel.close
13
19
  @connection.close
@@ -1,14 +1,30 @@
1
1
  module Rmsg
2
+ # Task handles publishing tasks and processing them.
2
3
  class Task
4
+ # When initializing a task handler, the queue
5
+ # will be declared durable, to survive RabbitMQ restarts.
6
+ # @param params [Hash]
7
+ # * :rabbit [Rmsg::Rabbit] Example: Rmsg::Rabbit.new
8
+ # * :queue [String] Example: 'messages'
3
9
  def initialize(params)
4
10
  @rabbit = params[:rabbit]
5
11
  @queue = @rabbit.channel.queue(params[:queue], durable: true)
6
12
  end
7
13
 
14
+ # Publish a message in the tasks queue.
15
+ # It is marked a persistent to survive RabbitMQ restarts.
16
+ # @param message [Hash] The message to be consumed.
8
17
  def publish(message)
9
18
  @queue.publish(message.to_json, presistent: true)
10
19
  end
11
20
 
21
+ # Subscribe to the tasks queue.
22
+ # Subscribing happens by continuously blocking the current process.
23
+ # It is specifically designed for long running processes.
24
+ # When receiving INT it will gracefully close.
25
+ # Consumer processes have a prefetch value of 1 for round-robin distribution.
26
+ # Consumer processes will send a manual ack after processing, to avoid losing tasks.
27
+ # @yield message [Hash] A block to process the message received.
12
28
  def subscribe
13
29
  @rabbit.channel.prefetch(1)
14
30
  begin
@@ -1,14 +1,29 @@
1
1
  module Rmsg
2
+ # Topic handles publishing and subscribing
3
+ # to a topic with a key, over RabbitMQ.
2
4
  class Topic
5
+ # @param params [Hash]
6
+ # * :rabbit [Rmsg::Rabbit] Example: Rmsg::Rabbit.new
7
+ # * :topic [String] Example: 'services'
3
8
  def initialize(params)
4
9
  @rabbit = params[:rabbit]
5
10
  @exchange = @rabbit.channel.topic(params[:topic])
6
11
  end
7
12
 
13
+ # Publish a message with a routing key.
14
+ # @param message [Hash] Example: {id: 1, key: 'xxxccc'}
15
+ # @param key [String] Example: 'users.key_changed'
16
+ # @return [Exchange] The exchange used to publish.
8
17
  def publish(message, key)
9
18
  @exchange.publish(message.to_json, :routing_key => key)
10
19
  end
11
20
 
21
+ # Subscribe to the topic, listening for a specific key.
22
+ # Subscribing happens by continuously blocking the current process.
23
+ # It is specifically designed for long running processes.
24
+ # When receiving INT it will gracefully close.
25
+ # @param key [String] Example: 'users.key_changed'
26
+ # @yield message [Hash] A block to process the message received.
12
27
  def subscribe(key)
13
28
  @queue = @rabbit.channel.queue("", :exclusive => true)
14
29
  @queue.bind(@exchange, :routing_key => key)
@@ -1,3 +1,3 @@
1
1
  module Rmsg
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "rmsg"
8
8
  spec.version = Rmsg::VERSION
9
9
  spec.authors = ["badshark"]
10
- spec.email = ["info@badshark.io"]
10
+ spec.email = ["marco@badshark.io"]
11
11
  spec.summary = %q{RabbitMQ messaging.}
12
12
  spec.description = %q{RabbitMQ messaging with topics and tasks. A thin, minimal layer on top of Bunny.}
13
13
  spec.homepage = "https://github.com/badshark/rmsg"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmsg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - badshark
@@ -69,7 +69,7 @@ dependencies:
69
69
  description: RabbitMQ messaging with topics and tasks. A thin, minimal layer on top
70
70
  of Bunny.
71
71
  email:
72
- - info@badshark.io
72
+ - marco@badshark.io
73
73
  executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []