Exemplo n.º 1
0
func pubsubSource(output chan<- *api.Message) {
	log.Debugln("warmupSource started")
	i := 0
	stop1 := false
	stop2 := false

	go func() {
		for !stop1 || !stop2 {
			msg := fmt.Sprintf("msg: %d", i)
			log.Debugf("Sending pubsub message: %s", msg)
			output <- api.NewTextMessage([]byte(msg))
			i++
			time.Sleep(1 * time.Second)
		}
	}()

	select {
	case msg := <-pubsubStopSendingChan:
		log.Debugf("pubsubStopSendingChan #1: %t", msg)
		stop1 = true
	}
	select {
	case msg := <-pubsubStopSendingChan:
		log.Debugf("pubsubStopSendingChan #2: %t", msg)
		stop2 = true
	}

	// now we have both consumers online, send 100 messages
	countingSource(output)
}
Exemplo n.º 2
0
func countingSource(output chan<- *api.Message) {
	log.Debugln("countingSource started")

	for i := 0; i < maxMessages; i++ {
		log.Debugf("Sending message: %d", i)
		output <- api.NewTextMessage([]byte(fmt.Sprintf("message: %d", i)))
	}
	senderChan <- "countingSource"
}
func timeSource(output chan<- *api.Message) {
	log.Println("timesource started")

	// TODO add timeformat support
	// TODO support initialDelay - delay before the first message (default: 1)
	// TODO support timeUnit - the time unit for the fixed and initial delays (default: "seconds")

	t := time.Tick(time.Duration(*period) * time.Second)
	for now := range t {
		output <- api.NewTextMessage([]byte(fmt.Sprint(now)))
	}

}
func httpclient(input <-chan *api.Message, output chan<- *api.Message) {
	log.Infoln("httpclient processor started")
	log.Debugf("--url: %s", *url)
	log.Debugf("--httpMethod: %s", *httpMethod)
	log.Debugf("--body: %s", *body)
	log.Debugf("--headers: %s", *headers)

	trimmedUrl := strings.Trim(*url, "'\"") // strip because we have seen weird things on some shells

	for {
		msg := <-input
		if msg.Content != nil {

			req, err := http.NewRequest(*httpMethod, trimmedUrl, nil)
			if err != nil {
				log.Errorf("Error while creating request %s %s", *httpMethod, trimmedUrl)
				output <- api.NewTextMessage([]byte(err.Error()))
			}

			// TODO support JSON path on body to dynamically create request

			// TODO support headers
			if len(*headers) > 0 {
				log.Warnf("Header no supported yet: %s", *headers)
			}

			resp, err := client.Do(req)
			if err != nil {
				log.Errorf("Error while invoking HTTP %s on %s", *httpMethod, trimmedUrl)
				// TODO send JSON error message downstream
				output <- api.NewTextMessage([]byte(err.Error()))
			} else {
				body, _ := ioutil.ReadAll(resp.Body)
				output <- api.NewTextMessage(body)
			}
		}
	}
}
Exemplo n.º 5
0
func countingSource(output chan<- *api.Message) {
	log.Debugln("countingSource started")

	for i := 0; i < maxMessages; i++ {
		entry := &logEntry{
			ID:           i,
			Host:         fmt.Sprintf("myhostname-%d", i%10),
			ResponseTime: rand.Float64(),
		}
		json, _ := json.Marshal(entry)

		log.Debugf("[countingSource] Sending message: %s", json)

		// TODO add a JSON message
		output <- api.NewTextMessage([]byte(json))
	}
	senderChan <- "countingSource"
}
Exemplo n.º 6
0
func handleMessage(consumerId string, channel chan *api.Message) func(*kafkaClient.Worker, *kafkaClient.Message, kafkaClient.TaskId) kafkaClient.WorkerResult {
	return func(_ *kafkaClient.Worker, msg *kafkaClient.Message, id kafkaClient.TaskId) kafkaClient.WorkerResult {
		channel <- api.NewTextMessage(msg.Value)
		return kafkaClient.NewSuccessfulResult(id)
	}
}