{"modulePath":"github.com/benthosdev/benthos","version":"v0.26.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package buffer\n\nPackage buffer is both a types.Consumer and types.Producer implementation that is able to sit between other stream components, effectively decoupling their transaction channels by storing messages in a buffer implementation.\n\nBuffers are not needed within Benthos, and should not be used unless there is a specific problem to be solved with one.\n\n## Constants\n\n```go\nconst (\n\tTypeMemory = \"memory\"\n\tTypeMMAP   = \"mmap_file\"\n\tTypeNone   = \"none\"\n)\n```\nString constants representing each buffer type.\n\n## Variables\n\n```go\nvar Constructors = map[string]TypeSpec{}\n```\nConstructors is a map of all buffer types with their specs.\n\n## Functions\n\n```go\nfunc Descriptions() string\n```\nDescriptions returns a formatted string of collated descriptions of each type.\n\n```go\nfunc SanitiseConfig(conf Config) (interface{}, error)\n```\nSanitiseConfig returns a sanitised version of the Config, meaning sections that aren't relevant to behaviour are removed.\n\n## Types\n\n```go\ntype Config struct {\n\tType   string                  `json:\"type\" yaml:\"type\"`\n\tMemory single.MemoryConfig     `json:\"memory\" yaml:\"memory\"`\n\tMmap   single.MmapBufferConfig `json:\"mmap_file\" yaml:\"mmap_file\"`\n\tNone   struct{}                `json:\"none\" yaml:\"none\"`\n}\n```\nConfig is the all encompassing configuration struct for all buffer types.\n\n```go\nfunc NewConfig() Config\n```\nNewConfig returns a configuration struct fully populated with default values.\n\n```go\ntype Empty struct {\n\t// contains filtered or unexported fields\n}\n```\nEmpty is an empty buffer, simply forwards messages on directly.\n\n```go\nfunc (e *Empty) CloseAsync()\n```\nCloseAsync shuts down the StackBuffer output and stops processing messages.\n\n```go\nfunc (e *Empty) Consume(msgs \u003c-chan types.Transaction) error\n```\nConsume assigns a messages channel for the output to read.\n\n```go\nfunc (e *Empty) ErrorsChan() \u003c-chan []error\n```\nErrorsChan returns the errors channel.\n\n```go\nfunc (e *Empty) StopConsuming()\n```\nStopConsuming instructs the buffer to no longer consume data.\n\n```go\nfunc (e *Empty) TransactionChan() \u003c-chan types.Transaction\n```\nTransactionChan returns the channel used for consuming messages from this input.\n\n```go\nfunc (e *Empty) WaitForClose(timeout time.Duration) error\n```\nWaitForClose blocks until the StackBuffer output has closed down.\n\n```go\ntype Parallel interface {\n\t// NextMessage reads the next oldest message, the message is preserved until\n\t// the returned AckFunc is called.\n\tNextMessage() (types.Message, parallel.AckFunc, error)\n\n\t// PushMessage adds a new message to the stack. Returns the backlog in\n\t// bytes.\n\tPushMessage(types.Message) (int, error)\n\n\t// CloseOnceEmpty closes the Buffer once the buffer has been emptied, this\n\t// is a way for a writer to signal to a reader that it is finished writing\n\t// messages, and therefore the reader can close once it is caught up. This\n\t// call blocks until the close is completed.\n\tCloseOnceEmpty()\n\n\t// Close closes the Buffer so that blocked readers or writers become\n\t// unblocked.\n\tClose()\n}\n```\nParallel represents a method of buffering messages such that they can be consumed by any number of parallel consumers, and can be acknowledged in any order.\n\n```go\ntype ParallelWrapper struct {\n\t// contains filtered or unexported fields\n}\n```\nParallelWrapper wraps a buffer with a Producer/Consumer interface.\n\n```go\nfunc (m *ParallelWrapper) CloseAsync()\n```\nCloseAsync shuts down the ParallelWrapper and stops processing messages.\n\n```go\nfunc (m *ParallelWrapper) Consume(msgs \u003c-chan types.Transaction) error\n```\nConsume assigns a messages channel for the output to read.\n\n```go\nfunc (m *ParallelWrapper) StopConsuming()\n```\nStopConsuming instructs the buffer to stop consuming messages and close once the buffer is empty.\n\n```go\nfunc (m *ParallelWrapper) TransactionChan() \u003c-chan types.Transaction\n```\nTransactionChan returns the channel used for consuming messages from this buffer.\n\n```go\nfunc (m *ParallelWrapper) WaitForClose(timeout time.Duration) error\n```\nWaitForClose blocks until the ParallelWrapper output has closed down.\n\n```go\ntype Single interface {\n\t// ShiftMessage removes the oldest message from the stack. Returns the\n\t// backlog in bytes.\n\tShiftMessage() (int, error)\n\n\t// NextMessage reads the oldest message, the message is preserved until\n\t// ShiftMessage is called.\n\tNextMessage() (types.Message, error)\n\n\t// PushMessage adds a new message to the stack. Returns the backlog in\n\t// bytes.\n\tPushMessage(types.Message) (int, error)\n\n\t// CloseOnceEmpty closes the Buffer once the buffer has been emptied, this\n\t// is a way for a writer to signal to a reader that it is finished writing\n\t// messages, and therefore the reader can close once it is caught up. This\n\t// call blocks until the close is completed.\n\tCloseOnceEmpty()\n\n\t// Close closes the Buffer so that blocked readers or writers become\n\t// unblocked.\n\tClose()\n}\n```\nSingle represents a method of buffering sequential messages, supporting only a single, sequential consumer.\n\n```go\ntype SingleWrapper struct {\n\t// contains filtered or unexported fields\n}\n```\nSingleWrapper wraps a buffer with a Producer/Consumer interface.\n\n```go\nfunc (m *SingleWrapper) CloseAsync()\n```\nCloseAsync shuts down the SingleWrapper and stops processing messages.\n\n```go\nfunc (m *SingleWrapper) Consume(msgs \u003c-chan types.Transaction) error\n```\nConsume assigns a messages channel for the output to read.\n\n```go\nfunc (m *SingleWrapper) StopConsuming()\n```\nStopConsuming instructs the buffer to stop consuming messages and close once the buffer is empty.\n\n```go\nfunc (m *SingleWrapper) TransactionChan() \u003c-chan types.Transaction\n```\nTransactionChan returns the channel used for consuming messages from this buffer.\n\n```go\nfunc (m *SingleWrapper) WaitForClose(timeout time.Duration) error\n```\nWaitForClose blocks until the SingleWrapper output has closed down.\n\n```go\ntype Type interface {\n\ttypes.Producer\n\ttypes.Consumer\n\ttypes.Closable\n\n\t// StopConsuming instructs the buffer to cut off the producer it is\n\t// consuming from. It will then enter a mode whereby messages can only be\n\t// read, and when the buffer is empty it will shut down.\n\tStopConsuming()\n}\n```\nType is an interface implemented by all buffer types.\n\n```go\nfunc New(conf Config, log log.Modular, stats metrics.Type) (Type, error)\n```\nNew creates a buffer type based on a buffer configuration.\n\n```go\nfunc NewEmpty(config Config, log log.Modular, stats metrics.Type) (Type, error)\n```\nNewEmpty creates a new buffer interface but doesn't buffer messages.\n\n```go\nfunc NewMemory(config Config, log log.Modular, stats metrics.Type) (Type, error)\n```\nNewMemory - Create a buffer held in memory.\n\n```go\nfunc NewMmapFile(config Config, log log.Modular, stats metrics.Type) (Type, error)\n```\nNewMmapFile creates a buffer held in memory and persisted to file through memory map.\n\n```go\nfunc NewParallelWrapper(\n\tconf Config,\n\tbuffer Parallel,\n\tlog log.Modular,\n\tstats metrics.Type,\n) Type\n```\nNewParallelWrapper creates a new Producer/Consumer around a buffer.\n\n```go\nfunc NewSingleWrapper(\n\tconf Config,\n\tbuffer Single,\n\tlog log.Modular,\n\tstats metrics.Type,\n) Type\n```\nNewSingleWrapper creates a new Producer/Consumer around a buffer.\n\n```go\ntype TypeSpec struct {\n\t// contains filtered or unexported fields\n}\n```\nTypeSpec is a constructor and usage description for each buffer type.\n\n","path":"github.com/benthosdev/benthos/lib/buffer","name":"buffer","synopsis":"Package buffer is both a types.Consumer and types.Producer implementation that is able to sit between other stream components, effectively decoupling their transaction channels by storing messages in a buffer implementation.","isRedistributable":true}
