8000 declare queue and log message sent · rtoth89/rabbitmq-tutorials@8752dc3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8752dc3

Browse files
committed
declare queue and log message sent
1 parent 1f6dc30 commit 8752dc3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

go/new_task.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,20 @@ func main() {
2525
failOnError(err, "Failed to open a channel")
2626
defer ch.Close()
2727

28+
q, err := ch.QueueDeclare(
29+
"task_queue", // name
30+
true, // durable
31+
false, // delete when unused
32+
false, // exclusive
33+
false, // no-wait
34+
nil, // arguments
35+
)
36+
failOnError(err, "Failed to declare a queue")
37+
2838
body := bodyFrom(os.Args)
2939
err = ch.Publish(
3040
"", // exchange
31-
"task_queue", // routing key
41+
q.Name, // routing key
3242
false, // mandatory
3343
false,
3444
amqp.Publishing{
@@ -37,6 +47,7 @@ func main() {
3747
Body: []byte(body),
3848
})
3949
failOnError(err, "Failed to publish a message")
50+
log.Printf(" [x] Sent %s", body)
4051
}
4152

4253
func bodyFrom(args []string) string {

0 commit comments

Comments
 (0)
0