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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 945917b242216c009d199f73de3c559b16b005cdae28504273b2ee68d04ed8df
4
- data.tar.gz: 39bc88b82f608a2a74de630c334bd6a7021a92666e8843fc4ba81e3f1b3a2b03
3
+ metadata.gz: ab62556fdb38e6d714ae0eeaf2210fc39c6611e5a193734b0edb44b18851edf1
4
+ data.tar.gz: be864c9a46dcb21e120fab860781189fbfea59f72a9f563ac68146df84b23b69
5
5
  SHA512:
6
- metadata.gz: 42425f432289124825d92ec02bc3350875070da6554c824fc4cb9f802d961817ae65980b6011566be24696abbecf6613e48166373e5d6476e1cf6498ae64057a
7
- data.tar.gz: 9d09e840a91d94a02e4551fa44f2d653e40e716e4606288649320709d54c47cccc8240268b38a550466b92ebd0882f4718bd271256ca520b735d283cbbcd3294
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, :protobuff_message, :delivery_info, :decoded_payload
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
- @protobuff_message = message_klass.decode(decoded_payload.message)
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
- @protobuff_message = RailwayIpc::BaseMessage.decode(decoded_payload.message)
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 process_protobuff!(message)
55
- if handler.handle(protobuff_message).success?
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: protobuff_message.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") { process_protobuff!(message) }
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") { process_protobuff!(message) }
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: protobuff_message.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: protobuff_message.uuid,
94
+ uuid: protobuf_message.uuid,
94
95
  status: status,
95
96
  message_type: decoded_payload.type,
96
- user_uuid: protobuff_message.user_uuid,
97
- correlation_id: protobuff_message.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: decoded_payload.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}.merge(options)
28
- )
29
+ logger: RailwayIpc.bunny_logger
30
+ }.merge(options))
29
31
  end
30
32
 
31
33
  def publish(message, options = {})
@@ -1,3 +1,3 @@
1
1
  module RailwayIpc
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
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
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-01-27 00:00:00.000000000 Z
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
- rubyforge_project:
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