Skip to content

Instantly share code, notes, and snippets.

@iamgoangle
Created June 29, 2019 10:54
Show Gist options
  • Select an option

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

Select an option

Save iamgoangle/cc087c0ecd26daafc022bbb46468dcad to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"log"
"time"
"github.com/iamgoangle/rabbit-go/internal/rabbitmq"
)
type mockData struct {
EventType string `json:"eventType"`
Data string `json:"data"`
}
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: rabbitmq.ExchangeFanout,
Name: "asia.exchange.fanout",
Durable: true,
RoutingKey: "",
},
}
producer, err := rabbitmq.NewProducer(conn, rbMqConfig)
if err != nil {
log.Fatalf("[main]: unable to initial producer RabbitMQ %+v", err)
}
for i := 0; i < 10000; i++ {
body, _ := json.Marshal(&mockData{
EventType: "asiaEvent",
Data: fmt.Sprintf("test fanout %+v", i),
})
err = producer.Publish(body)
if err != nil {
log.Printf("unable to send message %+v", err)
}
time.Sleep(1 * time.Second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment