#Ticker with multiple blocking operations

2 messages · Page 1 of 1 (latest)

storm apex
#

Hi guys, would like to ask for some help.

I am consuming data from a kafka queue using a ticker, this consumption is a block operation so it keeps listening to this queue until a message arrives.

I have the following code

loggerOutput := zerolog.ConsoleWriter{Out: os.Stdout}
    loggerOutput.TimeFormat = time.RFC3339Nano
    logger := zerolog.New(loggerOutput).With().Timestamp().Logger()

    ticker := time.NewTicker(500 * time.Millisecond)
    done := make(chan bool)
    go func() {
        for {
            select {
            case <-ticker.C:
                start := time.Now()
                api.VerifyCustomerExists()
                elapsed := time.Since(start)
                logger.Info().Msgf("Time taken for this iteration: %s", elapsed)
            case <-done:
                logger.Info().Msg("stopping ticker")
                ticker.Stop()
                return
            }
        }
    }()

But now I need to listen asynchronously for more 3 queues, can I keep this ticker? considering that the listening process is a blocking operation? or should I just create 1 go routine per queue to keep listening there?
Thank you

tiny folio
#

maybe better make sep G for every queue?