jackhammer 0.1.1 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 232498851115b9f31c67a674fd67bb003fed1913c217eb0b1bd8418ea04ff804
4
- data.tar.gz: febc0c5efee22668cf8c747eda637c50f53d7b307ae58376fce753ad34981f04
3
+ metadata.gz: 7cee97f6076b1008ddb323c8c43c87680cb334482569107992ac683c869fea7f
4
+ data.tar.gz: ee0aa15bb52690dba58a1145878d9d81fd1c33e3a802ef1290ee1fb584466898
5
5
  SHA512:
6
- metadata.gz: 97135ef2215f4a5d9ae1a584287c01d1f3067f555a488ebc18d1692bcaa6fd8350ff4e0391bf9b10d7345f904364c071f8bc9669415f77263bd446bbb43e5be2
7
- data.tar.gz: d21958748db93bd0dba6553374f58d7ced4ecec880f3203cec0385a4f0e4fd1d0555cdb8c02ee8cb4703f8aafe34402c0d3dfdddd9fd6067b8ebadc6848fab36
6
+ metadata.gz: 0d2d839de4fc36c47958b86b2f9e8f7857535b640ea86852ced3d4c79b93eb7c5e550035be7364e9a7f7b4e78c094bca93190c19322cf585b8dc483d1cb7ea0a
7
+ data.tar.gz: 9eb24d185af0730c0f17cb2fd8094d06604e5cb7548a44e6a2e1d1d0710970bef920e14455b38eaee447df4265c21de4529ddc85c31049c14b5536050d8411cf
data/.travis.yml CHANGED
@@ -5,4 +5,5 @@ cache: bundler
5
5
  rvm:
6
6
  - 2.5
7
7
  - 2.6
8
+ - ruby-head
8
9
  before_install: gem install bundler -v 2.0.2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jackhammer (0.1.1)
4
+ jackhammer (0.2.0)
5
5
  bunny (~> 2.14)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ [![Build Status](https://travis-ci.org/RenoFi/jackhammer.svg?branch=master)](https://travis-ci.org/RenoFi/jackhammer)
2
+ [![GitHub issues](https://img.shields.io/github/issues/renofi/jackhammer)](https://github.com/renofi/jackhammer/issues)
3
+ [![GitHub license](https://img.shields.io/github/license/renofi/jackhammer)](https://github.com/RenoFi/jackhammer/blob/master/LICENSE.txt)
4
+
1
5
  # Jackhammer
2
6
 
3
7
  Jackhammer is an opinionated, configurable facade over the RabbitMQ Bunny
@@ -7,9 +11,7 @@ module.
7
11
 
8
12
  Add this line to your application's Gemfile:
9
13
 
10
- ```ruby
11
- gem 'jackhammer'
12
- ```
14
+ gem 'jackhammer'
13
15
 
14
16
  And then execute:
15
17
 
@@ -21,10 +23,12 @@ Or install it yourself as:
21
23
 
22
24
  ## Usage
23
25
 
26
+ ### Quick Start
27
+
24
28
  Create a YAML file to configure topics and queues your Jackhammer::Server instance
25
29
  will subscribe to when using the executable.
26
30
 
27
- ```YAML
31
+ ```yaml
28
32
  # config/jackhammer.yml
29
33
  ---
30
34
  default: &default
@@ -42,7 +46,7 @@ default: &default
42
46
  development:
43
47
  <<: *default
44
48
 
45
- development:
49
+ test:
46
50
  <<: *default
47
51
 
48
52
  production:
@@ -51,20 +55,21 @@ production:
51
55
 
52
56
  Configure your subscription server by sublcassing `Jackhammer::Server`.
53
57
 
54
- ```Ruby
58
+ ```ruby
55
59
  # config/application.rb
56
60
  require 'jackhammer'
57
61
 
58
62
  module MyApp
59
63
  class Server < Jackhammer::Server
60
- Jackhammer.configure do |jack|
61
- jack.connection_options = {}
62
- jack.connection_url = nil
63
- jack.environment = ENV['RACK_ENV'] || :development
64
- jack.exception_adapter = NullExceptionAdapter.new
65
- jack.logger = Logger.new(IO::NULL)
66
- jack.publish_options = { mandatory: true, persistent: true }
67
- jack.yaml_config = "config/jackhammer.yml"
64
+ configure do |config|
65
+ # these are the default options
66
+ config.connection_options = {}
67
+ config.connection_url = nil
68
+ config.environment = ENV['RACK_ENV'] || :development
69
+ config.exception_adapter = proc { |e| raise e }
70
+ config.logger = Logger.new(IO::NULL)
71
+ config.publish_options = { mandatory: true, persistent: true }
72
+ config.yaml_config = "config/jackhammer.yml"
68
73
  end
69
74
  end
70
75
  end
@@ -72,9 +77,74 @@ end
72
77
 
73
78
  Start the subscription server to read the YAML and subscribe to topic queues.
74
79
 
80
+ $ bundle exec jackhammer
81
+
82
+ ### Topic Exchange Configuration
83
+
84
+ The YAML file configures [RabbitMQ Topic Exchanges](https://www.rabbitmq.com/tutorials/amqp-concepts.html#exchange-topic).
85
+
86
+ At the root are environment names used to load environment specific
87
+ configuration. Below that are the names of topic exchanges. Each topic exchange
88
+ can define `durable` and `auto_delete` options used when creating the exchange.
89
+ Additionally, each topic exchange defines a `queues` mapping. Each mapping
90
+ nested under the `queues` key represents options used by either Jackhammer or
91
+ Bunny.
92
+
93
+ Exchange topic queue options passed to Bunny during [queue initialization](http://reference.rubybunny.info/Bunny/Queue.html#initialize-instance_method):
94
+
95
+ - **durable** default: false — Should this queue be durable?
96
+ - **auto_delete** default: false — Should this queue be automatically deleted when the last consumer disconnects?
97
+ - **exclusive** default: false — Should this queue be exclusive (only can be used by this connection, removed when the connection is closed)?
98
+
99
+ The **routing_key** is used as an option when binding the Bunny::Queue and
100
+ Bunny::Exchange.
101
+
102
+ Exchange topic queue options used by Jackhammer:
103
+
104
+ - **handler** A string representing the name of a class that is intended to
105
+ receive messages delivered to the queue subscriber.
106
+
107
+ The handler class must implement at least a `.call` method. If the class
108
+ responds to `.perform_async` then that will be called instead of `.call`.
109
+
110
+ ```ruby
111
+ module MyApp
112
+ class SouthAmericaHandler
113
+ def self.call(message)
114
+ puts message
115
+ end
116
+ end
117
+ end
75
118
  ```
76
- $ bundle exec jackhammer -r config/application.rb
77
- ```
119
+
120
+ ### Executable
121
+
122
+ By default the executable will load `config/application.rb`. If you define
123
+ and configure your Jackhammer server somewhere else, use the `-r path/file.rb`
124
+ option on the command line.
125
+
126
+ $ bundle exec jackhammer -r config/rabbitmq_application.rb
127
+
128
+ ### Server Configuration
129
+
130
+ The `configure` block must be placed inside of your application class even if
131
+ you choose not to change any default configuration.
132
+
133
+ The intent of the options might not be obvious by looking at the name.
134
+ - **connection_options** passed into `Bunny.new`.
135
+ - **connection_url** passed into `Bunny.new`.
136
+ - **environment** specifies the section of YAML config to load.
137
+ - **exception_adapter** exceptions caught when handling received messages are
138
+ forwarded to the adapter object. The adapter must implement
139
+ `.call(exception)`.
140
+ - **logger** defines a logger the Jackhammer module should use.
141
+ - **publish_options** defines options passed to all messages published (can be
142
+ overridden by passing the same options as arguments in your code).
143
+ - **yaml_config** defines the file location of the Topic Exchange YAML
144
+ configuration file.
145
+
146
+ You can find defaults specified in the Jackhammer::Configuration class
147
+ constructor.
78
148
 
79
149
  ## Development
80
150
 
@@ -84,7 +154,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
84
154
 
85
155
  ## Contributing
86
156
 
87
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jackhammer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
157
+ Bug reports and pull requests are welcome on GitHub at https://github.com/renofi/jackhammer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
88
158
 
89
159
  ## License
90
160
 
data/jackhammer.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'jackhammer'
5
+ require 'jackhammer/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'jackhammer'
data/lib/jackhammer.rb CHANGED
@@ -6,13 +6,11 @@ require 'yaml'
6
6
  require 'bunny'
7
7
  require 'jackhammer/version'
8
8
  require 'jackhammer/log'
9
- require 'jackhammer/null_exception_adapter'
10
9
  require 'jackhammer/configuration'
11
10
  require 'jackhammer/message_receiver'
12
11
  require 'jackhammer/queue'
13
12
  require 'jackhammer/topic'
14
13
  require 'jackhammer/topic_manager'
15
- require 'jackhammer/publish'
16
14
  require 'jackhammer/server'
17
15
 
18
16
  module Jackhammer
@@ -17,7 +17,7 @@ module Jackhammer
17
17
  @connection_options = {}
18
18
  @connection_url = ENV['RABBITMQ_URL']
19
19
  @environment = ENV['RACK_ENV'] || :development
20
- @exception_adapter = NullExceptionAdapter.new
20
+ @exception_adapter = proc { |e| raise e }
21
21
  @logger = Logger.new IO::NULL
22
22
  @publish_options = { mandatory: true, persistent: true }
23
23
  @yaml_config = './config/jackhammer.yml'
@@ -13,7 +13,7 @@ module Jackhammer
13
13
  @handler_object.call content
14
14
  rescue StandardError => e
15
15
  Log.error e
16
- Jackhammer.configuration.exception_adapter.capture e
16
+ Jackhammer.configuration.exception_adapter.call e
17
17
  end
18
18
  end
19
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jackhammer
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jackhammer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Serok
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-13 00:00:00.000000000 Z
11
+ date: 2019-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -149,8 +149,6 @@ files:
149
149
  - lib/jackhammer/configuration.rb
150
150
  - lib/jackhammer/log.rb
151
151
  - lib/jackhammer/message_receiver.rb
152
- - lib/jackhammer/null_exception_adapter.rb
153
- - lib/jackhammer/publish.rb
154
152
  - lib/jackhammer/queue.rb
155
153
  - lib/jackhammer/server.rb
156
154
  - lib/jackhammer/topic.rb
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jackhammer
4
- class NullExceptionAdapter
5
- # does nothing with any rescued exceptions
6
- def capture(_); end
7
- end
8
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jackhammer
4
- # The API to send messages to a topic with a given attribute
5
- class Publish
6
- class << self
7
- def topics
8
- @topics ||= {}
9
- end
10
-
11
- def publish(event, message, options)
12
- publish_options = Jackhammer.configuration.publish_options # system defaults
13
- publish_options[:routing_key] = event # routing_key
14
- publish_options = publish_options.merge options # override any system defaults
15
- Jackhammer.connection.publish message, publish_options
16
- end
17
- end
18
- end
19
- end