Created
June 29, 2019 10:54
-
-
Save iamgoangle/cc087c0ecd26daafc022bbb46468dcad 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 ( | |
| "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