forked from benthosdev/benthos
/
noop.go
59 lines (45 loc) · 1.67 KB
/
noop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package processor
import (
"time"
"github.com/dafanshu/benthos/v3/internal/docs"
"github.com/dafanshu/benthos/v3/lib/log"
"github.com/dafanshu/benthos/v3/lib/metrics"
"github.com/dafanshu/benthos/v3/lib/types"
)
//------------------------------------------------------------------------------
func init() {
Constructors[TypeNoop] = TypeSpec{
constructor: NewNoop,
Summary: "Noop is a processor that does nothing, the message passes through unchanged. Why? Sometimes doing nothing is the braver option.",
config: docs.FieldComponent().HasType(docs.FieldTypeObject),
}
}
//------------------------------------------------------------------------------
// NoopConfig configures the no-op processor.
type NoopConfig struct{}
// NewNoopConfig creates a new default no-op processor config.
func NewNoopConfig() NoopConfig {
return NoopConfig{}
}
// Noop is a no-op processor that does nothing.
type Noop struct{}
// NewNoop returns a Noop processor.
func NewNoop(
conf Config, mgr types.Manager, log log.Modular, stats metrics.Type,
) (Type, error) {
return &Noop{}, nil
}
//------------------------------------------------------------------------------
// ProcessMessage does nothing and returns the message unchanged.
func (c *Noop) ProcessMessage(msg types.Message) ([]types.Message, types.Response) {
msgs := [1]types.Message{msg}
return msgs[:], nil
}
// CloseAsync shuts down the processor and stops processing requests.
func (c *Noop) CloseAsync() {
}
// WaitForClose blocks until the processor has closed down.
func (c *Noop) WaitForClose(timeout time.Duration) error {
return nil
}
//------------------------------------------------------------------------------