Runbox.Runtime.Stage.UnitRegistry.RoutingKeyBuilder (runbox v8.0.0)
Builder of msg_parser and unit_register fns used in Runbox.Runtime.Stage.UnitRegistry
- message_parser is lambda function used to parse
Toolbox.Message
and creates key to find unit in unit registry - unit_register is lambda function used to parse
Toolbox.Runtime.Stage.Unit
and creates key to store unit in unit registry
Link to this section Summary
Functions
Gets routing key definition as argument and returns msg_parser lambda function
Gets routing key definition as argument and returns unit_register lambda function
Link to this section Functions
build_msg_parser(arg)
@spec build_msg_parser(Runbox.Runtime.Stage.UnitRegistry.routing_key_def()) :: Runbox.Runtime.Stage.UnitRegistry.msg_parser()
Gets routing key definition as argument and returns msg_parser lambda function
Lambda takes Toolbox.Message
as argument and returns list of message body values based on
provided routing key definition.
iex> msg_parser_fn = ...> RoutingKeyBuilder.build_msg_parser({:=, [[:foo]], [[:bar]]}) ...> msg_parser_fn.(%Message{body: %{foo: "message_body_key_value"}}) ["message_body_key_value"]
iex> msg_parser_fn = ...> RoutingKeyBuilder.build_msg_parser({:in, [[:foo]], [[:bar]]}) ...> msg_parser_fn.(%Message{body: %{foo: "message_body_key_value"}}) ["message_body_key_value"]
build_unit_register(arg)
@spec build_unit_register(Runbox.Runtime.Stage.UnitRegistry.routing_key_def()) :: Runbox.Runtime.Stage.UnitRegistry.unit_register()
Gets routing key definition as argument and returns unit_register lambda function
Lambda takes alternative registers (unit indexes), alternative register name,
Toolbox.Runtime.Stage.Unit
as arguments and returns updated alternative registers based on
provided routing key definition.
iex> unit_register_fn = ...> RoutingKeyBuilder.build_unit_register({:=, [[:foo]], [[:bar]]}) ...> unit = %Unit{id: "unit_id", attributes: %{bar: "attribute_key_value"}} ...> unit_register_fn.(%{"alt_reg" => AlternativeRegistry.new()}, "alt_reg", unit) %{"alt_reg" => %{["attribute_key_value"] => ["unit_id"]}}
iex> unit_register_fn = ...> RoutingKeyBuilder.build_unit_register({:in, [[:foo]], [[:bar]]}) ...> unit = %Unit{id: "unit_id", attributes: %{bar: ["value_1", "value_2"]}} ...> unit_register_fn.(%{"alt_reg" => AlternativeRegistry.new()}, "alt_reg", unit) %{"alt_reg" => %{["value_1"] => ["unit_id"], ["value_2"] => ["unit_id"]}}