Documentation
¶
Index ¶
Constants ¶
const CName = "common.net.streampool"
Variables ¶
This section is empty.
Functions ¶
func CtxStreamId ¶ added in v0.13.0
CtxStreamId returns the id of the stream that delivered the current message. It is set on the context passed to StreamHandler.HandleMessage, letting a handler key per-stream state (e.g. subscription interest) so that two streams from the same peer stay independent.
Types ¶
type ExecPool ¶ added in v0.1.2
type ExecPool struct {
// contains filtered or unexported fields
}
ExecPool needed for parallel execution of the incoming send tasks
func NewExecPool ¶ added in v0.1.2
NewExecPool creates new ExecPool workers - how many processes will execute tasks maxSize - limit for queue size
type MessageQueueId ¶
type Option ¶ added in v0.13.0
type Option func(*streamPool)
Option configures a standalone pool created with NewStreamPool.
func WithMetric ¶ added in v0.13.0
WithMetric registers the standalone pool's prometheus gauges (stream_count, tag_count, dial_queue) under the given namespace prefix, so a service that owns a private pool (e.g. pubsub) is observable even though it never runs the app-component Init.
It deliberately does NOT call RegisterStreamPoolSyncMetric: that feeds a single shared slot on the metric component meant for the one app-level sync streampool, and registering a second pool there would overwrite (and, on Close, null) the sync pool's OutgoingMsg telemetry. The namespaced gauges below give the private pool independent observability without touching that slot.
func WithStreamCloseHook ¶ added in v0.13.0
WithStreamCloseHook registers a callback invoked after a stream is removed from the pool, outside the pool lock, with the closed stream's id, peerId and the tags it carried. The streamId lets a handler clean up per-stream state keyed on CtxStreamId even when several streams share a peerId.
type PeerGetter ¶
PeerGetter should dial or return cached peers
type SizeableMessage ¶ added in v0.3.9
type SizeableMessage interface {
Size() int
}
type StreamConfig ¶
type StreamPool ¶
type StreamPool interface {
app.ComponentRunnable
// AddStream adds new outgoing stream into the pool
AddStream(stream drpc.Stream, queueSize int, tags ...string) (err error)
// ReadStream adds new incoming stream and synchronously reads it
ReadStream(stream drpc.Stream, queueSize int, tags ...string) (err error)
// Send sends a message to given peers. A stream will be opened if it is not cached before. Works async.
Send(ctx context.Context, msg drpc.Message, target PeerGetter) (err error)
// SendById sends a message to given peerIds. Works only if stream exists
SendById(ctx context.Context, msg drpc.Message, peerIds ...string) (err error)
// Broadcast sends a message to all peers with given tags. Works async.
Broadcast(ctx context.Context, msg drpc.Message, tags ...string) (err error)
// AddTagsCtx adds tags to stream, stream will be extracted from ctx
AddTagsCtx(ctx context.Context, tags ...string) error
// RemoveTagsCtx removes tags from stream, stream will be extracted from ctx
RemoveTagsCtx(ctx context.Context, tags ...string) error
// RemoveTagsById removes tags from a specific stream by id, for callers that
// track streamId out of band. Missing streams and tags are ignored.
RemoveTagsById(streamId uint32, tags ...string) error
// Streams gets all streams for specific tags
Streams(tags ...string) (streams []drpc.Stream)
}
StreamPool stores opened streams, and it processes them using StreamHandler It opens a stream using StreamHandler.OpenStream method, if needed. Also, it could send requests to tagged streams or just to specific peers. For example, a stream could be tagged with a specific spaceId.
func New ¶
func New() StreamPool
func NewStreamPool ¶ added in v0.13.0
func NewStreamPool(handler streamhandler.StreamHandler, cfg StreamConfig, opts ...Option) StreamPool
NewStreamPool creates a standalone pool with explicit dependencies, for services that own a private pool (e.g. pubsub) instead of sharing the app-level component. The caller must not register it in the app and is responsible for calling Run(ctx) and Close(ctx); Init must not be called.