Skip to content

Instantly share code, notes, and snippets.

@iamgoangle
Last active June 29, 2019 07:15
Show Gist options
  • Select an option

  • Save iamgoangle/7c0802d971daed494976310c8b096216 to your computer and use it in GitHub Desktop.

Select an option

Save iamgoangle/7c0802d971daed494976310c8b096216 to your computer and use it in GitHub Desktop.
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.Fatalf("[main]: unable to connect RabbitMQ %+v", err)
}
rbMqConfig := rabbitmq.ConfigProducer{
Exchange: rabbitmq.ConfigExchange{
Type: "",
},
Queue: rabbitmq.ConfigQueue{
Name: "hello-simple",
},
}
producer, err := rabbitmq.NewProducer(conn, rbMqConfig)
if err != nil {
log.Fatalf("[main]: unable to connect RabbitMQ %+v", err)
}
for i := 0; i < 10; i++ {
body := []byte(`{"eventType":"sendMessage","data":"Hello World","Time":1294706395881547000}`)
err = producer.Publish(body)
if err != nil {
log.Printf("unable to send my message %+v", err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment