-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathbroker.go
65 lines (48 loc) · 1.56 KB
/
broker.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
60
61
62
63
64
65
package bokchoy
import (
"context"
"time"
"github.com/thoas/bokchoy/logging"
)
// Broker is the common interface to define a Broker.
type Broker interface {
// Initialize initializes the broker.
Initialize(context.Context) error
// Ping pings the broker to ensure it's well connected.
Ping(context.Context) error
// Get returns raw data stored in broker.
Get(context.Context, string) (map[string]interface{}, error)
// Delete deletes raw data in broker based on key.
Delete(context.Context, string, string) error
// List returns raw data stored in broker.
List(context.Context, string) ([]map[string]interface{}, error)
// Empty empties a queue.
Empty(context.Context, string) error
// Flush flushes the entire broker.
Flush(context.Context) error
// Count returns number of items from a queue name.
Count(context.Context, string) (BrokerStats, error)
// Save synchronizes the stored item.
Set(context.Context, string, map[string]interface{}, time.Duration) error
// Publish publishes raw data.
Publish(context.Context, string, string, map[string]interface{}, time.Time) error
// Consume returns an array of raw data.
Consume(context.Context, string, time.Time) ([]map[string]interface{}, error)
}
// BrokerStats is the statistics returned by a Queue.
type BrokerStats struct {
Total int
Direct int
Delayed int
}
// newBroker initializes a new Broker instance.
func newBroker(cfg BrokerConfig, logger logging.Logger) Broker {
var (
broker Broker
)
switch cfg.Type {
default:
broker = newRedisBroker(cfg.Redis, logger)
}
return broker
}