railway-ipc 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/railway_ipc/consumer/consumer.rb +14 -13
- data/lib/railway_ipc/rabbitmq/adapter.rb +4 -2
- data/lib/railway_ipc/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab62556fdb38e6d714ae0eeaf2210fc39c6611e5a193734b0edb44b18851edf1
|
4
|
+
data.tar.gz: be864c9a46dcb21e120fab860781189fbfea59f72a9f563ac68146df84b23b69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 225b0aded5a0880fbae40da74823707fea29741d98c13b4fedb9e80e7df9acc0e00c8a9d711df6a949b5bf7ac8898a5e3f0be7897c30a5068326fdc5d2ce9015
|
7
|
+
data.tar.gz: 235bb3d12d988761fffa79128d6cb4e4f68bec15856ca6fcc4262312d025ea840cf1f5a948c34ac83607981ff6f63857260e071a5edac240aaa88c4dd5e56b28
|
@@ -5,7 +5,7 @@ require "railway_ipc/consumer/consumer_response_handlers"
|
|
5
5
|
module RailwayIpc
|
6
6
|
class Consumer
|
7
7
|
include Sneakers::Worker
|
8
|
-
attr_reader :message, :handler, :
|
8
|
+
attr_reader :message, :handler, :protobuf_message, :delivery_info, :decoded_payload, :encoded_message
|
9
9
|
|
10
10
|
def self.listen_to(queue:, exchange:)
|
11
11
|
from_queue queue,
|
@@ -26,16 +26,17 @@ module RailwayIpc
|
|
26
26
|
def work_with_params(payload, delivery_info, _metadata)
|
27
27
|
@delivery_info = delivery_info
|
28
28
|
@decoded_payload = RailwayIpc::Rabbitmq::Payload.decode(payload)
|
29
|
+
@encoded_message = payload
|
29
30
|
|
30
31
|
case decoded_payload.type
|
31
32
|
when *registered_handlers
|
32
33
|
@handler = handler_for(decoded_payload)
|
33
34
|
message_klass = message_handler_for(decoded_payload)
|
34
|
-
@
|
35
|
+
@protobuf_message = message_klass.decode(decoded_payload.message)
|
35
36
|
process_known_message_type
|
36
37
|
else
|
37
38
|
@handler = RailwayIpc::NullHandler.new
|
38
|
-
@
|
39
|
+
@protobuf_message = RailwayIpc::BaseMessage.decode(decoded_payload.message)
|
39
40
|
process_unknown_message_type
|
40
41
|
end
|
41
42
|
|
@@ -51,8 +52,8 @@ module RailwayIpc
|
|
51
52
|
|
52
53
|
private
|
53
54
|
|
54
|
-
def
|
55
|
-
if handler.handle(
|
55
|
+
def process_protobuf!(message)
|
56
|
+
if handler.handle(protobuf_message).success?
|
56
57
|
message.status = RailwayIpc::ConsumedMessage::STATUSES[:success]
|
57
58
|
else
|
58
59
|
message.status = RailwayIpc::ConsumedMessage::STATUSES[:failed_to_process]
|
@@ -62,15 +63,15 @@ module RailwayIpc
|
|
62
63
|
end
|
63
64
|
|
64
65
|
def process_known_message_type
|
65
|
-
message = RailwayIpc::ConsumedMessage.find_by(uuid:
|
66
|
+
message = RailwayIpc::ConsumedMessage.find_by(uuid: protobuf_message.uuid)
|
66
67
|
|
67
68
|
if message && message.processed?
|
68
69
|
handler.ack!
|
69
70
|
elsif message && !message.processed?
|
70
|
-
message.with_lock("FOR UPDATE NOWAIT") {
|
71
|
+
message.with_lock("FOR UPDATE NOWAIT") { process_protobuf!(message) }
|
71
72
|
else
|
72
73
|
message = create_message_with_status!(RailwayIpc::ConsumedMessage::STATUSES[:processing])
|
73
|
-
message.with_lock("FOR UPDATE NOWAIT") {
|
74
|
+
message.with_lock("FOR UPDATE NOWAIT") { process_protobuf!(message) }
|
74
75
|
end
|
75
76
|
|
76
77
|
nil
|
@@ -79,7 +80,7 @@ module RailwayIpc
|
|
79
80
|
def process_unknown_message_type
|
80
81
|
handler.ack!
|
81
82
|
|
82
|
-
if RailwayIpc::ConsumedMessage.exists?(uuid:
|
83
|
+
if RailwayIpc::ConsumedMessage.exists?(uuid: protobuf_message.uuid)
|
83
84
|
return
|
84
85
|
else
|
85
86
|
create_message_with_status!(RailwayIpc::ConsumedMessage::STATUSES[:unknown_message_type])
|
@@ -90,14 +91,14 @@ module RailwayIpc
|
|
90
91
|
|
91
92
|
def create_message_with_status!(status)
|
92
93
|
RailwayIpc::ConsumedMessage.create!(
|
93
|
-
uuid:
|
94
|
+
uuid: protobuf_message.uuid,
|
94
95
|
status: status,
|
95
96
|
message_type: decoded_payload.type,
|
96
|
-
user_uuid:
|
97
|
-
correlation_id:
|
97
|
+
user_uuid: protobuf_message.user_uuid,
|
98
|
+
correlation_id: protobuf_message.correlation_id,
|
98
99
|
queue: delivery_info.consumer.queue.name,
|
99
100
|
exchange: delivery_info.exchange,
|
100
|
-
encoded_message:
|
101
|
+
encoded_message: encoded_message
|
101
102
|
)
|
102
103
|
end
|
103
104
|
|
@@ -18,14 +18,16 @@ module RailwayIpc
|
|
18
18
|
@queue_name = queue_name
|
19
19
|
@exchange_name = exchange_name
|
20
20
|
settings = AMQ::Settings.parse_amqp_url(amqp_url)
|
21
|
+
vhost = settings[:vhost] || '/'
|
21
22
|
@connection = Bunny.new({
|
22
23
|
host: settings[:host],
|
23
24
|
user: settings[:user],
|
24
25
|
pass: settings[:pass],
|
25
26
|
port: settings[:port],
|
27
|
+
vhost: vhost,
|
26
28
|
automatic_recovery: false,
|
27
|
-
logger: RailwayIpc.bunny_logger
|
28
|
-
|
29
|
+
logger: RailwayIpc.bunny_logger
|
30
|
+
}.merge(options))
|
29
31
|
end
|
30
32
|
|
31
33
|
def publish(message, options = {})
|
data/lib/railway_ipc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: railway-ipc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ''
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -281,8 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
281
281
|
- !ruby/object:Gem::Version
|
282
282
|
version: '0'
|
283
283
|
requirements: []
|
284
|
-
|
285
|
-
rubygems_version: 2.7.6.2
|
284
|
+
rubygems_version: 3.0.3
|
286
285
|
signing_key:
|
287
286
|
specification_version: 4
|
288
287
|
summary: IPC components for Rails
|