Exemplo n.º 1
0
func main() {
	config := siesta.NewConnectorConfig()
	config.BrokerList = []string{"localhost:9092"}

	connector, err := siesta.NewDefaultConnector(config)
	if err != nil {
		panic(err)
	}

	producerConfig := &siesta.ProducerConfig{
		BatchSize:       10000,
		ClientID:        "siesta",
		MaxRequests:     10,
		SendRoutines:    10,
		ReceiveRoutines: 10,
		ReadTimeout:     5 * time.Second,
		WriteTimeout:    5 * time.Second,
		RequiredAcks:    1,
		AckTimeoutMs:    2000,
		Linger:          1 * time.Second,
	}
	producer := siesta.NewKafkaProducer(producerConfig, siesta.ByteSerializer, siesta.StringSerializer, connector)

	metadataChannel := make(chan interface{}, 10000)
	count := 0
	start := time.Now()

	for i := 0; i < 10; i++ {
		go func() {
			for {
				<-metadataChannel
				count++

				elapsed := time.Since(start)
				if elapsed.Seconds() >= 1 {
					fmt.Println(fmt.Sprintf("Per Second %d", count))
					count = 0
					start = time.Now()
				}
			}
		}()
	}

	for {
		producer.Send(&siesta.ProducerRecord{Topic: "pr1", Value: "hello world"})
		metadataChannel <- nil
	}
}
Exemplo n.º 2
0
func (e *Executor) newProducer(valueSerializer func(interface{}) ([]byte, error)) (*siesta.KafkaProducer, error) {
	producerConfig, err := siesta.ProducerConfigFromFile(Config.ProducerProperties)
	if err != nil {
		return nil, err
	}

	c, err := cfg.LoadNewMap(Config.ProducerProperties)
	if err != nil {
		return nil, err
	}

	connectorConfig := siesta.NewConnectorConfig()
	connectorConfig.BrokerList = strings.Split(c["bootstrap.servers"], ",")

	connector, err := siesta.NewDefaultConnector(connectorConfig)
	if err != nil {
		return nil, err
	}

	return siesta.NewKafkaProducer(producerConfig, siesta.ByteSerializer, valueSerializer, connector), nil
}