Class: Karafka::Web::Pro::Commanding::Dispatcher

Inherits:
Object
  • Object
show all
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.0.0'

Class Method Summary collapse

Class Method Details

.command(name, process_id) ⇒ Object

Dispatches the command request

Parameters:

  • name (String, Symbol)

    name of the command we want to deal with in the process

  • process_id (String)

    id of the process. We use name instead of id only because in the web ui we work with the full name and it is easier. Since



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/karafka/web/pro/commanding/dispatcher.rb', line 33

def command(name, process_id)
  produce(
    process_id,
    {
      schema_version: SCHEMA_VERSION,
      type: 'command',
      command: {
        name: name
      },
      dispatched_at: Time.now.to_f,
      process: {
        id: process_id
      }
    }
  )
end

.result(result, process_id, command_name) ⇒ Object

Dispatches the result request

Parameters:

  • result (Object)

    anything that can be the result of the command execution

  • process_id (String)

    related process id

  • command_name (String, Symbol)

    command that triggered this result



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/karafka/web/pro/commanding/dispatcher.rb', line 55

def result(result, process_id, command_name)
  produce(
    process_id,
    {
      schema_version: SCHEMA_VERSION,
      type: 'result',
      command: {
        name: command_name
      },
      result: result,
      dispatched_at: Time.now.to_f,
      process: {
        id: process_id
      }
    }
  )
end