forked from beatlabs/patron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
async.go
35 lines (29 loc) · 934 Bytes
/
async.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
package async
import (
"context"
"github.com/mantzas/patron/encoding"
"github.com/mantzas/patron/encoding/json"
"github.com/pkg/errors"
)
// ProcessorFunc definition of a async processor.
type ProcessorFunc func(Message) error
// Message interface for defining messages that are handled by the async component.
type Message interface {
Context() context.Context
Decode(v interface{}) error
Ack() error
Nack() error
}
// Consumer interface which every specific consumer has to implement.
type Consumer interface {
Consume(context.Context) (<-chan Message, <-chan error, error)
Close() error
}
// DetermineDecoder determines the decoder based on the content type.
func DetermineDecoder(contentType string) (encoding.DecodeRawFunc, error) {
switch contentType {
case json.ContentType, json.ContentTypeCharset:
return json.DecodeRaw, nil
}
return nil, errors.Errorf("accept header %s is unsupported", contentType)
}