-
Notifications
You must be signed in to change notification settings - Fork 2
/
mq_context.go
41 lines (33 loc) · 946 Bytes
/
mq_context.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
package core
import (
"fmt"
"github.com/pskclub/mine-core/consts"
"github.com/streadway/amqp"
)
type IMQContext interface {
IContext
AddConsumer(handlerFunc func(ctx IMQContext))
Consume(name string, onConsume func(message amqp.Delivery), options *MQConsumeOptions)
Start()
}
type MQContext struct {
IContext
}
func (c *MQContext) Start() {
fmt.Println(fmt.Sprintf("MQ Consumer Service: %s", c.ENV().Config().Service))
select {}
}
func (c *MQContext) AddConsumer(handlerFunc func(ctx IMQContext)) {
handlerFunc(c)
}
func (c *MQContext) Consume(name string, onConsume func(message amqp.Delivery), options *MQConsumeOptions) {
go c.MQ().Consume(c, name, onConsume, options)
}
type MQContextOptions struct {
ContextOptions *ContextOptions
}
func NewMQContext(options *MQContextOptions) IMQContext {
ctxOptions := options.ContextOptions
ctxOptions.contextType = consts.MQ
return &MQContext{IContext: NewContext(ctxOptions)}
}