-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (48 loc) · 1.33 KB
/
main.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
package main
import (
"context"
"log"
"time"
"github.com/heureka/gorabbit"
"github.com/heureka/gorabbit/publisher"
amqp "github.com/rabbitmq/amqp091-go"
)
func main() {
pub, err := gorabbit.NewPublisher(
"amqp://localhost:5672",
"example-exchange",
publisher.WithHeaders(amqp.Table{"x-example-header": "example-value"}),
publisher.WithTransientDeliveryMode(),
publisher.WithImmediate(),
publisher.WithMandatory(),
publisher.WithExpiration(time.Minute),
)
if err != nil {
log.Panic(err)
}
// publish
err = pub.Publish(context.Background(), "example-key", []byte("hello world!"))
if err != nil {
log.Panic(err)
}
// override config only for this publishing
err = pub.Publish(
context.Background(),
"example-key",
[]byte("hello again!"),
// add headers
publisher.WithHeaders(amqp.Table{"x-other-header": "only for thing publishing"}),
// set another expiration
publisher.WithExpiration(time.Hour),
// custom overriding
func(channel publisher.Channel) publisher.Channel {
return publisher.ChannelFunc(func(ctx context.Context, exchange, key string, mandatory, immediate bool, msg amqp.Publishing) error {
// set another exchange only for this publishing
return channel.PublishWithContext(ctx, "other-exchange", key, mandatory, immediate, msg)
})
},
)
if err != nil {
log.Panic(err)
}
}