func main() { q, err := anyq.New("rabbitmq", *uri, func(q *anyq.Rabbitmq) { log.Println("declaring Exchange: ", *exchangeName) if err := q.ExchangeDeclare(*exchangeName, *exchangeType, false, false, false, false, nil); err != nil { log.Fatal(err) } log.Println("declared Exchange") }) if err != nil { panic(err) } p, err := q.NewProducer(anyq.RabbitmqProducerArgs{Exchange: *exchangeName, RoutingKey: *routingKey}) if err != nil { panic(err) } sendCh := make(chan []byte) p.BindSendChan(sendCh) sendCh <- []byte(*body) fmt.Println("[send]", *body) q.Close() }
func BenchmarkNatsProduce(b *testing.B) { log.SetOutput(ioutil.Discard) q, err := anyq.New("nats", "nats://127.0.0.1:4222") if err != nil { b.Error(err) } produceBenchmark(b, q, anyq.NatsProducerArgs{Subject: "test"}) }
func BenchmarkRabbitmqConsume(b *testing.B) { log.SetOutput(ioutil.Discard) q, err := anyq.New("rabbitmq", "amqp://*****:*****@localhost:5672/", setExchange) if err != nil { b.Error(err) } // run producer p, err := q.NewProducer(anyq.RabbitmqProducerArgs{Exchange: ex, RoutingKey: key}) if err != nil { b.Error(err) } sendCh := make(chan []byte) err = p.BindSendChan(sendCh) if err != nil { b.Error(err) } quit := make(chan struct{}, 1) go func() { i := 0 produceloop: for { select { case <-quit: break produceloop default: body := fmt.Sprintf("[%d]%s", i, "testMsg") sendCh <- []byte(body) i++ } } // b.Logf("produce count: %d", i) }() // run consumer c, err := q.NewConsumer(anyq.RabbitmqConsumerArgs{Queue: qname, RoutingKey: key, Exchange: ex}) if err != nil { b.Error(err) } recvCh := make(chan *anyq.Message) err = c.BindRecvChan(recvCh) if err != nil { b.Error(err) } b.ResetTimer() for i := 0; i < b.N; i++ { m := <-recvCh delivery := m.Origin.(amqp.Delivery) delivery.Ack(false) } quit <- struct{}{} q.Close() }
func BenchmarkRabbitmqProduce(b *testing.B) { log.SetOutput(ioutil.Discard) q, err := anyq.New("rabbitmq", "amqp://*****:*****@127.0.0.1:5672/", setExchange) if err != nil { panic(err) } produceBenchmark(b, q, anyq.RabbitmqProducerArgs{Exchange: ex, RoutingKey: key}) }
func BenchmarkKafkaAsyncProduce(b *testing.B) { log.SetOutput(ioutil.Discard) q, err := anyq.New("kafka", "localhost:9092") if err != nil { b.Error(err) } produceBenchmark(b, q, anyq.KafkaProducerArgs{Topic: "test"}) }
func BenchmarkKafkaConsume(b *testing.B) { log.SetOutput(ioutil.Discard) q, err := anyq.New("kafka", "localhost:9092") if err != nil { b.Error(err) } pubsubBenchmark(b, q, anyq.KafkaProducerArgs{Topic: "test"}, anyq.KafkaConsumerArgs{Topic: "test", Partitions: "all"}) }
func BenchmarkNsqProduce(b *testing.B) { log.SetOutput(ioutil.Discard) q, err := anyq.New("nsq", "127.0.0.1:4150") q.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags), anyq.LogLevelInfo) if err != nil { b.Error(err) } produceBenchmark(b, q, anyq.NsqProducerArgs{Topic: "test"}) }
func main() { q, err := anyq.New("rabbitmq", *uri, setExchange) if err != nil { panic(err) } c, err := q.NewConsumer(anyq.RabbitmqConsumerArgs{Queue: *queueName, RoutingKey: *bindingKey, Exchange: *exchange, ConsumerTag: *consumerTag}) if err != nil { panic(err) } recvCh := make(chan *anyq.Message) c.BindRecvChan(recvCh) for m := range recvCh { fmt.Println("[receive]", string(m.Body)) } }
func main() { flag.Parse() q, err := anyq.New("nsq", *url) if err != nil { panic(err) } c, err := q.NewConsumer(anyq.NsqConsumerArgs{Topic: *topic, Channel: *channel}) if err != nil { panic(err) } recvCh := make(chan *anyq.Message, 256) c.BindRecvChan(recvCh) for m := range recvCh { fmt.Println("[receive]", string(m.Body)) } }
func main() { flag.Parse() q, err := anyq.New("kafka", *brokerList) if err != nil { panic(err) } p, err := q.NewProducer(anyq.KafkaProducerArgs{Topic: *topic, Key: *key, Partitioner: *partitioner, Partition: int32(*partition)}) if err != nil { panic(err) } sendCh := make(chan []byte, 1) p.BindSendChan(sendCh) var bytes []byte for { fmt.Scanln(&bytes) sendCh <- bytes } }
func main() { flag.Parse() q, err := anyq.New("nats", *url) if err != nil { panic(err) } p, err := q.NewProducer(anyq.NatsProducerArgs{Subject: *subject}) if err != nil { panic(err) } sendCh := make(chan []byte, 1) p.BindSendChan(sendCh) var bytes []byte for { fmt.Scanln(&bytes) sendCh <- bytes } }
func main() { flag.Parse() q, err := anyq.New("kafka", *brokerList, func(q *anyq.Kafka) { q.Zookeepers = strings.Split(*zookeeper, ",") }) if err != nil { panic(err) } c, err := q.NewConsumer(anyq.KafkaConsumerArgs{Topic: *topic, Partitions: *partitions, Offset: *offset, Group: *group}) if err != nil { panic(err) } recvCh := make(chan *anyq.Message, 256) c.BindRecvChan(recvCh) for m := range recvCh { fmt.Println("[receive]", string(m.Body)) } }
func main() { flag.Parse() q, err := anyq.New("nsq", *url) if err != nil { panic(err) } p, err := q.NewProducer(anyq.NsqProducerArgs{Topic: *topic}) if err != nil { panic(err) } sendCh := make(chan []byte, 1) p.BindSendChan(sendCh) var bytes []byte for { fmt.Scanln(&bytes) sendCh <- bytes } }
func BenchmarkNatsReply(b *testing.B) { log.SetOutput(ioutil.Discard) q, err := anyq.New("nats", "nats://127.0.0.1:4222") if err != nil { panic(err) } conn, err := q.Conn() if err != nil { b.Error(err) } natsConn, ok := conn.(*nats.Conn) if !ok { log.Fatalf("invalid conn type(%T)\n", conn) } // set consumer for reply natsConn.Subscribe("test", func(m *nats.Msg) { natsConn.Publish(m.Reply, m.Data) log.Println("[receive and reply]", string(m.Data)) }) // set producer for request b.ResetTimer() for i := 0; i < b.N; i++ { body := strconv.Itoa(i) m, err := natsConn.Request("test", []byte(body), 10*time.Second) if err != nil { log.Fatalln(err) return } log.Println("[replied]", string(m.Data)) } }