Class: RubyEventStore::InstrumentedBroker

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_event_store/instrumented_broker.rb

Instance Method Summary collapse

Constructor Details

#initialize(broker, instrumentation) ⇒ InstrumentedBroker

Returns a new instance of InstrumentedBroker.



5
6
7
8
# File 'lib/ruby_event_store/instrumented_broker.rb', line 5

def initialize(broker, instrumentation)
  @broker = broker
  @instrumentation = instrumentation
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, **keyword_arguments, &block) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/ruby_event_store/instrumented_broker.rb', line 57

def method_missing(method_name, *arguments, **keyword_arguments, &block)
  if respond_to?(method_name)
    broker.public_send(method_name, *arguments, **keyword_arguments, &block)
  else
    super
  end
end

Instance Method Details

#add_global_subscription(subscriber) ⇒ Object



31
32
33
34
35
# File 'lib/ruby_event_store/instrumented_broker.rb', line 31

def add_global_subscription(subscriber)
  instrumentation.instrument("add_global_subscription.broker.rails_event_store", subscriber: subscriber) do
    broker.add_global_subscription(subscriber)
  end
end

#add_subscription(subscriber, topics) ⇒ Object



25
26
27
28
29
# File 'lib/ruby_event_store/instrumented_broker.rb', line 25

def add_subscription(subscriber, topics)
  instrumentation.instrument("add_subscription.broker.rails_event_store", subscriber: subscriber, topics: topics) do
    broker.add_subscription(subscriber, topics)
  end
end

#add_thread_global_subscription(subscriber) ⇒ Object



45
46
47
48
49
# File 'lib/ruby_event_store/instrumented_broker.rb', line 45

def add_thread_global_subscription(subscriber)
  instrumentation.instrument("add_thread_global_subscription.broker.rails_event_store", subscriber: subscriber) do
    broker.add_thread_global_subscription(subscriber)
  end
end

#add_thread_subscription(subscriber, topics) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/ruby_event_store/instrumented_broker.rb', line 37

def add_thread_subscription(subscriber, topics)
  instrumentation.instrument(
    "add_thread_subscription.broker.rails_event_store",
    subscriber: subscriber,
    topics: topics,
  ) { broker.add_thread_subscription(subscriber, topics) }
end

#all_subscriptions_for(topic) ⇒ Object



51
52
53
54
55
# File 'lib/ruby_event_store/instrumented_broker.rb', line 51

def all_subscriptions_for(topic)
  instrumentation.instrument("all_subscriptions_for.broker.rails_event_store", topic: topic) do
    broker.all_subscriptions_for(topic)
  end
end

#call(topic, event, record) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ruby_event_store/instrumented_broker.rb', line 10

def call(topic, event, record)
  instrumentation.instrument("call.broker.rails_event_store", topic: topic, event: event, record: record) do
    if broker.public_method(:call).arity == 3
      broker.call(topic, event, record)
    else
      warn <<~EOW
        Message broker shall support topics.
        Topic WILL BE IGNORED in the current broker.
        Modify the broker implementation to pass topic as an argument to broker.call method.
      EOW
      broker.call(event, record)
    end
  end
end

#respond_to_missing?(method_name, _include_private) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/ruby_event_store/instrumented_broker.rb', line 65

def respond_to_missing?(method_name, _include_private)
  broker.respond_to?(method_name)
end