PacketFlow.Component.Communication (packetflow v0.1.0)

Component communication protocols for inter-component messaging

This module provides:

  • Message routing between components
  • Protocol definitions for different message types
  • Message validation and transformation
  • Asynchronous and synchronous communication patterns
  • Message queuing and buffering

Summary

Functions

Broadcast a message to multiple components

Returns a specification to start this module under a supervisor.

Get pending requests for debugging

Get communication statistics

Callback implementation for GenServer.init/1.

Register a message handler for a component

Register a communication protocol

Send a message to a component

Send a synchronous request to a component

Subscribe to messages from a component

Unsubscribe from messages from a component

Types

communication_protocol()

@type communication_protocol() :: %{
  name: atom(),
  version: String.t(),
  message_types: [message_type()],
  validation_rules: map(),
  transformation_rules: map()
}

component_message()

@type component_message() :: %{
  id: message_id(),
  type: message_type(),
  from: atom(),
  to: atom() | [atom()],
  payload: term(),
  priority: message_priority(),
  timestamp: integer(),
  timeout: integer() | nil,
  reply_to: pid() | nil,
  metadata: map()
}

message_id()

@type message_id() :: String.t()

message_priority()

@type message_priority() :: :low | :normal | :high | :urgent

message_type()

@type message_type() :: :request | :response | :notification | :broadcast | :event

Functions

broadcast_message(targets, payload, opts \\ [])

@spec broadcast_message(
  [atom()],
  term(),
  keyword()
) :: :ok | {:error, term()}

Broadcast a message to multiple components

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_pending_requests()

@spec get_pending_requests() :: map()

Get pending requests for debugging

get_statistics()

@spec get_statistics() :: map()

Get communication statistics

init(opts)

Callback implementation for GenServer.init/1.

register_message_handler(component, handler_module)

@spec register_message_handler(atom(), module()) :: :ok | {:error, term()}

Register a message handler for a component

register_protocol(protocol)

@spec register_protocol(communication_protocol()) :: :ok | {:error, term()}

Register a communication protocol

send_message(to, payload, opts \\ [])

@spec send_message(atom(), term(), keyword()) :: :ok | {:error, term()}

Send a message to a component

send_request(to, payload, opts \\ [])

@spec send_request(atom(), term(), keyword()) :: {:ok, term()} | {:error, term()}

Send a synchronous request to a component

start_link(opts \\ [])

subscribe(from_component, to_component)

@spec subscribe(atom(), atom()) :: :ok | {:error, term()}

Subscribe to messages from a component

unsubscribe(from_component, to_component)

@spec unsubscribe(atom(), atom()) :: :ok | {:error, term()}

Unsubscribe from messages from a component