{"modulePath":"github.com/GoCodeAlone/workflow-plugin-eventbus","version":"v0.3.8","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package eventbus\n\nPackage eventbus implements the workflow-plugin-eventbus plugin. It provides eventbus.broker, eventbus.stream, and eventbus.consumer module types plus step and trigger types for durable event-bus integration.\n\n## Functions\n\n```go\nfunc DefaultBusConn() (*nats.Conn, error)\n```\nDefaultBusConn returns a live NATS connection for the lexicographically first registered eventbus.broker module. Sorting ensures deterministic selection across invocations and concurrent goroutines, even when multiple buses are registered. For multi-bus workflows, use GetOrDialNATSConn(instanceName) directly.\n\nDeprecated: superseded by LookupRuntimeWithFallback, which routes through providers.RuntimeBroker and works across nats / pgchannel / future providers. Retained for source-compat with callers that still hold a direct \\*nats.Conn.\n\n```go\nfunc GetBusURI(instanceName string) (string, bool)\n```\nGetBusURI returns the broker URI for instanceName.\n\n```go\nfunc GetCluster(instanceName string) (*eventbusv1.ClusterConfig, bool)\n```\nGetCluster looks up a ClusterConfig by instance name.\n\n```go\nfunc GetConsumer(instanceName string) (*eventbusv1.ConsumerConfig, bool)\n```\nGetConsumer looks up a ConsumerConfig by instance name.\n\n```go\nfunc GetConsumerByName(durableName string) (*eventbusv1.ConsumerConfig, bool)\n```\nGetConsumerByName looks up a ConsumerConfig by its durable consumer name (cfg.name), iterating all registered instances. This is used by step.eventbus.consume to resolve the consumer config from the durable name supplied in ConsumeRequest.consumer.\n\n```go\nfunc GetNATSConn(instanceName string) (*nats.Conn, bool)\n```\nGetNATSConn returns the cached \\*nats.Conn for instanceName, or false if absent.\n\nDeprecated: see RegisterNATSConn.\n\n```go\nfunc GetOrDialNATSConn(instanceName string) (*nats.Conn, error)\n```\nGetOrDialNATSConn returns the cached NATS connection for instanceName, dialing a new one (via natsDialFn) if no live connection is cached. Returns an error if no URI is registered for instanceName or the dial fails.\n\nLock ordering: connCacheMu and urlMu (held inside GetBusURI) are never held simultaneously. The URI lookup happens between the fast-path unlock and the slow-path re-lock so that no nested acquisition is possible.\n\nDeprecated: new code should use LookupRuntime / LookupRuntimeWithFallback, which dispatch through providers.RuntimeBroker. Retained for source-compat with external consumers that still hold a direct \\*nats.Conn.\n\n```go\nfunc GetStream(instanceName string) (*eventbusv1.StreamConfig, bool)\n```\nGetStream looks up a StreamConfig by instance name.\n\n```go\nfunc LookupBrokerInstance(name string) (*clusterModule, bool)\n```\nLookupBrokerInstance returns the \\*clusterModule registered under name, or false when absent. Primarily for tests; production callers should use LookupRuntime, which also validates that Start has run.\n\n```go\nfunc LookupRuntime(name string) (providers.RuntimeBroker, providers.Connection, error)\n```\nLookupRuntime returns the RuntimeBroker + cached Connection for the named broker. Used by stream/consumer modules' Start (Group E) and by step factories + the trigger module (Group F) to dispatch through the provider abstraction.\n\nReturns an error when:\n\n  - no broker module is registered under name (Init never ran or wrong name);\n  - the broker module is registered but Start has not yet completed (runtime/conn are still nil).\n\n```go\nfunc LookupRuntimeWithFallback(brokerRef string) (providers.RuntimeBroker, providers.Connection, error)\n```\nLookupRuntimeWithFallback resolves a RuntimeBroker + Connection given an optional brokerRef. When brokerRef is non-empty, behaves like LookupRuntime. When brokerRef is empty AND exactly one broker is registered, returns that broker (the legacy single-bus fallback that mirrors DefaultBusConn).\n\nUsed by step factories + the trigger so configs predating the broker\\_ref field continue to work in single-bus deployments. Returns a clear error when the fallback is ambiguous (multiple brokers registered) or impossible (no brokers registered), guiding the caller to set broker\\_ref explicitly.\n\n```go\nfunc NewClusterModule(instanceName string, cfg *eventbusv1.ClusterConfig) (sdk.ModuleInstance, error)\n```\nNewClusterModule creates a clusterModule from a typed ClusterConfig proto.\n\nValidation is per-provider because the configuration shape diverges:\n\n  - pgchannel runs in-process against an existing Postgres database. It does not deploy a broker, so deploy\\_target is meaningless; instead broker\\_target=in\\_process is required (the only supported mode in the in-process runtime) along with cfg.dsn carrying the Postgres connection string.\n  - nats, kafka, kinesis each deploy a managed/self-hosted broker onto a cloud target, so deploy\\_target is required and must be in the supported matrix (providers.ValidateProviderTarget).\n\nAny provider not in the {pgchannel, nats, kafka, kinesis} set is rejected here. The previous implementation rejected any empty deploy\\_target uniformly; the relaxation lands as part of design §1.7 to enable the pg-backed-provider flow.\n\n```go\nfunc NewConsumerModule(instanceName string, cfg *eventbusv1.ConsumerConfig) (sdk.ModuleInstance, error)\n```\nNewConsumerModule creates a consumerModule from a typed ConsumerConfig proto.\n\nReturns an error if:\n\n  - config.name is empty\n  - config.stream\\_name is empty\n\n```go\nfunc NewStreamModule(instanceName string, cfg *eventbusv1.StreamConfig) (sdk.ModuleInstance, error)\n```\nNewStreamModule creates a streamModule from a typed StreamConfig proto.\n\nReturns an error if:\n\n  - config.name is empty\n  - config.subjects contains no entries\n\n```go\nfunc NewSubscribeTrigger(instanceName string, cfg *eventbusv1.ConsumerConfig, cb sdk.TriggerCallback) (sdk.ModuleInstance, error)\n```\nNewSubscribeTrigger creates a subscribeTrigger from a typed ConsumerConfig proto.\n\nReturns an error if:\n\n  - config.name is empty\n  - config.stream\\_name is empty\n\n```go\nfunc RegisterBrokerInstance(name string, m *clusterModule)\n```\nRegisterBrokerInstance stores m under name. Exported so integration tests can pre-seed the registry with a hand-built clusterModule.\n\n```go\nfunc RegisterBusURI(instanceName, uri string)\n```\nRegisterBusURI stores a broker URI under instanceName.\n\n```go\nfunc RegisterCluster(instanceName string, cfg *eventbusv1.ClusterConfig)\n```\nRegisterCluster stores a ClusterConfig in the global registry under instanceName.\n\n```go\nfunc RegisterConsumer(instanceName string, cfg *eventbusv1.ConsumerConfig)\n```\nRegisterConsumer stores a ConsumerConfig in the global registry under instanceName.\n\n```go\nfunc RegisterNATSConn(instanceName string, conn *nats.Conn)\n```\nRegisterNATSConn stores a live connection under instanceName. Exported so that integration tests and the trigger can pre-populate the cache.\n\nDeprecated: this helper predates the providers.RuntimeBroker abstraction. New code should construct an eventbus.broker module + call Init/Start, which publishes the runtime + connection through LookupRuntime. Kept for legacy callers and the bounded lifecycle teardown path in clusterModule.Stop.\n\n```go\nfunc RegisterStream(instanceName string, cfg *eventbusv1.StreamConfig)\n```\nRegisterStream stores a StreamConfig in the global registry under instanceName.\n\n```go\nfunc UnregisterBrokerInstance(name string)\n```\nUnregisterBrokerInstance removes the entry for name. Idempotent.\n\n```go\nfunc UnregisterBusURI(instanceName string)\n```\nUnregisterBusURI removes the URI entry for instanceName.\n\n```go\nfunc UnregisterCluster(instanceName string)\n```\nUnregisterCluster removes a ClusterConfig from the registry.\n\n```go\nfunc UnregisterConsumer(instanceName string)\n```\nUnregisterConsumer removes a ConsumerConfig from the registry.\n\n```go\nfunc UnregisterNATSConn(instanceName string)\n```\nUnregisterNATSConn removes the cached connection entry for instanceName without closing the connection. Use this in tests that manage the connection's lifetime separately (e.g., via nc.Close() + embedded-server shutdown).\n\nDeprecated: see RegisterNATSConn.\n\n```go\nfunc UnregisterStream(instanceName string)\n```\nUnregisterStream removes a StreamConfig from the registry.\n\n## Types\n\n```go\ntype ClusterModuleFactory struct{}\n```\nClusterModuleFactory implements sdk.TypedModuleProvider for the eventbus.broker module type. The plugin wires this factory into CreateTypedModule.\n\n```go\nfunc (f *ClusterModuleFactory) CreateTypedModule(typeName, name string, config *anypb.Any) (sdk.ModuleInstance, error)\n```\nCreateTypedModule unpacks the typed proto config and delegates to NewClusterModule.\n\n```go\nfunc (f *ClusterModuleFactory) TypedModuleTypes() []string\n```\nTypedModuleTypes returns the single module type served by this factory.\n\n```go\ntype ConsumerModuleFactory struct{}\n```\nConsumerModuleFactory implements sdk.TypedModuleProvider for the eventbus.consumer module type.\n\n```go\nfunc (f *ConsumerModuleFactory) CreateTypedModule(typeName, name string, config *anypb.Any) (sdk.ModuleInstance, error)\n```\nCreateTypedModule unpacks the typed proto config and delegates to NewConsumerModule.\n\n```go\nfunc (f *ConsumerModuleFactory) TypedModuleTypes() []string\n```\nTypedModuleTypes returns the single module type served by this factory.\n\n```go\ntype StreamModuleFactory struct{}\n```\nStreamModuleFactory implements sdk.TypedModuleProvider for the eventbus.stream module type.\n\n```go\nfunc (f *StreamModuleFactory) CreateTypedModule(typeName, name string, config *anypb.Any) (sdk.ModuleInstance, error)\n```\nCreateTypedModule unpacks the typed proto config and delegates to NewStreamModule.\n\n```go\nfunc (f *StreamModuleFactory) TypedModuleTypes() []string\n```\nTypedModuleTypes returns the single module type served by this factory.\n\n```go\ntype SubscribeTriggerModuleFactory struct{}\n```\nSubscribeTriggerModuleFactory implements sdk.TypedModuleProvider for the trigger.eventbus.subscribe module type. The external plugin adapter calls CreateTypedModule with the trigger type name to instantiate triggers over gRPC.\n\n```go\nfunc (f *SubscribeTriggerModuleFactory) CreateTypedModule(typeName, name string, config *anypb.Any) (sdk.ModuleInstance, error)\n```\nCreateTypedModule unpacks the typed proto config and delegates to NewSubscribeTrigger. cb is always nil in the external gRPC subprocess path (the callback client is never wired in production SDK code); triggers that receive cb=nil behave as no-ops on Start, which is correct for IaC-only and plan/apply workflows.\n\n```go\nfunc (f *SubscribeTriggerModuleFactory) TypedModuleTypes() []string\n```\nTypedModuleTypes returns the single trigger module type served by this factory.\n\n","path":"github.com/GoCodeAlone/workflow-plugin-eventbus","name":"eventbus","synopsis":"Package eventbus implements the workflow-plugin-eventbus plugin.","isRedistributable":true}
