hutch 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +14 -0
- data/README.md +45 -0
- data/lib/hutch/broker.rb +10 -6
- data/lib/hutch/cli.rb +8 -0
- data/lib/hutch/config.rb +2 -0
- data/lib/hutch/version.rb +1 -1
- data/lib/hutch/worker.rb +2 -2
- data/spec/hutch/worker_spec.rb +16 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eeb23a1408742881e2fe57465b1ac93ff5f291c7
|
4
|
+
data.tar.gz: a690db26520da645ce2727d70f06757e1db9e161
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 578a80bc3746ceb989bd569f0bbf838f7ceffeae97628fd06705d03a6d10c8945f3916184466ad397ce7f2052df0e1677602f85d5fa8074e5181fb8639ab4662
|
7
|
+
data.tar.gz: d03df05f440e75a3620ce885d004af204fb0adcdf255ba250429d797c9bf02d0dd7d6abf006ef9d1a04e7bf2316de14156c8c6d5dd28b016693ac19b70c4e344
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
## 0.2.0 - September 16, 2013
|
2
|
+
|
3
|
+
- Support for connecting to RabbitMQ with TLS/SSL. There are two new
|
4
|
+
configuration options : `mq-tls` and `mq-api-ssl`.
|
5
|
+
- JSON message parsing errors are now handled properly.
|
6
|
+
|
7
|
+
## 0.1.1 - September 9, 2013
|
8
|
+
|
9
|
+
- Relax Bunny dependency specification
|
10
|
+
|
11
|
+
## 0.1.0 - September 9, 2013
|
12
|
+
|
13
|
+
- Initial release
|
14
|
+
|
data/README.md
CHANGED
@@ -4,6 +4,44 @@ Hutch is a Ruby library for enabling asynchronous inter-service communication
|
|
4
4
|
in a service-oriented architecture, using RabbitMQ.
|
5
5
|
|
6
6
|
|
7
|
+
## Project Maturity
|
8
|
+
|
9
|
+
Hutch is a relatively young project that was extracted from production systems.
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
## Installation & Bundler Dependency
|
14
|
+
|
15
|
+
### Most Recent Release
|
16
|
+
|
17
|
+
[![Gem Version](https://badge.fury.io/rb/hutch.png)](http://badge.fury.io/rb/hutch)
|
18
|
+
|
19
|
+
### With Rubygems
|
20
|
+
|
21
|
+
To install with RubyGems:
|
22
|
+
|
23
|
+
```
|
24
|
+
gem install hutch
|
25
|
+
```
|
26
|
+
|
27
|
+
### Bundler Dependency
|
28
|
+
|
29
|
+
To use in a project managed with Bundler:
|
30
|
+
|
31
|
+
``` ruby
|
32
|
+
gem "hutch", "~> 0.1.1"
|
33
|
+
```
|
34
|
+
|
35
|
+
## Overview
|
36
|
+
|
37
|
+
Hutch is a conventions-based framework for writing services that communicate
|
38
|
+
over RabbitMQ. Hutch is opinionated: it uses topic exchanges for message
|
39
|
+
distribution and makes some assumptions about how consumers and publishers
|
40
|
+
should work.
|
41
|
+
|
42
|
+
Hutch uses [Bunny](http://rubybunny.info) under the hood.
|
43
|
+
|
44
|
+
|
7
45
|
## Defining Consumers
|
8
46
|
|
9
47
|
Consumers receive messages from a RabbitMQ queue. That queue may be bound to
|
@@ -96,6 +134,7 @@ possible, this should be used, rather than directly interfacing with RabbitMQ
|
|
96
134
|
libraries.
|
97
135
|
|
98
136
|
```ruby
|
137
|
+
Hutch.connect
|
99
138
|
Hutch.publish('routing.key', subject: 'payment', action: 'received')
|
100
139
|
```
|
101
140
|
|
@@ -131,6 +170,12 @@ AMQP.connect(host: config[:host]) do |connection|
|
|
131
170
|
end
|
132
171
|
```
|
133
172
|
|
173
|
+
## Supported RabbitMQ Versions
|
174
|
+
|
175
|
+
Hutch requires RabbitMQ 2.x or later. 3.x releases
|
176
|
+
are recommended.
|
177
|
+
|
178
|
+
|
134
179
|
[pc-issue]: https://github.com/ruby-amqp/amqp/issues/92
|
135
180
|
[pc-gist]: https://gist.github.com/3042381
|
136
181
|
|
data/lib/hutch/broker.rb
CHANGED
@@ -36,11 +36,12 @@ module Hutch
|
|
36
36
|
def set_up_amqp_connection
|
37
37
|
host, port, vhost = @config[:mq_host], @config[:mq_port]
|
38
38
|
username, password = @config[:mq_username], @config[:mq_password]
|
39
|
-
vhost = @config[:mq_vhost]
|
39
|
+
vhost, tls = @config[:mq_vhost], @config[:mq_tls]
|
40
|
+
protocol = tls ? "amqps://" : "amqp://"
|
40
41
|
uri = "#{username}:#{password}@#{host}:#{port}/#{vhost.sub(/^\//, '')}"
|
41
|
-
logger.info "connecting to rabbitmq (
|
42
|
+
logger.info "connecting to rabbitmq (#{protocol}#{uri})"
|
42
43
|
|
43
|
-
@connection = Bunny.new(host: host, port: port, vhost: vhost,
|
44
|
+
@connection = Bunny.new(host: host, port: port, vhost: vhost, tls: tls,
|
44
45
|
username: username, password: password,
|
45
46
|
heartbeat: 1, automatically_recover: true,
|
46
47
|
network_recovery_interval: 1)
|
@@ -54,7 +55,7 @@ module Hutch
|
|
54
55
|
@exchange = @channel.topic(exchange_name, durable: true)
|
55
56
|
rescue Bunny::TCPConnectionFailed => ex
|
56
57
|
logger.error "amqp connection error: #{ex.message.downcase}"
|
57
|
-
uri = "
|
58
|
+
uri = "#{protocol}#{host}:#{port}"
|
58
59
|
raise ConnectionError.new("couldn't connect to rabbitmq at #{uri}")
|
59
60
|
rescue Bunny::PreconditionFailed => ex
|
60
61
|
logger.error ex.message
|
@@ -69,12 +70,15 @@ module Hutch
|
|
69
70
|
def set_up_api_connection
|
70
71
|
host, port = @config[:mq_api_host], @config[:mq_api_port]
|
71
72
|
username, password = @config[:mq_username], @config[:mq_password]
|
73
|
+
ssl = @config[:mq_api_ssl]
|
72
74
|
|
73
|
-
|
75
|
+
protocol = ssl ? "https://" : "http://"
|
76
|
+
management_uri = "#{protocol}#{username}:#{password}@#{host}:#{port}/"
|
74
77
|
logger.info "connecting to rabbitmq management api (#{management_uri})"
|
75
78
|
|
76
79
|
@api_client = CarrotTop.new(host: host, port: port,
|
77
|
-
user: username, password: password
|
80
|
+
user: username, password: password,
|
81
|
+
ssl: ssl)
|
78
82
|
@api_client.exchanges
|
79
83
|
rescue Errno::ECONNREFUSED => ex
|
80
84
|
logger.error "api connection error: #{ex.message.downcase}"
|
data/lib/hutch/cli.rb
CHANGED
@@ -96,6 +96,10 @@ module Hutch
|
|
96
96
|
Hutch::Config.mq_port = port
|
97
97
|
end
|
98
98
|
|
99
|
+
opts.on('--mq-tls', 'Set the RabbitMQ connection to use TLS') do |tls|
|
100
|
+
Hutch::Config.mq_tls = tls
|
101
|
+
end
|
102
|
+
|
99
103
|
opts.on('--mq-exchange EXCHANGE',
|
100
104
|
'Set the RabbitMQ exchange') do |exchange|
|
101
105
|
Hutch::Config.mq_exchange = exchange
|
@@ -123,6 +127,10 @@ module Hutch
|
|
123
127
|
Hutch::Config.mq_api_port = port
|
124
128
|
end
|
125
129
|
|
130
|
+
opts.on('--mq-api-ssl', 'Set the RabbitMQ API connection to use SSL') do |api_ssl|
|
131
|
+
Hutch::Config.mq_api_ssl = api_ssl
|
132
|
+
end
|
133
|
+
|
126
134
|
opts.on('--require PATH', 'Require a Rails app or path') do |path|
|
127
135
|
Hutch::Config.require_paths << path
|
128
136
|
end
|
data/lib/hutch/config.rb
CHANGED
@@ -10,10 +10,12 @@ module Hutch
|
|
10
10
|
mq_port: 5672,
|
11
11
|
mq_exchange: 'hutch', # TODO: should this be required?
|
12
12
|
mq_vhost: '/',
|
13
|
+
mq_ssl: false,
|
13
14
|
mq_username: 'guest',
|
14
15
|
mq_password: 'guest',
|
15
16
|
mq_api_host: 'localhost',
|
16
17
|
mq_api_port: 15672,
|
18
|
+
mq_api_ssl: false,
|
17
19
|
log_level: Logger::INFO,
|
18
20
|
require_paths: [],
|
19
21
|
error_handlers: [Hutch::ErrorHandlers::Logger.new]
|
data/lib/hutch/version.rb
CHANGED
data/lib/hutch/worker.rb
CHANGED
@@ -84,13 +84,13 @@ module Hutch
|
|
84
84
|
"consumer: #{consumer}, " +
|
85
85
|
"payload: #{payload}")
|
86
86
|
|
87
|
-
message = Message.new(delivery_info, properties, payload)
|
88
87
|
broker = @broker
|
89
88
|
begin
|
89
|
+
message = Message.new(delivery_info, properties, payload)
|
90
90
|
consumer.new.process(message)
|
91
91
|
broker.ack(delivery_info.delivery_tag)
|
92
92
|
rescue StandardError => ex
|
93
|
-
handle_error(
|
93
|
+
handle_error(properties.message_id, consumer, ex)
|
94
94
|
broker.ack(delivery_info.delivery_tag)
|
95
95
|
end
|
96
96
|
end
|
data/spec/hutch/worker_spec.rb
CHANGED
@@ -75,6 +75,22 @@ describe Hutch::Worker do
|
|
75
75
|
worker.handle_message(consumer, delivery_info, properties, payload)
|
76
76
|
end
|
77
77
|
end
|
78
|
+
|
79
|
+
context "when the payload is not valid json" do
|
80
|
+
let(:payload) { "Not Valid JSON" }
|
81
|
+
|
82
|
+
it 'logs the error' do
|
83
|
+
Hutch::Config[:error_handlers].each do |backend|
|
84
|
+
backend.should_receive(:handle)
|
85
|
+
end
|
86
|
+
worker.handle_message(consumer, delivery_info, properties, payload)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'acknowledges the message' do
|
90
|
+
broker.should_receive(:ack).with(delivery_info.delivery_tag)
|
91
|
+
worker.handle_message(consumer, delivery_info, properties, payload)
|
92
|
+
end
|
93
|
+
end
|
78
94
|
end
|
79
95
|
end
|
80
96
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hutch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Marr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -76,6 +76,7 @@ extensions: []
|
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
78
|
- .gitignore
|
79
|
+
- CHANGELOG.md
|
79
80
|
- Gemfile
|
80
81
|
- Guardfile
|
81
82
|
- README.md
|