Class: Karafka::Web::Pro::Commanding::Dispatcher
- Inherits:
-
Object
- Object
- Karafka::Web::Pro::Commanding::Dispatcher
- Defined in:
- lib/karafka/web/pro/commanding/dispatcher.rb
Overview
Dispatcher for sending commanding related messages. Those can be:
-
command (do something)
-
result (you wanted me to get you some info, here it is)
Dispatcher requires Web UI to have a producer
Constant Summary collapse
- SCHEMA_VERSION =
What schema do we have in current Karafka version for commands dispatches
"1.2.0"
Class Method Summary collapse
-
.acceptance(command_name, process_id, params = {}) ⇒ Object
Dispatches the acceptance info.
-
.request(command_name, params = {}, matchers: {}) ⇒ Object
Dispatches the command request.
-
.result(command_name, process_id, result) ⇒ Object
Dispatches the result request.
Class Method Details
.acceptance(command_name, process_id, params = {}) ⇒ Object
Dispatches the acceptance info. Indicates that a command was received and appropriate action will be taken but async. Useful for commands that may not take immediate actions upon receiving a command.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/karafka/web/pro/commanding/dispatcher.rb', line 74 def acceptance(command_name, process_id, params = {}) produce_reply( process_id, "acceptance", { schema_version: SCHEMA_VERSION, type: "acceptance", id: SecureRandom.uuid, command: params.merge(name: command_name), dispatched_at: Time.now.to_f, process: { id: process_id } } ) end |
.request(command_name, params = {}, matchers: {}) ⇒ Object
Dispatches the command request
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/karafka/web/pro/commanding/dispatcher.rb', line 52 def request(command_name, params = {}, matchers: {}) produce_request( { schema_version: SCHEMA_VERSION, type: "request", # UUID to uniquely identify this command instance id: SecureRandom.uuid, # Name is auto-generated and required. Should not be changed command: params.merge(name: command_name), dispatched_at: Time.now.to_f, matchers: matchers } ) end |
.result(command_name, process_id, result) ⇒ Object
Dispatches the result request
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/karafka/web/pro/commanding/dispatcher.rb', line 96 def result(command_name, process_id, result) produce_reply( process_id, "result", { schema_version: SCHEMA_VERSION, type: "result", id: SecureRandom.uuid, command: { name: command_name }, result: result, dispatched_at: Time.now.to_f, process: { id: process_id } } ) end |