11package main
22
33import (
4+ "crypto/tls"
45 "encoding/json"
56 "flag"
67 "fmt"
78 "io/ioutil"
89 "os"
910 "path"
11+ "strings"
1012
1113 "github.com/streadway/amqp"
1214)
1315
1416var (
15- uri = flag .String ("uri" , "amqp://guest:guest@localhost:5672/" , "AMQP URI" )
16- queue = flag .String ("queue" , "" , "AMQP queue name" )
17- maxMessages = flag .Uint ("max-messages" , 1000 , "Maximum number of messages to dump" )
18- outputDir = flag .String ("output-dir" , "." , "Directory in which to save the dumped messages" )
19- full = flag .Bool ("full" , false , "Dump the message, its properties and headers" )
20- verbose = flag .Bool ("verbose" , false , "Print progress" )
17+ uri = flag .String ("uri" , "amqp://guest:guest@localhost:5672/" , "AMQP URI" )
18+ insecure_tls = flag .Bool ("insecure-tls" , false , "Insecure TLS mode: don't check certificates" )
19+ queue = flag .String ("queue" , "" , "AMQP queue name" )
20+ maxMessages = flag .Uint ("max-messages" , 1000 , "Maximum number of messages to dump" )
21+ outputDir = flag .String ("output-dir" , "." , "Directory in which to save the dumped messages" )
22+ full = flag .Bool ("full" , false , "Dump the message, its properties and headers" )
23+ verbose = flag .Bool ("verbose" , false , "Print progress" )
2124)
2225
2326func main () {
@@ -29,13 +32,24 @@ func main() {
2932 }
3033}
3134
35+ func dial (amqpURI string ) (* amqp.Connection , error ) {
36+ VerboseLog (fmt .Sprintf ("Dialing %q" , amqpURI ))
37+ if * insecure_tls && strings .HasPrefix (amqpURI , "amqps://" ) {
38+ tlsConfig := new (tls.Config )
39+ tlsConfig .InsecureSkipVerify = true
40+ conn , err := amqp .DialTLS (amqpURI , tlsConfig )
41+ return conn , err
42+ }
43+ conn , err := amqp .Dial (amqpURI )
44+ return conn , err
45+ }
46+
3247func DumpMessagesFromQueue (amqpURI string , queueName string , maxMessages uint , outputDir string ) error {
3348 if queueName == "" {
3449 return fmt .Errorf ("Must supply queue name" )
3550 }
3651
37- VerboseLog (fmt .Sprintf ("Dialing %q" , amqpURI ))
38- conn , err := amqp .Dial (amqpURI )
52+ conn , err := dial (amqpURI )
3953 if err != nil {
4054 return fmt .Errorf ("Dial: %s" , err )
4155 }
0 commit comments