8000 Changed emit_log.go to handle multiple command line args · blake2002/rabbitmq-tutorials@1b92c78 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1b92c78

Browse files
committed
Changed emit_log.go to handle multiple command line args
Changed receive_logs.go to declare the Exchange so that if it is run before emit_log it will not panic.
1 parent c51568a commit 1b92c78

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

go/emit_log.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"log"
66
"os"
7+
"strings"
78

89
"github.com/streadway/amqp"
910
)
@@ -51,11 +52,11 @@ func main() {
5152
}
5253

5354
func bodyFrom(args []string) string {
54-
var body string
55+
var s string
5556
if (len(args) < 2) || os.Args[1] == "" {
56-
body = "hello"
57+
s = "hello"
5758
} else {
58-
body = os.Args[1]
59+
s = strings.Join(args[1:], " ")
5960
}
60-
return body
61+
return s
6162
}

go/receive_logs.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ func main() {
2323
failOnError(err, "Failed to open a channel")
2424
defer ch.Close()
2525

26+
err = ch.ExchangeDeclare(
27+
"logs", // name
28+
"fanout", // type
29+
true, // durable
30+
false, // auto-deleted
31+
false, // internal
32+
false, // no-wait
33+
nil, // arguments
34+
)
35+
failOnError(err, "Failed to declare an exchange")
36+
2637
q, err := ch.QueueDeclare(
2738
"", // name
2839
false, // durable

0 commit comments

Comments
 (0)
0