fix: prepare native cluster deployment
This commit is contained in:
@@ -34,8 +34,10 @@ type configEventPayload struct {
|
||||
Keys []string `json:"keys"`
|
||||
}
|
||||
|
||||
var kafkaConfigEventConsumerGroup string
|
||||
|
||||
func startKafkaConfigEventConsumer() {
|
||||
startKafkaConsumer("config_event", handleKafkaConfigEvent)
|
||||
kafkaConfigEventConsumerGroup = startKafkaBroadcastConsumer("config_event", handleKafkaConfigEvent)
|
||||
}
|
||||
|
||||
func handleKafkaConfigEvent(ctx context.Context, envelope kafkaEnvelope, _ kafka.Message) error {
|
||||
@@ -46,17 +48,18 @@ func handleKafkaConfigEvent(ctx context.Context, envelope kafkaEnvelope, _ kafka
|
||||
if tenantID.IsZero() {
|
||||
tenantID = types.TenantID(1)
|
||||
}
|
||||
consume, claimed, err := beginKafkaConsumeForTopic(tenantID, envelope, "config_event")
|
||||
consumerGroup := kafkaConfigEventConsumerGroup
|
||||
consume, claimed, err := beginKafkaConsumeForTopicWithGroup(tenantID, envelope, "config_event", consumerGroup)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !claimed {
|
||||
logs.Info.Printf("kafka config event skipped: event=%s group=%s status=%s", envelope.EventID, kafkaBus.config.ConsumerGroup, consume.Status)
|
||||
logs.Info.Printf("kafka config event skipped: event=%s group=%s status=%s", envelope.EventID, consumerGroup, consume.Status)
|
||||
return nil
|
||||
}
|
||||
if err = executeKafkaConfigEvent(envelope); err != nil {
|
||||
reason := kafkaCommandErrorReason(err)
|
||||
failed, markErr := store.HTTPInfrastructure.MarkKafkaConsumeFailed(tenantID, envelope.EventID, kafkaBus.config.ConsumerGroup, reason, err.Error(), time.Now().UTC().Round(time.Millisecond))
|
||||
failed, markErr := store.HTTPInfrastructure.MarkKafkaConsumeFailed(tenantID, envelope.EventID, consumerGroup, reason, err.Error(), time.Now().UTC().Round(time.Millisecond))
|
||||
if markErr != nil {
|
||||
return markErr
|
||||
}
|
||||
@@ -66,7 +69,7 @@ func handleKafkaConfigEvent(ctx context.Context, envelope kafkaEnvelope, _ kafka
|
||||
sleepKafkaRetryBackoff(failed.RetryCount)
|
||||
return err
|
||||
}
|
||||
return store.HTTPInfrastructure.MarkKafkaConsumeSucceeded(tenantID, envelope.EventID, kafkaBus.config.ConsumerGroup, time.Now().UTC().Round(time.Millisecond))
|
||||
return store.HTTPInfrastructure.MarkKafkaConsumeSucceeded(tenantID, envelope.EventID, consumerGroup, time.Now().UTC().Round(time.Millisecond))
|
||||
}
|
||||
|
||||
func executeKafkaConfigEvent(envelope kafkaEnvelope) error {
|
||||
@@ -141,10 +144,20 @@ func beginKafkaConsumeForTopic(tenantID types.TenantID, envelope kafkaEnvelope,
|
||||
if kafkaBus == nil {
|
||||
return nil, false, types.ErrUnsupported
|
||||
}
|
||||
return beginKafkaConsumeForTopicWithGroup(tenantID, envelope, topicName, kafkaBus.config.ConsumerGroup)
|
||||
}
|
||||
|
||||
func beginKafkaConsumeForTopicWithGroup(tenantID types.TenantID, envelope kafkaEnvelope, topicName, consumerGroup string) (*types.KafkaConsumeRecord, bool, error) {
|
||||
if kafkaBus == nil {
|
||||
return nil, false, types.ErrUnsupported
|
||||
}
|
||||
if consumerGroup = strings.TrimSpace(consumerGroup); consumerGroup == "" {
|
||||
consumerGroup = kafkaBus.config.ConsumerGroup
|
||||
}
|
||||
deadline := time.Now().UTC().Add(5 * time.Minute).Round(time.Millisecond)
|
||||
return store.HTTPInfrastructure.BeginKafkaConsume(tenantID, &types.KafkaConsumeRecord{
|
||||
EventID: envelope.EventID,
|
||||
ConsumerGroup: kafkaBus.config.ConsumerGroup,
|
||||
ConsumerGroup: consumerGroup,
|
||||
SourceTopic: kafkaTopic(topicName),
|
||||
EventType: envelope.EventType,
|
||||
BizType: envelope.BizType,
|
||||
|
||||
Reference in New Issue
Block a user