Class: Realm::SNS::Gateway
- Inherits:
-
EventRouter::Gateway
- Object
- EventRouter::Gateway
- Realm::SNS::Gateway
show all
- Defined in:
- lib/realm/sns/gateway.rb,
lib/realm/sns/gateway/worker.rb,
lib/realm/sns/gateway/queue_adapter.rb,
lib/realm/sns/gateway/queue_manager.rb,
lib/realm/sns/gateway/topic_adapter.rb
Defined Under Namespace
Classes: QueueAdapter, QueueManager, TopicAdapter, Worker
Instance Method Summary
collapse
Constructor Details
#initialize(topic_arn:, queue_prefix: nil, event_processing_attempts: 3) ⇒ Gateway
Returns a new instance of Gateway.
15
16
17
18
19
20
21
|
# File 'lib/realm/sns/gateway.rb', line 15
def initialize(topic_arn:, queue_prefix: nil, event_processing_attempts: 3, **)
super
@topic = TopicAdapter.new(topic_arn)
@queue_prefix = queue_prefix
@event_processing_attempts = event_processing_attempts
@queue_map = {}
end
|
Instance Method Details
#add_listener(event_type, listener, queue_arn: nil) ⇒ Object
23
24
25
26
|
# File 'lib/realm/sns/gateway.rb', line 23
def add_listener(event_type, listener, queue_arn: nil)
queue = queue_arn ? queue_manager.get(arn: queue_arn) : provide_queue(event_type, listener)
@queue_map[queue] = listener
end
|
#queues ⇒ Object
42
43
44
|
# File 'lib/realm/sns/gateway.rb', line 42
def queues
@queue_map.keys
end
|
#trigger(event_type, attributes = {}) ⇒ Object
28
29
30
|
# File 'lib/realm/sns/gateway.rb', line 28
def trigger(event_type, attributes = {})
create_event(event_type, attributes).tap { |event| @topic.publish(event_type, event.to_json) }
end
|
#worker(**options) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/realm/sns/gateway.rb', line 32
def worker(**options)
@worker ||= Worker.new(
@queue_map,
event_factory: @event_factory,
logger: @runtime && @runtime.context[:logger],
event_processing_attempts: @event_processing_attempts,
**options,
)
end
|