Module: Strum::Esb::Handler::ClassMethods
- Defined in:
- lib/strum/esb/handler.rb
Instance Method Summary collapse
- #bind_to(queue, message_type, message_binding, handler = nil) ⇒ Object
- #content_type_enabled?(content_type) ⇒ Boolean
- #enable_json(switcher) ⇒ Object
- #enable_protobuf(switcher) ⇒ Object
- #handler_key(message_type, message_binding) ⇒ Object
- #handlers ⇒ Object
- #json_enabled? ⇒ Boolean
- #protobuf_enabled? ⇒ Boolean
- #protobuf_service ⇒ Object
- #use_application_config ⇒ Object
- #use_protobuf_service(service) ⇒ Object
Instance Method Details
#bind_to(queue, message_type, message_binding, handler = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/strum/esb/handler.rb', line 19 def bind_to(queue, , , handler = nil) bindings ||= (queue_opts && queue_opts[:bindings]) || {} if block_given? yield(bindings) else bindings[] ||= [] bindings[] << end from_queue queue, bindings: bindings handlers[handler_key(, )] = handler.to_s if handler end |
#content_type_enabled?(content_type) ⇒ Boolean
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/strum/esb/handler.rb', line 59 def content_type_enabled?(content_type) case content_type when "application/json" json_enabled? when "application/x-protobuf" protobuf_enabled? else false end end |
#enable_json(switcher) ⇒ Object
43 44 45 |
# File 'lib/strum/esb/handler.rb', line 43 def enable_json(switcher) @json_mode = switcher end |
#enable_protobuf(switcher) ⇒ Object
51 52 53 |
# File 'lib/strum/esb/handler.rb', line 51 def enable_protobuf(switcher) @protobuf_mode = switcher end |
#handler_key(message_type, message_binding) ⇒ Object
33 34 35 36 37 |
# File 'lib/strum/esb/handler.rb', line 33 def handler_key(, ) _, *msg = Strum::Esb::Functions.public_send("#{message_type}_explain", ) params = msg.map { |param| param&.to_s&.gsub(/[^a-zA-Z0-9]/, "_")&.downcase } ([] + params).join("-") end |
#handlers ⇒ Object
39 40 41 |
# File 'lib/strum/esb/handler.rb', line 39 def handlers @handlers ||= {} end |
#json_enabled? ⇒ Boolean
47 48 49 |
# File 'lib/strum/esb/handler.rb', line 47 def json_enabled? @json_mode end |
#protobuf_enabled? ⇒ Boolean
55 56 57 |
# File 'lib/strum/esb/handler.rb', line 55 def protobuf_enabled? @protobuf_mode end |
#protobuf_service ⇒ Object
77 78 79 |
# File 'lib/strum/esb/handler.rb', line 77 def protobuf_service @protobuf_service end |
#use_application_config ⇒ Object
81 82 83 84 |
# File 'lib/strum/esb/handler.rb', line 81 def use_application_config enable_json(Strum::Esb.config.enable_json) enable_protobuf(Strum::Esb.config.enable_protobuf) end |
#use_protobuf_service(service) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/strum/esb/handler.rb', line 70 def use_protobuf_service(service) raise ArgumentError, "#{service} must be a grpc service" unless service.respond_to?(:rpc_descs) @protobuf_service = service enable_protobuf(true) end |