bug_bunny 2.0.0 → 2.0.1
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 +4 -4
- data/README.md +164 -1
- data/lib/bug_bunny/rabbit.rb +2 -2
- data/lib/bug_bunny/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 074005f6739a5a8486230e47edbce60b9719f5e15f35d9ab3ed95d91eaf28a47
|
|
4
|
+
data.tar.gz: 39f1d8afb65be6ff2b86e0461c16c93e0ff6ae6cbe629668ba8e6601fe898e80
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 88e99f4d71b1bb78599cf7a1750218cf5fde2e9ccb010c1aa671d1ba5e1ffe011a9bc70c39fe284b150d6fb497827e94766a82085a3758308990e57eb0f0b5da
|
|
7
|
+
data.tar.gz: 66acaa871a7f5adabf4135c3b84216f71072be0f9bc7f76c4e42247dde064709596c78b88fed32c9bd24bc47a6ba737d54bc7c3396509f4dae61f06c69d026fd
|
data/README.md
CHANGED
|
@@ -1,9 +1,172 @@
|
|
|
1
1
|
# BugBunny
|
|
2
2
|
|
|
3
|
+
## Configuration
|
|
4
|
+
|
|
5
|
+
```ruby
|
|
6
|
+
config/initializers/bug_bunny.rb
|
|
7
|
+
BugBunny.configure do |config|
|
|
8
|
+
config.host = 'Host'
|
|
9
|
+
config.username = 'Username'
|
|
10
|
+
config.password = 'Password'
|
|
11
|
+
config.vhost = '/'
|
|
12
|
+
config.logger = Rails.logger
|
|
13
|
+
config.automatically_recover = false
|
|
14
|
+
config.network_recovery_interval = 5
|
|
15
|
+
config.connection_timeout = 10
|
|
16
|
+
config.read_timeout = 30
|
|
17
|
+
config.write_timeout = 30
|
|
18
|
+
config.heartbeat = 15
|
|
19
|
+
config.continuation_timeout = 15_000
|
|
20
|
+
end
|
|
21
|
+
```
|
|
22
|
+
|
|
3
23
|
## Publish
|
|
4
24
|
|
|
25
|
+
### Rutas
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
# config/rabbit_rest.yml
|
|
29
|
+
default: &default
|
|
30
|
+
healt_check:
|
|
31
|
+
up: 'healt_check/up'
|
|
32
|
+
manager:
|
|
33
|
+
services:
|
|
34
|
+
index: 'services/index'
|
|
35
|
+
create: 'services/create'
|
|
36
|
+
show: 'services/%<id>s/show'
|
|
37
|
+
update: 'services/%<id>s/update'
|
|
38
|
+
destroy: 'services/%<id>s/destroy'
|
|
39
|
+
swarm:
|
|
40
|
+
info: 'swarm/info'
|
|
41
|
+
version: 'swarm/version'
|
|
42
|
+
swarm: 'swarm/swarm'
|
|
43
|
+
tasks:
|
|
44
|
+
index: 'tasks/index'
|
|
45
|
+
|
|
46
|
+
development:
|
|
47
|
+
<<: *default
|
|
48
|
+
|
|
49
|
+
test:
|
|
50
|
+
<<: *default
|
|
51
|
+
|
|
52
|
+
production:
|
|
53
|
+
<<: *default
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Configuration
|
|
58
|
+
|
|
59
|
+
```ruby
|
|
60
|
+
# config/initializers/bug_bunny.rb
|
|
61
|
+
BUG_BUNNY_ENDPOINTS = Rails.application.config_for(:rabbit_rest)
|
|
62
|
+
|
|
63
|
+
BUNNY_POOL = ConnectionPool.new(size: RABBIT_MAX_THREADS) do
|
|
64
|
+
BugBunny::Rabbit.create_connection(host: RABBIT_HOST, username: RABBIT_USER, password: RABBIT_PASS, vhost: RABBIT_VIRTUAL_HOST)
|
|
65
|
+
end
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Publisher
|
|
69
|
+
|
|
70
|
+
Creamos cualquier clase que herede de `BugBunny::Publisher`, luego definimos metodos de clase y dentro de cada una de ella su implementacion
|
|
71
|
+
|
|
72
|
+
1. Mensajes sincronicos
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
class Rabbit::Publisher::Manager < BugBunny::Publisher
|
|
76
|
+
ROUTING_KEY = :manager
|
|
77
|
+
ROUTES = BUG_BUNNY_ENDPOINTS[:manager][:swarm]
|
|
78
|
+
|
|
79
|
+
def self.info(exchange:, message: nil)
|
|
80
|
+
obj = new(pool: NEW_BUNNY_POOL, exchange_name: exchange, action: self::ROUTES[:info], message: message)
|
|
81
|
+
obj.publish_and_consume!
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def self.version(exchange:, message: nil)
|
|
85
|
+
obj = new(pool: NEW_BUNNY_POOL, exchange_name: exchange, action: self::ROUTES[:version], message: message)
|
|
86
|
+
obj.publish_and_consume!
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
2. Mensajes Asincronicos
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
class Rabbit::Publisher::Manager < BugBunny::Publisher
|
|
95
|
+
ROUTING_KEY = :manager
|
|
96
|
+
ROUTES = BUG_BUNNY_ENDPOINTS[:manager][:swarm]
|
|
97
|
+
|
|
98
|
+
def self.info(exchange:, message: nil)
|
|
99
|
+
obj = new(pool: NEW_BUNNY_POOL, exchange_name: exchange, action: self::ROUTES[:info], message: message)
|
|
100
|
+
obj.publish!
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def self.version(exchange:, message: nil)
|
|
104
|
+
obj = new(pool: NEW_BUNNY_POOL, exchange_name: exchange, action: self::ROUTES[:version], message: message)
|
|
105
|
+
obj.publish!
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
3. Attributes del objeto BugBunny::Publisher
|
|
111
|
+
|
|
112
|
+
- content_type
|
|
113
|
+
- content_encoding
|
|
114
|
+
- correlation_id
|
|
115
|
+
- reply_to
|
|
116
|
+
- message_id
|
|
117
|
+
- timestamp
|
|
118
|
+
- priority
|
|
119
|
+
- expiration
|
|
120
|
+
- user_id
|
|
121
|
+
- app_id
|
|
122
|
+
- action
|
|
123
|
+
- aguments
|
|
124
|
+
- cluster_id
|
|
125
|
+
- persistent
|
|
126
|
+
- expiration
|
|
127
|
+
|
|
5
128
|
## Consumer
|
|
6
129
|
|
|
130
|
+
```
|
|
131
|
+
class Rabbit::Controllers::Application < BugBunny::Controller
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
class Rabbit::Controllers::Swarm < Rabbit::Controllers::Application
|
|
135
|
+
def info
|
|
136
|
+
render status: :ok, json: Api::Docker.info
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def version
|
|
140
|
+
render status: :ok, json: Api::Docker.version
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def swarm
|
|
144
|
+
render status: :ok, json: Api::Docker.swarm
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Resource
|
|
151
|
+
Solo para recursos que se adaptan al crud de rails estoy utilizando automaticamente la logica de los publicadores. Los atributos solo se ponen si son necesarios, si no la dejas vacia y actua igual que active resource.
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
class Manager::Application < BugBunny::Resource
|
|
155
|
+
self.resource_path = 'rabbit/publisher/manager'
|
|
156
|
+
|
|
157
|
+
attribute :id # 'ID'
|
|
158
|
+
attribute :version # 'Version'
|
|
159
|
+
attribute :created_at # 'CreatedAt'
|
|
160
|
+
attribute :update_at # 'UpdatedAt'
|
|
161
|
+
attribute :spec # 'Spec'
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
class Manager::Service < Manager::Application
|
|
165
|
+
attribute :endpoint # 'Endpoint'
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
|
|
7
170
|
## Exceptions
|
|
8
171
|
- Error General:
|
|
9
172
|
- `BugBunny::Error` hereda de `::StandardError` (Captura cualquier error de la gema.)
|
|
@@ -16,5 +179,5 @@
|
|
|
16
179
|
- `BugBunny::ResponseError::NotFound`
|
|
17
180
|
- `BugBunny::ResponseError::NotAcceptable`
|
|
18
181
|
- `BugBunny::ResponseError::RequestTimeout`
|
|
19
|
-
- `BugBunny::ResponseError::UnprocessableEntity
|
|
182
|
+
- `BugBunny::ResponseError::UnprocessableEntity`: En este el error viene el error details a lo rails.
|
|
20
183
|
- `BugBunny::ResponseError::InternalServerError`
|
data/lib/bug_bunny/rabbit.rb
CHANGED
|
@@ -137,11 +137,11 @@ module BugBunny
|
|
|
137
137
|
Rails.logger.debug("PUBLISHER Options: #{options}")
|
|
138
138
|
publish!(msg, options)
|
|
139
139
|
|
|
140
|
-
if response_latch.wait(
|
|
140
|
+
if response_latch.wait(RABBIT_CONNECTION_TIMEOUT)
|
|
141
141
|
subscription.cancel
|
|
142
142
|
build_response(status: response[:status], body: response[:body])
|
|
143
143
|
else
|
|
144
|
-
raise "Timeout: No response received within #{
|
|
144
|
+
raise "Timeout: No response received within #{RABBIT_CONNECTION_TIMEOUT} seconds."
|
|
145
145
|
end
|
|
146
146
|
rescue BugBunny::ResponseError::Base => e
|
|
147
147
|
subscription&.cancel
|
data/lib/bug_bunny/version.rb
CHANGED