-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstructues.go
112 lines (97 loc) · 3.52 KB
/
structues.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package queuelib
import (
"time"
kafka "github.com/segmentio/kafka-go"
"github.com/streadway/amqp"
)
//Queue : This interface is used as return type of Init()
type Queue interface {
Connect(*Config) (bool, error)
Publish(PublishStruct) (bool, error)
Subscribe(SubscribeStruct) (<-chan Delivery, error)
Get(GetStruct) (Delivery, bool, error)
Acknowledge(Delivery) (bool, error)
}
//RabbitMQ : Pointer to this struct is retured in Init() if input QueueType is "rabbitmq"
type RabbitMQ struct {
Connection *amqp.Connection
Channel *amqp.Channel
}
//RabbitMQ : Pointer to this struct is retured in Init() if input QueueType is "rabbitmq"
type Kafka struct {
Connection *kafka.Conn
}
//Config : This struct is used to define all neccessary parameters required by Supported Queue Client i.e. RabbitMQ (As of now)
type Config struct {
ConString string
Scheme string
Host string
Port int
Username string
Password string
Vhost string
KafkaTopic string
KafkaPartition int
}
//PublishStruct : This struct is an input parameter for Publish()
type PublishStruct struct {
Exchange string
Key string
Mandatory bool
Immediate bool
Message []byte
ContentType string
DeliveryTag uint64
Delay uint64 //Delay in milliseconds
KafkaTimeoutInSeconds time.Duration
}
//SubscribeStruct : This struct is an input parameter for Subscribe()
type SubscribeStruct struct {
Queue string
Consumer string
AutoAck bool
Exclusive bool
NoLocal bool
NoWait bool
PrefetchCount int //Allows batching of messages
PrefetchSize int
ApplyPrefetchGlobally bool //apply prefetch settings to all channels - across all consumers
KafkaTopic string
KafkaConsumerGroupID string
KafkaBrokers []string
}
//GetStruct : This struct is an input parameter for Get()
type GetStruct struct {
Queue string
AutoAck bool
}
// Delivery captures the fields for a previously delivered message resident in
// a queue to be delivered by the server to a consumer from Channel.Consume or
// Channel.Get.
type Delivery struct {
// Properties
ContentType string // MIME content type
ContentEncoding string // MIME content encoding
DeliveryMode uint8 // queue implementation use - non-persistent (1) or persistent (2)
Priority uint8 // queue implementation use - 0 to 9
CorrelationID string // application use - correlation identifier
ReplyTo string // application use - address to reply to (ex: RPC)
Expiration string // implementation use - message expiration spec
MessageID string // application use - message identifier
Timestamp time.Time // application use - message timestamp
Type string // application use - message type name
UserID string // application use - creating user - should be authenticated user
AppID string // application use - creating application id
// Valid only with Channel.Consume
ConsumerTag string
// Valid only with Channel.Get
MessageCount uint32
DeliveryTag uint64
Redelivered bool
Exchange string // basic.publish exhange
RoutingKey string // basic.publish routing key
Body []byte
KafkaTopic string
KafkaPartition int
KafkaKey []byte
}