func TestSyslogProducer(t *testing.T) {
	topic := fmt.Sprintf("syslog-producer-%d", time.Now().Unix())

	consumeMessages := 100
	timeout := 1 * time.Minute
	consumeStatus := make(chan int)

	CreateMultiplePartitionsTopic(localZk, topic, 1)
	EnsureHasLeader(localZk, topic)

	config := syslog.NewSyslogProducerConfig()
	config.ProducerConfig = producer.NewProducerConfig()
	config.BrokerList = localBroker
	config.NumProducers = 1
	config.TCPAddr = tcpAddr
	config.Topic = topic
	syslogProducer := syslog.NewSyslogProducer(config)
	go syslogProducer.Start()

	time.Sleep(2 * time.Second)
	for i := 0; i < 100; i++ {
		logMessage()
	}

	consumerConfig := testConsumerConfig()
	consumerConfig.Strategy = newCountingStrategy(t, consumeMessages, timeout, consumeStatus)
	consumer := NewConsumer(consumerConfig)
	go consumer.StartStatic(map[string]int{topic: 1})
	if actual := <-consumeStatus; actual != consumeMessages {
		t.Errorf("Failed to consume %d messages within %s. Actual messages = %d", consumeMessages, timeout, actual)
	}
	closeWithin(t, 10*time.Second, consumer)
	syslogProducer.Stop()
}
예제 #2
0
func main() {
	config := parseAndValidateArgs()
	producer := syslog.NewSyslogProducer(config)
	go producer.Start()

	ctrlc := make(chan os.Signal, 1)
	signal.Notify(ctrlc, os.Interrupt)
	<-ctrlc
	producer.Stop()
}