messaging 3.5.1 → 3.5.6

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: 441c7c47e5f82c297229ac9651d306554adc0571adf8533d7a98ac07d25223e3
4
- data.tar.gz: 892513550640905f8fe3db14921edc8ea18e4dc6b98c18d632e49bac1a9bdd94
3
+ metadata.gz: 9af5bcee24c4ab1eebcfb97e77a4793431b149e9a00ffd7cfe8d6dfb3985aa02
4
+ data.tar.gz: bc2f7fc37a5b759691c9ea31398304ca0515a5d6e7ee0db7a3eccf4c79e3c534
5
5
  SHA512:
6
- metadata.gz: 029f9c439069df9db00b4adc8f948eeda489498bf9bf5acde6d85f2236b78636d627c7c99e045875cbdfd586da0fc1e68618d5aa378e3c8b2768ec654068434b
7
- data.tar.gz: 4c72b14e9646de2ad2a5898051cb1ee1b20ba3156aabc33d66cd67bede63cb42881308bd28614a199c1678b8c716053b0b68401badcd1a4870fb0811fb57b0c5
6
+ metadata.gz: 278f0251732828f67528b8ce72e7455df587ce18b8a1e68a26f25a43d33516b36f4b0a3e008e3fc785a7f97d73b58946a89b946ff0f34edc8c3c6b5189fe27d4
7
+ data.tar.gz: 5cc743e11eac703f43783db84a2db14e88ddd6cf5a4e4f4d124589894c37edd3f1eb9ab2e07dcd7bb428a5dc0f4aa343f0037c0905cd83a4987f800b7c8be333
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- messaging (3.5.1)
4
+ messaging (3.5.5)
5
5
  activerecord
6
6
  activesupport
7
7
  after_transaction
@@ -56,6 +56,17 @@ module Messaging
56
56
  routes.inline!(&block)
57
57
  end
58
58
 
59
+ def self.without_dispatch(&block)
60
+ current_dispatcher = Config.dispatcher.adapter
61
+ Config.dispatcher.adapter = :null_adapter
62
+
63
+ result = block.call
64
+
65
+ ensure
66
+ Config.dispatcher.adapter = current_dispatcher
67
+ result
68
+ end
69
+
59
70
  def self.category(name)
60
71
  message_store.category(name)
61
72
  end
@@ -30,6 +30,8 @@ module Messaging
30
30
  end
31
31
  end
32
32
 
33
+ Messaging::Adapters::Dispatcher.register(:null_adapter, memoize: true) { proc {} }
34
+
33
35
  require 'messaging/adapters/kafka'
34
36
  require 'messaging/adapters/postgres'
35
37
  require 'messaging/adapters/test'
@@ -25,6 +25,32 @@ module Messaging
25
25
  end
26
26
 
27
27
  module ClassMethods
28
+ # The stream that the message will be stored in when published.
29
+ #
30
+ # Stream names consists of the stream category and the stream id separated by a $.
31
+ # For instance "customer$123" where "customer" is the category and "123" is the id.
32
+ #
33
+ # When no stream name is given the message will not be persisted in the message store.
34
+ #
35
+ # @param [#call,String,nil] name The name of the stream, will be evaluated in the context
36
+ # of the message instance.
37
+ #
38
+ # @example
39
+ # class CustomerRegistered
40
+ # include Messaging::Message
41
+ #
42
+ # stream_name -> { "customer$#{customer_id}"}
43
+ #
44
+ # attribute :customer_id, Integer
45
+ # end
46
+ #
47
+ # CustomerRegistered.new(customer_id: 123).stream_name
48
+ # # => "customer$123"
49
+ def stream_name(name = nil)
50
+ return @stream_name unless name
51
+ @stream_name = name
52
+ end
53
+
28
54
  # By default the topic is the same as the name of the message.
29
55
  # We change the / that would be set for a namespaced message as "/" isn't valid in a topic
30
56
  # To change the topic for a message just set it to whatever you want in your class definition.
@@ -88,8 +114,8 @@ module Messaging
88
114
  end
89
115
 
90
116
  def stream_name
91
- # define stream_name in your message class to override
92
- nil
117
+ return unless self.class.stream_name
118
+ instance_exec(&self.class.stream_name)
93
119
  end
94
120
 
95
121
  def stream_category
@@ -31,6 +31,10 @@ module Messaging
31
31
  Messaging.routes.reload_consumer_routes!
32
32
  end
33
33
  end
34
+
35
+ config.to_prepare do
36
+ Messaging.routes.finalize_routes
37
+ end
34
38
  end
35
39
  end
36
40
  end
@@ -51,7 +51,18 @@ module Messaging
51
51
 
52
52
  # Public: Evaluate route definition.
53
53
  def draw(&block)
54
- instance_eval(&block)
54
+ routing_definition_blocks << block
55
+ end
56
+
57
+ def routing_definition_blocks
58
+ @routing_definition_blocks ||= []
59
+ end
60
+
61
+ def finalize_routes
62
+ clear_routes!
63
+ routing_definition_blocks.each do |block|
64
+ instance_eval(&block)
65
+ end
55
66
  end
56
67
 
57
68
  private
@@ -5,6 +5,32 @@ require 'messaging/routing/enqueue_message_handler'
5
5
 
6
6
  module Messaging
7
7
  module Routing
8
+ def self.included(base)
9
+ base.send :extend, ClassMethods
10
+ end
11
+
12
+ module ClassMethods
13
+ def definitions
14
+ @definitions ||= []
15
+ end
16
+
17
+ def on(pattern, **options, &block)
18
+ definitions << { pattern: pattern, options: options, block: block }
19
+ end
20
+
21
+ def new(*args, &block)
22
+ instance = allocate
23
+
24
+ # Pre-initialize
25
+ definitions.each do |definition|
26
+ instance.on(definition[:pattern], definition[:options], &definition[:block])
27
+ end
28
+
29
+ instance.send(:initialize, *args, &block)
30
+ instance
31
+ end
32
+ end
33
+
8
34
  # Public: Sets up routes for the events that matches the given pattern
9
35
  #
10
36
  # pattern - Which messages to route. Can be a string, a regexp,
@@ -44,8 +70,8 @@ module Messaging
44
70
  end
45
71
 
46
72
  # Internal: Handles the message with the matching subscribers
47
- def handle(message)
48
- routes.map { |route| route.call(message) }
73
+ def handle(message, context = self)
74
+ routes.map { |route| route.call(message, context) }
49
75
  message
50
76
  end
51
77
 
@@ -4,7 +4,7 @@ module Messaging
4
4
  class EnqueuedRoute < Route
5
5
  def initialize(pattern, handler)
6
6
  super
7
- @handler = EnqueueMessageHandler.new(handler)
7
+ @handler = EnqueueMessageHandler.new(handler).method(:call)
8
8
  end
9
9
  end
10
10
  end
@@ -11,14 +11,14 @@ module Messaging
11
11
 
12
12
  def initialize(pattern, handler)
13
13
  @matcher = MessageMatcher.new(pattern: pattern)
14
- @handler = handler
14
+ @handler = handler.respond_to?(:to_proc) ? handler : handler.method(:call)
15
15
  verify_handler!
16
16
  end
17
17
 
18
- def call(message)
18
+ def call(message, context = self)
19
19
  return unless @matcher.matches?(message)
20
20
 
21
- @handler.call(message)
21
+ context.instance_exec(message, &@handler)
22
22
  end
23
23
 
24
24
  def topics
@@ -1,3 +1,3 @@
1
1
  module Messaging
2
- VERSION = '3.5.1'.freeze
2
+ VERSION = '3.5.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: messaging
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.1
4
+ version: 3.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bukowskis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-13 00:00:00.000000000 Z
11
+ date: 2021-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -351,7 +351,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
351
351
  - !ruby/object:Gem::Version
352
352
  version: '0'
353
353
  requirements: []
354
- rubygems_version: 3.0.6
354
+ rubygems_version: 3.1.4
355
355
  signing_key:
356
356
  specification_version: 4
357
357
  summary: A library for decoupling applications by using messaging to communicate between