ElGraph.Signal.Bus (ElGraph v0.3.0)

Copy Markdown View Source

시그널 라우터/버스 (SPEC §5). 패턴 구독 + fan-out 발행.

두 transport (:transport 옵션, 기본 :local):

  • :local — Registry 기반(단일 노드). Agent 구독과 함수 구독(변환/로깅) 모두 지원.
  • :pg — distributed Erlang :pg 기반(클러스터 전체). Agent 구독만 분산된다 — 함수는 노드 경계를 넘지 못하므로 :pg 버스에서 함수 구독은 거부된다.

구독자 프로세스가 죽으면 구독은 자동 정리된다(Registry/:pg 모두). 분산은 best-effort 전달이다 (SPEC §6) — 전달 보장이 필요하면 멱등 수신으로 설계하라.

children = [{ElGraph.Signal.Bus, name: MyApp.Bus}]                    # 로컬
children = [{ElGraph.Signal.Bus, name: MyApp.Bus, transport: :pg}]    # 분산

Summary

Functions

시그널을 매칭되는 모든 구독자에게 발행한다 (fan-out). 전달 id를 fan-out 전에 한 번 스탬프한다.

버스를 시작한다 (:name 필수, :transport 기본 :local).

Agent 구독: 매칭되는 시그널이 호출 프로세스에 send_signal로 전달된다.

함수 구독: 매칭되는 시그널로 fun이 (발행자 컨텍스트에서) 호출된다. :local 전용.

Functions

publish(bus, signal)

@spec publish(atom(), ElGraph.Signal.t()) :: :ok

시그널을 매칭되는 모든 구독자에게 발행한다 (fan-out). 전달 id를 fan-out 전에 한 번 스탬프한다.

start_link(opts)

버스를 시작한다 (:name 필수, :transport 기본 :local).

subscribe(bus, pattern)

@spec subscribe(atom(), String.t()) :: :ok

Agent 구독: 매칭되는 시그널이 호출 프로세스에 send_signal로 전달된다.

subscribe(bus, pattern, fun)

@spec subscribe(atom(), String.t(), (ElGraph.Signal.t() -> any())) :: :ok

함수 구독: 매칭되는 시그널로 fun이 (발행자 컨텍스트에서) 호출된다. :local 전용.