-
Notifications
You must be signed in to change notification settings - Fork 1
/
driver.go
47 lines (38 loc) · 971 Bytes
/
driver.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
package kasync
import (
"context"
"io"
)
type MsgHdr = string
type MsgType = string
type CtxKey string
const (
MsgHdrMsgType MsgHdr = "X-MsgType"
MsgHdrMsgName MsgHdr = "X-MsgName"
MsgHdrCntType MsgHdr = "X-CntType"
MsgHdrValUnk MsgHdr = "UNK"
)
const (
CtxKeyMsgID CtxKey = "k-msgid"
CtxKeyMsgName CtxKey = "k-msgname"
)
const (
MsgTypeEvent MsgType = "EVENT"
MsgTypeErrEvent MsgType = "ERR_EVENT"
MsgTypeUnk MsgType = "UNK"
)
type Router interface {
io.Closer
Listen() error
NewRouteGrp(topic string, defHandler MsgHandler) RouteGroup
RouteGroup(topic string) (RouteGroup, error)
RqTopics() []string
}
type RouteGroup interface {
SetMsgNameResolver(r ResolveMsgName)
HandleMsg(msgName string, handler MsgHandler)
MsgHandler(msgName string) (MsgHandler, error)
ResolveMsgName(msg interface{}) (string, error)
}
type MsgHandler func(ctx context.Context, data []byte) error
type ResolveMsgName func(msg interface{}) (string, error)