-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdocs.go
More file actions
76 lines (56 loc) · 2.74 KB
/
Copy pathdocs.go
File metadata and controls
76 lines (56 loc) · 2.74 KB
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
// Package harego contains the logic for communicating with RabbitMQ.
/*
# Publisher
A Publisher wraps an exchange in a concurrent safe manner for publishing
messages to RabbitMQ. Zero value is not usable therefore a Publisher should be
constructed with NewPublisher() function.
The only requirement for a Publisher to operate is a connector that returns a
connection to the broker. There is also a helper function that can create a new
connection from the address of the broker. The Publisher will create 1 worker
by default for publishing messages. The default exchange of the Publisher is
"default" and it is set with the "topic" type. The default delivery method is
persistent. You can use provided ConfigFunc functions to change the Publisher's
behaviour.
You should call the Close() method when you are done with this object,
otherwise it will leak goroutines.
# NewPublisher
NewPublisher returns a Publisher instance. You can configure the object by
providing ConfigFunc functions. See ConfigFunc documentation for more
information.
pub, err := harego.NewPublisher(harego.URLConnector("amqp://"),
harego.Workers(6),
)
// handle error
# Publish
If the publisher is setup with multiple workers, each Publish call will go
through the next available worker.
# Consumer
A Consumer wraps a queue in a concurrent safe manner for receiving messages
from RabbitMQ. If the Consumer doesn't have a queue name set, it will not
create a queue. Zero value is not usable, therefore a Consumer should be
constructed with NewConsumer() function.
The only requirement for a Consumer to operate is a connector that returns a
connection to the broker. There is also a helper function that can create a new
connection from the address of the broker. The Consumer will create 1 worker by
default for consuming messages. The default delivery method is persistent. You
can use provided ConfigFunc functions to change the Consumer's behaviour.
Make sure to provide a queue name. The Consumer binds the queue to the given
exchange.
You should call the Close() method when you are done with this object,
otherwise it will leak goroutines.
# NewConsumer
NewConsumer returns an Consumer instance. You can configure the object by
providing ConfigFunc functions. See ConfigFunc documentation for more
information.
cons, err := harego.NewConsumer(harego.URLConnector("amqp://"),
harego.Workers(6),
)
// handle error
# Consume
Consume calls the handler with the next available message from the next
available worker. It stops handling messages when the context is done or the
consumer is closed. Consume internally creates a Publisher for requeueing
messages. By default messages are consumed with false autoAck.
Make sure you have enough workers so the Consume is not clogged on delays.
*/
package harego