Created
June 26, 2020 17:47
-
-
Save cawa87/1938b3571869ecb95f3c2d93d7ff0893 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/streadway/amqp" | |
) | |
func main() { | |
fmt.Println(".") | |
conn, err := amqp.Dial("amqps://jEET11HDo04kR0bEFe:[email protected]/%2Funifiedfeed%2F31285") | |
if err != nil { | |
fmt.Println(err) | |
panic(err) | |
} | |
chnl, err := conn.Channel() | |
if err != nil { | |
fmt.Println(err) | |
panic(err) | |
} | |
qee, err := chnl.QueueDeclare( | |
"", // name, leave empty to generate a unique name | |
false, // durable | |
true, // delete when unused | |
true, // exclusive | |
false, // noWait | |
nil, // arguments | |
) | |
if err != nil { | |
fmt.Println(err) | |
panic(err) | |
} | |
err = chnl.QueueBind( | |
qee.Name, // name of the queue | |
"#", // bindingKey | |
"unifiedfeed", // sourceExchange | |
false, // noWait | |
nil, // arguments | |
) | |
consumerTag := "" | |
msgs, err := chnl.Consume( | |
qee.Name, // queue | |
consumerTag, // consumerTag | |
true, // auto-ack | |
true, // exclusive | |
false, // no-local | |
false, // no-wait | |
nil, // args | |
) | |
if err != nil { | |
fmt.Println(err) | |
panic(err) | |
} | |
forver := make(chan bool) | |
go func(){ | |
for d := range msgs{ | |
fmt.Println(string(d.Body)) | |
} | |
}() | |
defer chnl.Close() | |
defer conn.Close() | |
<-forver | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment