-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproducer.go
44 lines (39 loc) · 1.1 KB
/
producer.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
package main
import (
"flag"
"github.com/ysk229/go-rabbitmq/v2"
"github.com/ysk229/go-rabbitmq/v2/channels"
"github.com/ysk229/go-rabbitmq/v2/lib"
"github.com/ysk229/go-rabbitmq/v2/msg"
"github.com/ysk229/go-rabbitmq/v2/producers"
"log"
)
var (
uri = flag.String("uri", "amqp://admin:[email protected]:5672", "AMQP URI")
exchangeName = flag.String("exchange", "test-exchange7", "Durable AMQP exchange name")
routingKey = flag.String("key", "test-key2", "AMQP routing key")
body = flag.String("body", "foobar", "Body of message")
)
func init() {
flag.Parse()
}
func main() {
mq := rabbitmq.NewClient(*uri)
p := mq.GetProducer()
p.Producer(
msg.NewMessage(
msg.WithOptionsChannel(channels.NewChannel(mq.Connection)),
msg.WithOptionsBody(*body),
),
producers.WithOptionsProducer(&producers.ProducerOpt{
Exchange: *exchangeName,
ExchangeType: lib.Topic,
RouteKey: *routingKey,
Mandatory: true,
ResendNum: 2,
}),
producers.WithOptionsProducerCallBack(&producers.CallBack{Fnc: func(ret msg.Ret) {
log.Printf("call back %+v", ret)
}}),
)
}