Documentation
ยถ
Index ยถ
- type EventBusAdapter
- func (a *EventBusAdapter) Close() error
- func (a *EventBusAdapter) GetEventBus() eventbus.EventBus
- func (a *EventBusAdapter) GetPublishResultChannel() <-chan *outbox.PublishResult
- func (a *EventBusAdapter) GetRegisteredTenants() []int
- func (a *EventBusAdapter) GetTenantPublishResultChannel(tenantID int) <-chan *outbox.PublishResult
- func (a *EventBusAdapter) IsStarted() bool
- func (a *EventBusAdapter) PublishEnvelope(ctx context.Context, topic string, envelope *outbox.Envelope) error
- func (a *EventBusAdapter) RegisterTenant(tenantID int, bufferSize int) error
- func (a *EventBusAdapter) UnregisterTenant(tenantID int) error
- type EventHandler
- type InProcessEventPublisher
- func (p *InProcessEventPublisher) Close() error
- func (p *InProcessEventPublisher) GetPublishResultChannel() <-chan *outbox.PublishResult
- func (*InProcessEventPublisher) IsSyncSemantics()
- func (p *InProcessEventPublisher) PublishEnvelope(ctx context.Context, topic string, envelope *outbox.Envelope) error
- func (p *InProcessEventPublisher) RegisterHandler(topic string, handler EventHandler)
- type InProcessOption
Constants ยถ
This section is empty.
Variables ยถ
This section is empty.
Functions ยถ
This section is empty.
Types ยถ
type EventBusAdapter ยถ
type EventBusAdapter struct {
// contains filtered or unexported fields
}
EventBusAdapter EventBus ้้ ๅจ ๅฐ jxt-core/sdk/pkg/eventbus.EventBus ้้ ไธบ outbox.EventPublisher ๆฅๅฃ
ๅ่ฝ๏ผ 1. โ ่ฝฌๆข Outbox Envelope ไธบ EventBus Envelope 2. โ ่ฝฌๆข EventBus PublishResult ไธบ Outbox PublishResult 3. โ ่ชๅจๅฏๅจ ACK ็ปๆ่ฝฌๆข goroutine 4. โ ็บฟ็จๅฎๅ จ๏ผๆฏๆๅนถๅ่ฐ็จ
ไฝฟ็จ็คบไพ๏ผ
// 1. ๅๅปบ EventBus ๅฎไพ
eventBus, err := eventbus.NewKafkaEventBus(kafkaConfig)
if err != nil {
panic(err)
}
// 2. ๅๅปบ้้
ๅจ
adapter := NewEventBusAdapter(eventBus)
// 3. ๅๅปบ Outbox Publisher
publisher := outbox.NewOutboxPublisher(repo, adapter, topicMapper, config)
// 4. ๅฏๅจ ACK ็ๅฌๅจ
publisher.StartACKListener(ctx)
defer publisher.StopACKListener()
// 5. ๅๅธไบไปถ
event := outbox.NewOutboxEvent(...)
publisher.PublishEvent(ctx, event)
func NewEventBusAdapter ยถ
func NewEventBusAdapter(eventBus eventbus.EventBus) *EventBusAdapter
NewEventBusAdapter ๅๅปบ EventBus ้้ ๅจ
ๅๆฐ๏ผ
eventBus: EventBus ๅฎไพ๏ผKafka ๆ NATS๏ผ
่ฟๅ๏ผ
*EventBusAdapter: ้้ ๅจๅฎไพ
ๆณจๆ๏ผ
- ้้ ๅจไผ่ชๅจๅฏๅจ ACK ็ปๆ่ฝฌๆข goroutine
- ไฝฟ็จๅฎๆฏๅๅบ่ฏฅ่ฐ็จ Close() ้ๆพ่ตๆบ
func NewKafkaEventBusAdapter ยถ
func NewKafkaEventBusAdapter(kafkaConfig *eventbus.KafkaConfig) (*EventBusAdapter, error)
NewKafkaEventBusAdapter ๅๅปบ Kafka EventBus ้้ ๅจ
ๅๆฐ๏ผ
kafkaConfig: Kafka ้ ็ฝฎ
่ฟๅ๏ผ
*EventBusAdapter: ้้ ๅจๅฎไพ error: ๅๅปบๅคฑ่ดฅๆถ่ฟๅ้่ฏฏ
ไฝฟ็จ็คบไพ๏ผ
adapter, err := NewKafkaEventBusAdapter(kafkaConfig)
if err != nil {
panic(err)
}
defer adapter.Close()
func NewNATSEventBusAdapter ยถ
func NewNATSEventBusAdapter(natsConfig *eventbus.NATSConfig) (*EventBusAdapter, error)
NewNATSEventBusAdapter ๅๅปบ NATS EventBus ้้ ๅจ
ๅๆฐ๏ผ
natsConfig: NATS ้ ็ฝฎ
่ฟๅ๏ผ
*EventBusAdapter: ้้ ๅจๅฎไพ error: ๅๅปบๅคฑ่ดฅๆถ่ฟๅ้่ฏฏ
ไฝฟ็จ็คบไพ๏ผ
adapter, err := NewNATSEventBusAdapter(natsConfig)
if err != nil {
panic(err)
}
defer adapter.Close()
func (*EventBusAdapter) Close ยถ
func (a *EventBusAdapter) Close() error
Close ๅ ณ้ญ้้ ๅจ๏ผ้ๆพ่ตๆบใๅบ่ฏฅๅจๅบ็จๅ ณ้ญๆถ่ฐ็จใ
PR2-core (Task 4, Step 4 โ D9 ownership split): Close returns its OWN teardown error honestly and does NOT close the injected bus ("don't close what you don't own"). The bus is injected via NewEventBusAdapter; the orchestrator (e.g. the outbox consumer) owns the bus lifecycle โ it calls bus.Close() and surfaces the terminal error for the non-zero exit (spec ยง3.3). This adapter's terminal error lives on the bus and is surfaced by the bus owner, NOT here.
Deterministic join (replaces the old time.Sleep(100ms), ce-doc-review #2): close(stopChan) signals ALL conversion loops (global + per-tenant) to exit via their <-stopChan cases, then loopsWg.Wait() joins them. A single Sleep could never deterministically join the per-tenant loops spawned by GetTenantPublishResultChannel.
Today the join+close can't fail, so the return is nil โ but the signature stays honest (never swallow a future join/close error to nil).
func (*EventBusAdapter) GetEventBus ยถ
func (a *EventBusAdapter) GetEventBus() eventbus.EventBus
GetEventBus ่ทๅๅบๅฑ EventBus ๅฎไพ ็จไบ้่ฆ็ดๆฅ่ฎฟ้ฎ EventBus ็ๅบๆฏ
func (*EventBusAdapter) GetPublishResultChannel ยถ
func (a *EventBusAdapter) GetPublishResultChannel() <-chan *outbox.PublishResult
GetPublishResultChannel ๅฎ็ฐ outbox.EventPublisher ๆฅๅฃ ่ทๅๅผๆญฅๅๅธ็ปๆ้้
่ฟๅ๏ผ
<-chan *outbox.PublishResult: ๅช่ฏป็ๅๅธ็ปๆ้้
func (*EventBusAdapter) GetRegisteredTenants ยถ added in v1.1.22
func (a *EventBusAdapter) GetRegisteredTenants() []int
GetRegisteredTenants ่ทๅๆๆๅทฒๆณจๅ็็งๆทIDๅ่กจ ๅงๆ็ปๅบๅฑ EventBus ๅฎ็ฐ
func (*EventBusAdapter) GetTenantPublishResultChannel ยถ added in v1.1.22
func (a *EventBusAdapter) GetTenantPublishResultChannel(tenantID int) <-chan *outbox.PublishResult
GetTenantPublishResultChannel ่ทๅ็งๆทไธๅฑ็ๅผๆญฅๅๅธ็ปๆ้้๏ผๅค็งๆทๆจกๅผ๏ผ ่ฟๅไธไธช่ฝฌๆขๅ็ Outbox PublishResult ้้
ๆณจๆ๏ผๆญคๆนๆณ่ฟๅ็ๆฏ EventBus ็็งๆท้้๏ผ้่ฆ่ฐ็จ่ ่ช่ก่ฝฌๆข็ฑปๅ ๆจ่ไฝฟ็จ CreateTenantResultChannel() ๆนๆณ๏ผๅฎไผ่ชๅจๅๅปบ่ฝฌๆข้้
func (*EventBusAdapter) IsStarted ยถ
func (a *EventBusAdapter) IsStarted() bool
IsStarted ๆฃๆฅ้้ ๅจๆฏๅฆๅทฒๅฏๅจ
func (*EventBusAdapter) PublishEnvelope ยถ
func (a *EventBusAdapter) PublishEnvelope(ctx context.Context, topic string, envelope *outbox.Envelope) error
PublishEnvelope ๅฎ็ฐ outbox.EventPublisher ๆฅๅฃ ๅๅธ Envelope ๆถๆฏๅฐ EventBus
ๅๆฐ๏ผ
ctx: ไธไธๆ topic: ็ฎๆ topic envelope: Outbox Envelope
่ฟๅ๏ผ
error: ๅๅธๅคฑ่ดฅๆถ่ฟๅ้่ฏฏ๏ผๆณจๆ๏ผ็ซๅณ่ฟๅ๏ผไธ็ญๅพ ACK๏ผ
func (*EventBusAdapter) RegisterTenant ยถ added in v1.1.22
func (a *EventBusAdapter) RegisterTenant(tenantID int, bufferSize int) error
RegisterTenant ๆณจๅ็งๆท๏ผๅๅปบ็งๆทไธๅฑ็ ACK Channel๏ผ ๅงๆ็ปๅบๅฑ EventBus ๅฎ็ฐ
func (*EventBusAdapter) UnregisterTenant ยถ added in v1.1.22
func (a *EventBusAdapter) UnregisterTenant(tenantID int) error
UnregisterTenant ๆณจ้็งๆท๏ผๅ ณ้ญๅนถๆธ ็็งๆท็ ACK Channel๏ผ ๅงๆ็ปๅบๅฑ EventBus ๅฎ็ฐ
type EventHandler ยถ added in v1.1.47
EventHandler ่ฟ็จๅ ไบไปถๅค็ๅจ
type InProcessEventPublisher ยถ added in v1.1.47
type InProcessEventPublisher struct {
// contains filtered or unexported fields
}
InProcessEventPublisher ่ฟ็จๅ ไบไปถๅๅธๅจ๏ผๅฎ็ฐ outbox.EventPublisher ๆฅๅฃใ ไธ EventBusAdapter๏ผKafka/NATS๏ผๅฏน็งฐ๏ผๅฐไบไปถๆดพๅๅฐ่ฟ็จๅ ๆณจๅ็ Go handler ่้ๅค้จๆถๆฏๆป็บฟใ
ไฝฟ็จๅบๆฏ๏ผๅพฎๆๅกๅ ้จ้ขๅไบไปถๆดพๅ๏ผๅฆ IAM ่ฎพๅค็ฎก็๏ผ๏ผไบไปถไธ่ทจๆๅกใไธ็ป่ฟ brokerใ
ไฝฟ็จ็คบไพ่ง examples/evidence_management_adapter.go ๅบ้จ็ InProcessEventPublisher ็คบไพใ
func NewInProcessEventPublisher ยถ added in v1.1.47
func NewInProcessEventPublisher(opts ...InProcessOption) *InProcessEventPublisher
func (*InProcessEventPublisher) Close ยถ added in v1.1.47
func (p *InProcessEventPublisher) Close() error
Close ๅ ณ้ญๅๅธๅจใๅฏๅฎๅ จๅคๆฌก่ฐ็จ๏ผsendMu + closed ไฟ่ฏๅน็ญ๏ผใๅจ sendMu ไธๅ ณ้ญ resultChan๏ผไธ sendResult ไบๆฅ๏ผไป็ปๆไธๆถ้ค close-vs-send ๆฐๆฎ็ซไบใ
func (*InProcessEventPublisher) GetPublishResultChannel ยถ added in v1.1.47
func (p *InProcessEventPublisher) GetPublishResultChannel() <-chan *outbox.PublishResult
GetPublishResultChannel ๅฎ็ฐ outbox.EventPublisher ๆฅๅฃ
func (*InProcessEventPublisher) IsSyncSemantics ยถ added in v1.1.58
func (*InProcessEventPublisher) IsSyncSemantics()
IsSyncSemantics marks InProcessEventPublisher as a sync-semantics publisher. PublishEnvelope runs all registered handlers synchronously and returns when done.
func (*InProcessEventPublisher) PublishEnvelope ยถ added in v1.1.47
func (p *InProcessEventPublisher) PublishEnvelope(ctx context.Context, topic string, envelope *outbox.Envelope) error
PublishEnvelope ๅฎ็ฐ outbox.EventPublisher ๆฅๅฃใ ๅๆญฅ่ฐ็จ่ฏฅ topic ไธ็ๆๆ handler๏ผๅ จ้จๅฎๆๅๅ้ ACK resultใ ๆๆ handler ้ฝไผ่ขซ่ฐ็จ๏ผไธๅ ไธญ้ๅคฑ่ดฅ่็ญ่ทฏ๏ผ๏ผ่ฟๅ็ฌฌไธไธช้ๅฐ็ errorใ
func (*InProcessEventPublisher) RegisterHandler ยถ added in v1.1.47
func (p *InProcessEventPublisher) RegisterHandler(topic string, handler EventHandler)
RegisterHandler ๆณจๅไบไปถๅค็ๅจ๏ผ็บฟ็จๅฎๅ จ๏ผใๅไธ topic ๅฏๆณจๅๅคไธช handler๏ผๆๆณจๅ้กบๅบไพๆฌก่ฐ็จใ ๅฟ ้กปๅจ Scheduler ๅฏๅจๅ่ฐ็จใ
type InProcessOption ยถ added in v1.1.47
type InProcessOption func(*InProcessEventPublisher)
InProcessOption ่ฟ็จๅ ๅๅธๅจ้ ็ฝฎ้้กน
func WithBufferSize ยถ added in v1.1.47
func WithBufferSize(n int) InProcessOption
WithBufferSize ่ฎพ็ฝฎ ACK result channel ็ผๅฒๅบๅคงๅฐ๏ผ้ป่ฎค 1000