10000 Merge pull request #46 from mandolyte/master · rtoth89/rabbitmq-tutorials@9f52048 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9f52048

Browse files
Merge pull request rabbitmq#46 from mandolyte/master
Imports corrected
2 parents fc83432 + dc5357c commit 9f52048

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

go/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ Code examples are executed via `go run`:
3737

3838
[Tutorial five: Topics](http://www.rabbitmq.com/tutorial-five-python.html)
3939

40-
go run receive_logs_topic.go info warn
41-
go run emit_log_topic.go warn "a warning"
40+
go run receive_logs_topic.go "kern.*" "*.critical"
41+
go run emit_log_topic.go kern.critical "A critical kernel error"
4242

4343
[Tutorial six: RPC](http://www.rabbitmq.com/tutorial-six-python.html)
4444

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

go/receive_logs_direct.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ func main() {
4545
)
4646
failOnError(err, "Failed to declare a queue")
4747

48-
for _, s := range os.Args {
48+
if len(os.Args) < 2 {
49+
log.Printf("Usage: %s [info] [warning] [error]", os.Args[0])
50+
os.Exit(0)
51+
}
52+
for _, s := range os.Args[1:] {
4953
log.Printf("Binding queue %s to exchange %s with routing key %s", q.Name, "logs_direct", s)
5054
err = ch.QueueBind(
5155
q.Name, // queue name

go/receive_logs_topic.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ func main() {
4545
)
4646
failOnError(err, "Failed to declare a queue")
4747

48-
for _, s := range os.Args {
48+
if len(os.Args) < 2 {
49+
log.Printf("Usage: %s [binding_key]...", os.Args[0])
50+
os.Exit(0)
51+
}
52+
for _, s := range os.Args[1:] {
4953
log.Printf("Binding queue %s to exchange %s with routing key %s", q.Name, "logs_topic", s)
5054
err = ch.QueueBind(
5155
q.Name, // queue name

go/worker.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package main
22

33
import (
4+
"bytes"
45
"fmt"
5-
"log"
6-
76
"github.com/streadway/amqp"
7+
"log"
8+
"time"
89
)
910

1011
func failOnError(err error, msg string) {

0 commit comments

Comments
 (0)
0