PhoenixGenApi.Structs.ServiceConfig (PhoenixGenApi v2.11.0)

Copy Markdown View Source

Service configuration struct that defines how to connect to a remote service and pull its function configurations.

Version Checking

When version_module and version_function are configured, the ConfigPuller will first call the lightweight version check RPC before performing a full config pull. If the returned version matches the locally stored version for that service, the full pull is skipped — saving network bandwidth and reducing load on remote nodes.

The remote service should implement a version function that returns a value that changes whenever the function configurations change. Good candidates include:

  • A monotonically increasing integer (e.g., 1, 2, 3)
  • A semantic version string (e.g., "1.2.3")
  • A content hash of the config data (e.g., "a1b2c3d4")
  • A timestamp of the last config change (e.g., "2024-01-15T10:30:00Z")

The version value is compared using strict equality (==), so any format that can be compared this way will work.

Example Configuration

%ServiceConfig{
  service: "user_service",
  nodes: ["node1@host", "node2@host"],
  module: UserService.Api,
  function: :get_config,
  args: [],
  version_module: UserService.Api,
  version_function: :get_config_version,
  version_args: []
}

If version_module or version_function is nil, version checking is disabled and the full config pull will always be performed (backward compatible behavior).

Summary

Types

t()

Service configuration struct.

Functions

Creates a ServiceConfig struct from a map (typically from application config).

Returns true if version checking is configured for this service.

Types

t()

@type t() :: %PhoenixGenApi.Structs.ServiceConfig{
  args: list(),
  function: atom(),
  module: module(),
  nodes: [String.t()] | {module(), atom(), list()},
  service: String.t(),
  version_args: list(),
  version_function: atom() | nil,
  version_module: module() | nil
}

Service configuration struct.

Functions

from_map(config)

Creates a ServiceConfig struct from a map (typically from application config).

Handles both atom and string keys, and converts string module/function names to atoms when necessary.

version_check_enabled?(arg1)

@spec version_check_enabled?(t()) :: boolean()

Returns true if version checking is configured for this service.

A service is considered to have version checking enabled when both version_module and version_function are non-nil.