Last active
June 29, 2019 07:35
-
-
Save iamgoangle/cf23cc3dbdf500fab932f261e75e92c2 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 ( | |
| "log" | |
| "github.com/iamgoangle/rabbit-go/internal/rabbitmq" | |
| ) | |
| func main() { | |
| conn, err := rabbitmq.NewConnection(rabbitmq.ConfigConnection{ | |
| Type: "standalone", | |
| Url: "amqp://admin:1234@localhost:5672/", | |
| }) | |
| if err != nil { | |
| log.Fatal("[main]: unable to connect RabbitMQ %+v", err) | |
| } | |
| rbMqConfig := rabbitmq.ConfigConsumer{ | |
| Queue: rabbitmq.ConfigQueue{ | |
| Name: "hello-simple", | |
| }, | |
| } | |
| consumer, err := rabbitmq.NewConsumer(conn, rbMqConfig) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| msgs, err := consumer.WorkerProcessor() | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| forever := make(chan bool) | |
| go func() { | |
| for m := range msgs { | |
| log.Println("Received a message: %s", string(m.Body)) | |
| log.Println("Done") | |
| m.Ack(false) | |
| } | |
| }() | |
| <-forever | |
| consumer.Close() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment