neuron-explorer
Qwen3.5‑4B 전용 조향형 뉴런 탐색기, 모든 MLP 뉴런을 밀어 결과를 보관·탐색
Library for handing Kafka messages with retries
저장소 README에서 가져옴
README 전체를 불러오는 중입니다. 아래는 저장된 발췌입니다.
kp
Library for handing Kafka messages with retries
v2 (confluent-kafka-go/librdkafka, middleware chain, schema registry) lives in v2/. The docs below cover v1 (sarama).README 전문 보기 ↗Library for handing Kafka messages with retries
v2 (confluent-kafka-go/librdkafka, middleware chain, schema registry) lives in
v2/. The docs below cover v1 (sarama).
Each KP instance create a kafka sarama client which will listen to 2 topics: main topic and retry topic. The Retry topic will be prepended with the consumer group name such that each instance could have its own retry and dead letter topics. This will enable a case such that you have two services that listen to the same topic but one service might fail the topic, with this it would only retry on that service and not the other one.
Code Example: (see examples)
func main() {
cfg, err := config.LoadConfig()
if err != nil {
panic(err)
}
retryCount := 10
consumerGroup := "simple-service" // usually the name of your service
backoffDuration := time.Second * 1 // set to 0 for no backoff
processor := kp.NewKafkaProcessor("main-topic", "retry-main-topic", "dead-main-topic", retryCount, consumerGroup, kp.KafkaConfig{KafkaBootstrapServers: strings.Split(cfg.KafkaConfig.KafkaBootstrapServers, ",")}, backoffDuration)
// retry topic becomes "simple-service-retry-main-topic"
// dead letter topic becomes "simple-service-dead-main-topic"
processor.Process(func(key string, message string, retries int, rawMessage *sarama.ConsumerMessage) error {
err := processMessage(message)
if err != nil {
log.Printf("Error processing message: %s", err)
return err
}
log.Println("successfully processed message")
return nil
})
processor.Start()
}
To disable retries, just set retries to 0
This library supports exponential backoff. To use a backoff policy, set the backoffDuration to anything above 1. To disable the backoff policy, set the backoffDuration to 0. Backoff happens on the whole client which will slow down all mesaages. When a message is successful, the backoffDuration is reduced.
KP Uses 3 topics: main topic, retry topic and dead letter topic. You are able to modify the retry and dead letter topics like so:
processor := kp.NewKafkaProcessor(
cfg.Kafka.CardReplacementTopic,
"retry-"+cfg.Kafka.CardReplacementTopic,
"deadletter-"+cfg.Kafka.CardReplacementTopic,
10,
"card-delivery-service",
kp.KafkaConfig{KafkaBootstrapServers: strings.Split(cfg.Kafka.KafkaBootstrap, ",")},
time.Second*5,
)
This is useful when you have a worker that listens to multiple topics and each topic needs to have its own retry and dead letter topic.
For retry and deadletter topics they are generated with the consumer group. ex:
topic: test
retrytopic: retry
deadlettertopic: deadletter
consumergroup: group
resulting topics:
retrytopic: group-retry
deadlettertopic: group-deadletter
resulting topic format: <consumer group>-<retry|deadletter topic>