Remove root honeybee package; promote inbound and outbound as primary API

- Delete honeybee.go (coincidental-strength re-export module)
- Add Socket, InboxMessage, NormalizeURL re-exports to inbound/pool.go
- Add InboxMessage, Dialer, NormalizeURL re-exports to outbound/pool.go
- Add Socket, Dialer re-exports to honeybeetest/mocks.go
- Update README, CONFIG, EXTEND to reflect new import structure
This commit is contained in:
Jay
2026-05-18 09:25:55 -04:00
parent 9616764899
commit 16cafdb86d
7 changed files with 103 additions and 243 deletions
+35 -29
View File
@@ -8,7 +8,9 @@ Logging can be controlled independently at the pool, worker, and connection leve
## Connection Options ## Connection Options
These are passed to `NewConnectionConfig` or supplied via `WithInboundConnectionConfig` / `WithOutboundConnectionConfig`. `ConnectionConfig` is defined in the `transport` package. Import `git.wisehodl.dev/jay/go-honeybee/transport` to construct one, then pass it to a pool via `inbound.WithConnectionConfig` or `outbound.WithConnectionConfig`.
These options are passed to `transport.NewConnectionConfig`.
### Write Behavior ### Write Behavior
@@ -63,95 +65,99 @@ Overrides the minimum log level for connection-scoped records. Does not affect p
## Inbound Pool Options ## Inbound Pool Options
Import `git.wisehodl.dev/jay/go-honeybee/inbound`.
### Pool ### Pool
These are passed to `NewInboundPoolConfig`. These are passed to `inbound.NewPoolConfig`.
**`WithInboundInboxBufferSize(int)`** **`inbound.WithInboxBufferSize(int)`**
Sets the capacity of the pool's shared inbox channel. Must be at least 1. Sets the capacity of the pool's shared inbox channel. Must be at least 1.
**`WithInboundEventsBufferSize(int)`** **`inbound.WithEventsBufferSize(int)`**
Sets the capacity of the pool's events channel. Must be at least 1. Sets the capacity of the pool's events channel. Must be at least 1.
**`WithInboundPoolLoggingEnabled(bool)`** **`inbound.WithPoolLoggingEnabled(bool)`**
Enables or disables pool-level logging. Enables or disables pool-level logging.
**`WithInboundPoolLogLevel(slog.Level)`** **`inbound.WithPoolLogLevel(slog.Level)`**
Overrides the minimum log level for pool-scoped records only. Overrides the minimum log level for pool-scoped records only.
### Worker ### Worker
These are passed to `NewInboundWorkerConfig` or embedded in the pool config. These are passed to `inbound.NewWorkerConfig` or embedded in the pool config.
**`WithInboundInactivityTimeout(duration)`** **`inbound.WithInactivityTimeout(duration)`**
Enables the inactivity watchdog. When no data messages or pong replies arrive within this duration, the peer is evicted and `InboundEventEvictedPolicy` is emitted. When set to zero, the watchdog is disabled and connections persist until removed or remotely terminated. Must not be negative. Enables the inactivity watchdog. When no data messages or pong replies arrive within this duration, the peer is evicted and `inbound.EventEvictedPolicy` is emitted. When set to zero, the watchdog is disabled and connections persist until removed or remotely terminated. Must not be negative.
**`WithInboundMaxQueueSize(int)`** **`inbound.WithMaxQueueSize(int)`**
Bounds the worker's internal message queue. When the queue is full, the oldest undelivered message is dropped. When set to zero, the queue is unbounded. Must not be negative. Bounds the worker's internal message queue. When the queue is full, the oldest undelivered message is dropped. When set to zero, the queue is unbounded. Must not be negative.
**`WithInboundWorkerLoggingEnabled(bool)`** **`inbound.WithWorkerLoggingEnabled(bool)`**
Enables or disables worker-level logging. Enables or disables worker-level logging.
**`WithInboundWorkerLogLevel(slog.Level)`** **`inbound.WithWorkerLogLevel(slog.Level)`**
Overrides the minimum log level for worker-scoped records only. Overrides the minimum log level for worker-scoped records only.
### Wiring ### Wiring
**`WithInboundConnectionConfig(*ConnectionConfig)`** **`inbound.WithConnectionConfig(*transport.ConnectionConfig)`**
Supplies a connection config that is applied to every socket added to the pool. Supplies a connection config that is applied to every socket added to the pool.
**`WithInboundWorkerConfig(*WorkerConfig)`** **`inbound.WithWorkerConfig(*inbound.WorkerConfig)`**
Supplies a worker config that is applied to every worker the pool creates. Supplies a worker config that is applied to every worker the pool creates.
**`WithInboundWorkerFactory(WorkerFactory)`** **`inbound.WithWorkerFactory(inbound.WorkerFactory)`**
Replaces the default worker constructor. See [EXTEND.md](EXTEND.md) for the factory contract. Replaces the default worker constructor. See [EXTEND.md](EXTEND.md) for the factory contract.
## Outbound Pool Options ## Outbound Pool Options
Import `git.wisehodl.dev/jay/go-honeybee/outbound`.
### Pool ### Pool
These are passed to `NewOutboundPoolConfig`. These are passed to `outbound.NewPoolConfig`.
**`WithOutboundInboxBufferSize(int)`** **`outbound.WithInboxBufferSize(int)`**
Sets the capacity of the pool's shared inbox channel. Must be at least 1. Sets the capacity of the pool's shared inbox channel. Must be at least 1.
**`WithOutboundEventsBufferSize(int)`** **`outbound.WithEventsBufferSize(int)`**
Sets the capacity of the pool's events channel. Must be at least 1. Sets the capacity of the pool's events channel. Must be at least 1.
**`WithOutboundPoolLoggingEnabled(bool)`** **`outbound.WithPoolLoggingEnabled(bool)`**
Enables or disables pool-level logging. Enables or disables pool-level logging.
**`WithOutboundPoolLogLevel(slog.Level)`** **`outbound.WithPoolLogLevel(slog.Level)`**
Overrides the minimum log level for pool-scoped records only. Overrides the minimum log level for pool-scoped records only.
### Worker ### Worker
These are passed to `NewOutboundWorkerConfig` or embedded in the pool config. These are passed to `outbound.NewWorkerConfig` or embedded in the pool config.
**`WithOutboundKeepaliveTimeout(duration)`** **`outbound.WithKeepaliveTimeout(duration)`**
Enables the keepalive mechanism. When no heartbeat (inbound data, outbound send, or pong reply) is observed within this duration, the current connection is closed and a new one is dialed. When set to zero, keepalive is disabled. Must not be negative. Enables the keepalive mechanism. When no heartbeat (inbound data, outbound send, or pong reply) is observed within this duration, the current connection is closed and a new one is dialed. When set to zero, keepalive is disabled. Must not be negative.
**`WithReconnectDelay(duration)`** **`outbound.WithReconnectDelay(duration)`**
Sets the delay between a disconnect and the next dial attempt. Applies after every session end, including those triggered by keepalive. The default of 2 seconds prevents tight reconnect loops against unavailable peers. Set to zero in tests or when immediate reconnection is required. Must not be negative. Sets the delay between a disconnect and the next dial attempt. Applies after every session end, including those triggered by keepalive. The default of 2 seconds prevents tight reconnect loops against unavailable peers. Set to zero in tests or when immediate reconnection is required. Must not be negative.
**`WithOutboundMaxQueueSize(int)`** **`outbound.WithMaxQueueSize(int)`**
Bounds the worker's internal message queue. When the queue is full, the oldest undelivered message is dropped. When set to zero, the queue is unbounded. Must not be negative. Bounds the worker's internal message queue. When the queue is full, the oldest undelivered message is dropped. When set to zero, the queue is unbounded. Must not be negative.
**`WithOutboundWorkerLoggingEnabled(bool)`** **`outbound.WithWorkerLoggingEnabled(bool)`**
Enables or disables worker-level logging. Enables or disables worker-level logging.
**`WithOutboundWorkerLogLevel(slog.Level)`** **`outbound.WithWorkerLogLevel(slog.Level)`**
Overrides the minimum log level for worker-scoped records only. Overrides the minimum log level for worker-scoped records only.
### Wiring ### Wiring
**`WithOutboundConnectionConfig(*ConnectionConfig)`** **`outbound.WithConnectionConfig(*transport.ConnectionConfig)`**
Supplies a connection config used when dialing each peer. Supplies a connection config used when dialing each peer.
**`WithOutboundWorkerConfig(*WorkerConfig)`** **`outbound.WithWorkerConfig(*outbound.WorkerConfig)`**
Supplies a worker config applied to every worker the pool creates. Supplies a worker config applied to every worker the pool creates.
**`WithOutboundWorkerFactory(WorkerFactory)`** **`outbound.WithWorkerFactory(outbound.WorkerFactory)`**
Replaces the default worker constructor. See [EXTEND.md](EXTEND.md) for the factory contract. Replaces the default worker constructor. See [EXTEND.md](EXTEND.md) for the factory contract.
## Defaults ## Defaults
+23 -11
View File
@@ -30,18 +30,30 @@ The behavioral contract for each method:
The pool constructs a `PoolPlugin` and passes it to `Start`. It gives the worker access to pool-level channels and the logging handler. The pool constructs a `PoolPlugin` and passes it to `Start`. It gives the worker access to pool-level channels and the logging handler.
```go ```go
// inbound.PoolPlugin
type PoolPlugin struct { type PoolPlugin struct {
Inbox chan<- InboxMessage Inbox chan<- inbound.InboxMessage
Events chan<- PoolEvent Events chan<- inbound.PoolEvent
InboxCounter *atomic.Uint64 InboxCounter *atomic.Uint64
OnExit OnExitFunction // inbound only OnExit inbound.OnExitFunction // inbound only
Handler slog.Handler Handler slog.Handler
} }
// outbound.PoolPlugin
type PoolPlugin struct {
ID string
Inbox chan<- outbound.InboxMessage
Events chan<- outbound.PoolEvent
InboxCounter *atomic.Uint64
Dialer outbound.Dialer
ConnectionConfig *transport.ConnectionConfig
Handler slog.Handler
}
``` ```
**`Inbox`** The shared channel that delivers received messages to the pool's consumer. All peers in the pool deliver to the same inbox channel. Workers must include their peer ID in each `InboxMessage`. **`Inbox`** The shared channel that delivers received messages to the pool's consumer. All peers in the pool deliver to the same inbox channel. Workers must include their peer ID in each `InboxMessage`.
**`Events`** The shared channel for lifecycle events. Outbound workers emit `EventConnected` and `EventDisconnected` directly. Inbound workers do not touch this channel directly; instead they call `OnExit`, and the pool translates the exit kind into the appropriate event. All events include a timestamp in the `At` field. **`Events`** The shared channel for lifecycle events. Outbound workers emit `outbound.EventConnected` and `outbound.EventDisconnected` directly. Inbound workers do not touch this channel directly; instead they call `OnExit`, and the pool translates the exit kind into the appropriate event. All events include a timestamp in the `At` field.
**`InboxCounter`** An atomic counter owned by the pool. Workers must increment this once for each message forwarded to `Inbox`. The pool reads it in `Stats()`. **`InboxCounter`** An atomic counter owned by the pool. Workers must increment this once for each message forwarded to `Inbox`. The pool reads it in `Stats()`.
@@ -54,18 +66,18 @@ type PoolPlugin struct {
### Factory Signature ### Factory Signature
```go ```go
type WorkerFactory func( type inbound.WorkerFactory func(
ctx context.Context, ctx context.Context,
id string, id string,
conn *transport.Connection, conn *transport.Connection,
config *WorkerConfig, config *inbound.WorkerConfig,
logger *slog.Logger, logger *slog.Logger,
) (Worker, error) ) (inbound.Worker, error)
``` ```
The pool calls the factory under its write lock when `Add` or `Replace` is called. The factory must return without blocking. The pool constructs `logger` from the worker logging config before calling the factory; pass it to your worker or ignore it. The pool calls the factory under its write lock when `Add` or `Replace` is called. The factory must return without blocking. The pool constructs `logger` from the worker logging config before calling the factory; pass it to your worker or ignore it.
The factory is set via `WithInboundWorkerFactory` on the pool config. The factory is set via `inbound.WithWorkerFactory` on the pool config.
### Building Blocks ### Building Blocks
@@ -94,16 +106,16 @@ The default inbound worker is assembled from these exported functions. Each can
### Factory Signature ### Factory Signature
```go ```go
type WorkerFactory func( type outbound.WorkerFactory func(
ctx context.Context, ctx context.Context,
id string, id string,
logger *slog.Logger, logger *slog.Logger,
) (Worker, error) ) (outbound.Worker, error)
``` ```
The pool calls the factory under its write lock when `Connect` is called. The factory must return without blocking. Note that the outbound factory does not receive a `*transport.Connection`; the worker is responsible for dialing and managing its own connections. The pool constructs `logger` from the worker logging config before calling the factory. The pool calls the factory under its write lock when `Connect` is called. The factory must return without blocking. Note that the outbound factory does not receive a `*transport.Connection`; the worker is responsible for dialing and managing its own connections. The pool constructs `logger` from the worker logging config before calling the factory.
The factory is set via `WithOutboundWorkerFactory` on the pool config. The factory is set via `outbound.WithWorkerFactory` on the pool config.
### Building Blocks ### Building Blocks
+26 -22
View File
@@ -5,8 +5,6 @@ WebSocket connection and pool primitives in Go. Built for Nostr.
## Library Map ## Library Map
```txt ```txt
honeybee.go top-level re-exports and constructors
transport/ single-connection primitives transport/ single-connection primitives
connection.go *Connection, state machine, reader goroutine, pinger connection.go *Connection, state machine, reader goroutine, pinger
config.go ConnectionConfig, RetryConfig, options config.go ConnectionConfig, RetryConfig, options
@@ -27,7 +25,7 @@ outbound/ pool for self-initiated connections
logging/ structured log construction logging/ structured log construction
logging.go logger constructors, ForcedLevelHandler logging.go logger constructors, ForcedLevelHandler
types/ shared interfaces (Dialer, Socket) types/ internal interfaces
honeybeetest/ test helpers and mocks for consumers honeybeetest/ test helpers and mocks for consumers
```` ````
@@ -71,10 +69,12 @@ replace git.wisehodl.dev/jay/go-honeybee => github.com/wisehodl/go-honeybee late
### Bare Connection ### Bare Connection
A `Connection` wraps a single WebSocket. Use it directly when you need one socket and do not want pool semantics. Use `transport` directly when you need one socket and do not want pool semantics.
```go ```go
conn, err := honeybee.NewConnection("wss://example.com", nil, nil) import "git.wisehodl.dev/jay/go-honeybee/transport"
conn, err := transport.NewConnection("wss://example.com", nil, nil)
if err != nil { /* handle error */ } if err != nil { /* handle error */ }
if err := conn.Connect(ctx); err != nil { /* handle error */ } if err := conn.Connect(ctx); err != nil { /* handle error */ }
@@ -116,7 +116,9 @@ The inbound pool manages connections initiated by peers. The consumer accepts a
Each pool requires a non-empty string ID. This ID is attached to all structured log records emitted by the pool, its workers, and their connections. Each pool requires a non-empty string ID. This ID is attached to all structured log records emitted by the pool, its workers, and their connections.
```go ```go
pool, err := honeybee.NewInboundPool(ctx, "my-pool", nil, handler) import "git.wisehodl.dev/jay/go-honeybee/inbound"
pool, err := inbound.NewPool(ctx, "my-pool", nil, handler)
if err != nil { /* handle error */ } if err != nil { /* handle error */ }
defer pool.Close() defer pool.Close()
@@ -137,10 +139,10 @@ go func() {
for ev := range pool.Events() { for ev := range pool.Events() {
// ev.At is the event timestamp // ev.At is the event timestamp
switch ev.Kind { switch ev.Kind {
case honeybee.InboundEventDisconnected: // clean close case inbound.EventDisconnected: // clean close
case honeybee.InboundEventDroppedClose: // peer closed with abnormal code case inbound.EventDroppedClose: // peer closed with abnormal code
case honeybee.InboundEventDroppedError: // read error case inbound.EventDroppedError: // read error
case honeybee.InboundEventEvictedPolicy: // inactivity timeout case inbound.EventEvictedPolicy: // inactivity timeout
} }
} }
}() }()
@@ -152,7 +154,7 @@ pool.Send(peerID, []byte("response"))
Use `Replace` if you need to swap the socket for a peer while keeping its ID. No events are emitted during this process. Use `Replace` if you need to swap the socket for a peer while keeping its ID. No events are emitted during this process.
The watchdog is configured via `WithInboundInactivityTimeout`. When set to zero, it is disabled. When set, the watchdog observes message traffic and disconnects the peer if no messages arrive within the configured duration. The watchdog is disabled by default, meaning connections persist until manually removed or remotely terminated. The watchdog is configured via `inbound.WithInactivityTimeout`. When set to zero, it is disabled. When set, the watchdog observes message traffic and disconnects the peer if no messages arrive within the configured duration. The watchdog is disabled by default, meaning connections persist until manually removed or remotely terminated.
### Outbound Pool ### Outbound Pool
@@ -161,7 +163,9 @@ The outbound pool connects to peers by their URLs and keeps them connected. It r
Each pool requires a non-empty string ID. This ID is attached to all structured log records emitted by the pool, its workers, and their connections. Each pool requires a non-empty string ID. This ID is attached to all structured log records emitted by the pool, its workers, and their connections.
```go ```go
pool, err := honeybee.NewOutboundPool(ctx, "my-pool", nil, handler) import "git.wisehodl.dev/jay/go-honeybee/outbound"
pool, err := outbound.NewPool(ctx, "my-pool", nil, handler)
if err != nil { /* handle error */ } if err != nil { /* handle error */ }
defer pool.Close() defer pool.Close()
@@ -179,8 +183,8 @@ go func() {
for ev := range pool.Events() { for ev := range pool.Events() {
// ev.At is the event timestamp // ev.At is the event timestamp
switch ev.Kind { switch ev.Kind {
case honeybee.OutboundEventConnected: case outbound.EventConnected:
case honeybee.OutboundEventDisconnected: case outbound.EventDisconnected:
} }
} }
}() }()
@@ -188,11 +192,11 @@ go func() {
pool.Send("wss://peer.example.com", []byte("hello")) pool.Send("wss://peer.example.com", []byte("hello"))
``` ```
URLs are normalized by the pool. `wss://peer.example.com`, `wss://peer.example.com/`, and `WSS://Peer.Example.Com:443` all identify the same peer. `honeybee.NormalizeURL` is also available directly if you need to use the same URLs as keys elsewhere. URLs are normalized by the pool. `wss://peer.example.com`, `wss://peer.example.com/`, and `WSS://Peer.Example.Com:443` all identify the same peer. `outbound.NormalizeURL` is also available directly if you need to use the same URLs as keys elsewhere.
Every time a connection is established, `OutboundEventConnected` is emitted. Every time a connection drops for any reason, `OutboundEventDisconnected` is emitted. A peer that reconnects three times produces three Connected/Disconnected pairs. Every time a connection is established, `outbound.EventConnected` is emitted. Every time a connection drops for any reason, `outbound.EventDisconnected` is emitted. A peer that reconnects three times produces three Connected/Disconnected pairs.
Keepalive is configured via `WithOutboundKeepaliveTimeout`. The worker records a heartbeat on every inbound message, every successful send, and every received pong. If no heartbeats arrive before the keepalive timer fires, the connection is proactively disconnected and reconnected. When set to zero, keepalive is disabled. Keepalive is configured via `outbound.WithKeepaliveTimeout`. The worker records a heartbeat on every inbound message, every successful send, and every received pong. If no heartbeats arrive before the keepalive timer fires, the connection is proactively disconnected and reconnected. When set to zero, keepalive is disabled.
After a disconnect, the worker waits for `ReconnectDelay` before attempting the next connection. The default is 2 seconds. Set to zero in tests or when you need immediate reconnection. After a disconnect, the worker waits for `ReconnectDelay` before attempting the next connection. The default is 2 seconds. Set to zero in tests or when you need immediate reconnection.
@@ -208,7 +212,7 @@ For inbound workers, pong-derived heartbeats reset the inactivity watchdog timer
For outbound workers, pong-derived heartbeats reset the keepalive timer. A peer that sends no data but responds to pings will not be disconnected and reconnected by the keepalive mechanism. For outbound workers, pong-derived heartbeats reset the keepalive timer. A peer that sends no data but responds to pings will not be disconnected and reconnected by the keepalive mechanism.
The ping interval is configured via `WithPingInterval` on the `ConnectionConfig`. The default is 20 seconds. Set to zero to disable pings entirely, in which case only data messages and outbound sends generate heartbeats. The ping interval is configured via `transport.WithPingInterval` on the `transport.ConnectionConfig`. Import `git.wisehodl.dev/jay/go-honeybee/transport` to construct a `ConnectionConfig`, then pass it to the pool via `inbound.WithConnectionConfig` or `outbound.WithConnectionConfig`. The default is 20 seconds. Set to zero to disable pings entirely, in which case only data messages and outbound sends generate heartbeats.
## Statistics ## Statistics
@@ -228,8 +232,8 @@ peerStats, err := pool.PeerStats(peerID)
// peerStats.Worker — queue depths, buffer depth, processed/dropped/sent counts // peerStats.Worker — queue depths, buffer depth, processed/dropped/sent counts
// peerStats.Connection — channel depths, receive/send/heartbeat counts (inbound) // peerStats.Connection — channel depths, receive/send/heartbeat counts (inbound)
// Bare connection // Bare connection (transport package)
connStats := conn.Stats() connStats := conn.Stats() // conn is a *transport.Connection
// connStats.TotalReceived, connStats.TotalSent, connStats.TotalHeartbeats // connStats.TotalReceived, connStats.TotalSent, connStats.TotalHeartbeats
``` ```
@@ -263,8 +267,8 @@ go test -race ./...
The `honeybeetest` package provides mocks and assertions for code that builds on Honeybee: The `honeybeetest` package provides mocks and assertions for code that builds on Honeybee:
- `MockSocket` implements `types.Socket` with pluggable function fields for every method, including `WriteControl` and `SetPongHandler`. - `MockSocket` implements `honeybeetest.Socket` with pluggable function fields for every method, including `WriteControl` and `SetPongHandler`.
- `MockDialer` implements `types.Dialer` with a pluggable `DialContextFunc`. - `MockDialer` implements `honeybeetest.Dialer` with a pluggable `DialContextFunc`.
- `MockSlogHandler` captures `slog` records for assertions against log output. Child handlers produced via `WithAttrs` share the same record slice as the parent, so attributes added by the logging package appear on the correct records. - `MockSlogHandler` captures `slog` records for assertions against log output. Child handlers produced via `WithAttrs` share the same record slice as the parent, so attributes added by the logging package appear on the correct records.
- `Eventually(t, condition, msg)` polls a condition until it holds or the test timeout expires. - `Eventually(t, condition, msg)` polls a condition until it holds or the test timeout expires.
- `Never(t, condition, msg)` asserts a condition never holds over a short window. - `Never(t, condition, msg)` asserts a condition never holds over a short window.
-181
View File
@@ -1,181 +0,0 @@
package honeybee
import (
"context"
"log/slog"
"git.wisehodl.dev/jay/go-honeybee/inbound"
"git.wisehodl.dev/jay/go-honeybee/outbound"
"git.wisehodl.dev/jay/go-honeybee/transport"
"git.wisehodl.dev/jay/go-honeybee/types"
)
// Functions
func NormalizeURL(input string) (string, error) {
return transport.NormalizeURL(input)
}
// Connection types
type Connection = transport.Connection
type ConnectionConfig = transport.ConnectionConfig
type RetryConfig = transport.RetryConfig
type ConnectionOption = transport.ConnectionOption
type ConnectionStats = transport.ConnectionStats
// Common Types
type InboxMessage = types.InboxMessage
// Outbound Pool types
type OutboundPool = outbound.Pool
type OutboundPoolConfig = outbound.PoolConfig
type OutboundPoolOption = outbound.PoolOption
type OutboundWorkerConfig = outbound.WorkerConfig
type OutboundWorkerOption = outbound.WorkerOption
type OutboundPoolEvent = outbound.PoolEvent
type OutboundPoolEventKind = outbound.PoolEventKind
type OutboundPoolStats = outbound.PoolStats
type OutboundWorkerStats = outbound.WorkerStats
// Pool event constants
const (
OutboundEventConnected = outbound.EventConnected
OutboundEventDisconnected = outbound.EventDisconnected
)
// Inbound Pool types
type InboundPool = inbound.Pool
type InboundPoolConfig = inbound.PoolConfig
type InboundPoolOption = inbound.PoolOption
type InboundWorkerConfig = inbound.WorkerConfig
type InboundWorkerOption = inbound.WorkerOption
type InboundWorkerFactory = inbound.WorkerFactory
type InboundWorker = inbound.Worker
type InboundWorkerExitKind = inbound.WorkerExitKind
type InboundPoolEvent = inbound.PoolEvent
type InboundPoolEventKind = inbound.PoolEventKind
type InboundPoolStats = inbound.PoolStats
type InboundWorkerStats = inbound.WorkerStats
// Inbound Pool event constants
const (
InboundEventDisconnected = inbound.EventDisconnected
InboundEventDroppedClose = inbound.EventDroppedClose
InboundEventDroppedError = inbound.EventDroppedError
InboundEventEvictedPolicy = inbound.EventEvictedPolicy
)
// Inbound Worker exit kinds
const (
InboundExitDisconnected = inbound.ExitDisconnected
InboundExitUnexpectedClose = inbound.ExitUnexpectedClose
InboundExitReadError = inbound.ExitReadError
InboundExitPolicy = inbound.ExitPolicy
)
// Connection constructors
func NewConnection(url string, config *ConnectionConfig, logger *slog.Logger) (*Connection, error) {
return transport.NewConnection(url, config, logger)
}
func NewConnectionConfig(opts ...ConnectionOption) (*ConnectionConfig, error) {
return transport.NewConnectionConfig(opts...)
}
// Connection options
var (
WithIncomingBufferSize = transport.WithIncomingBufferSize
WithErrorsBufferSize = transport.WithErrorsBufferSize
WithoutRetry = transport.WithoutRetry
WithRetryMaxRetries = transport.WithRetryMaxRetries
WithRetryInitialDelay = transport.WithRetryInitialDelay
WithRetryMaxDelay = transport.WithRetryMaxDelay
WithRetryJitterFactor = transport.WithRetryJitterFactor
WithWriteTimeout = transport.WithWriteTimeout
WithCloseHandler = transport.WithCloseHandler
WithConnectionLoggingEnabled = transport.WithLoggingEnabled
WithConnectionLogLevel = transport.WithLogLevel
)
// Outbound Pool constructors
func NewOutboundPool(ctx context.Context, id string, config *OutboundPoolConfig, handler slog.Handler) (*OutboundPool, error) {
return outbound.NewPool(ctx, id, config, handler)
}
func NewOutboundPoolConfig(opts ...OutboundPoolOption) (*OutboundPoolConfig, error) {
return outbound.NewPoolConfig(opts...)
}
func NewOutboundWorkerConfig(opts ...OutboundWorkerOption) (*OutboundWorkerConfig, error) {
return outbound.NewWorkerConfig(opts...)
}
// Outbound Pool options
var (
WithOutboundInboxBufferSize = outbound.WithInboxBufferSize
WithOutboundEventsBufferSize = outbound.WithEventsBufferSize
WithOutboundPoolLoggingEnabled = outbound.WithPoolLoggingEnabled
WithOutboundPoolLogLevel = outbound.WithPoolLogLevel
WithOutboundConnectionConfig = outbound.WithConnectionConfig
WithOutboundWorkerConfig = outbound.WithWorkerConfig
WithOutboundWorkerFactory = outbound.WithWorkerFactory
)
// Outbound Worker options
var (
WithOutboundKeepaliveTimeout = outbound.WithKeepaliveTimeout
WithOutboundMaxQueueSize = outbound.WithMaxQueueSize
WithOutboundWorkerLoggingEnabled = outbound.WithWorkerLoggingEnabled
WithOutboundWorkerLogLevel = outbound.WithWorkerLogLevel
)
// Inbound Pool constructors
func NewInboundPool(ctx context.Context, id string, config *InboundPoolConfig, handler slog.Handler) (*InboundPool, error) {
return inbound.NewPool(ctx, id, config, handler)
}
func NewInboundPoolConfig(opts ...InboundPoolOption) (*InboundPoolConfig, error) {
return inbound.NewPoolConfig(opts...)
}
func NewInboundWorkerConfig(opts ...InboundWorkerOption) (*InboundWorkerConfig, error) {
return inbound.NewWorkerConfig(opts...)
}
// Inbound Pool options
var (
WithInboundInboxBufferSize = inbound.WithInboxBufferSize
WithInboundEventsBufferSize = inbound.WithEventsBufferSize
WithInboundPoolLoggingEnabled = inbound.WithPoolLoggingEnabled
WithInboundPoolLogLevel = inbound.WithPoolLogLevel
WithInboundConnectionConfig = inbound.WithConnectionConfig
WithInboundWorkerConfig = inbound.WithWorkerConfig
WithInboundWorkerFactory = inbound.WithWorkerFactory
)
// Inbound Worker options
var (
WithInboundInactivityTimeout = inbound.WithInactivityTimeout
WithInboundMaxQueueSize = inbound.WithMaxQueueSize
WithInboundWorkerLoggingEnabled = inbound.WithWorkerLoggingEnabled
WithInboundWorkerLogLevel = inbound.WithWorkerLogLevel
)
// Socket type — needed for inbound pool.Add and pool.Replace
type Socket = types.Socket
+5
View File
@@ -9,6 +9,11 @@ import (
"time" "time"
) )
// Re-exported types for consumer convenience
type Socket = types.Socket
type Dialer = types.Dialer
// Dialer Mocks // Dialer Mocks
type MockDialer struct { type MockDialer struct {
+7
View File
@@ -12,6 +12,13 @@ import (
"time" "time"
) )
// Re-exported types for consumer convenience
type Socket = types.Socket
type InboxMessage = types.InboxMessage
var NormalizeURL = transport.NormalizeURL
// Types // Types
type PoolEventKind string type PoolEventKind string
+7
View File
@@ -11,6 +11,13 @@ import (
"time" "time"
) )
// Re-exported types for consumer convenience
type InboxMessage = types.InboxMessage
type Dialer = types.Dialer
var NormalizeURL = transport.NormalizeURL
// Types // Types
type PoolEventKind string type PoolEventKind string