Skip to content

Commit

Permalink
Merge pull request #542 from zendesk/avoid_regexp
Browse files Browse the repository at this point in the history
don't regex the topic unless needed
  • Loading branch information
Ben Osheroff authored Jan 21, 2017
2 parents 6ad4406 + fa1bccc commit cfe8095
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class MaxwellKafkaProducer extends AbstractAsyncProducer {
private final MaxwellKafkaPartitioner partitioner;
private final MaxwellKafkaPartitioner ddlPartitioner;
private final KeyFormat keyFormat;
private final boolean interpolateTopic;

public MaxwellKafkaProducer(MaxwellContext context, Properties kafkaProperties, String kafkaTopic) {
super(context);
Expand All @@ -71,6 +72,7 @@ public MaxwellKafkaProducer(MaxwellContext context, Properties kafkaProperties,
this.topic = "maxwell";
}

this.interpolateTopic = kafkaTopic.contains("%{");
this.kafka = new KafkaProducer<>(kafkaProperties, new StringSerializer(), new StringSerializer());

String hash = context.getConfig().kafkaPartitionHash;
Expand All @@ -97,7 +99,10 @@ private Integer getNumPartitions(String topic) {
}

private String generateTopic(String topic, RowMap r){
return topic.replaceAll("%\\{database\\}", r.getDatabase()).replaceAll("%\\{table\\}", r.getTable());
if ( interpolateTopic )
return topic.replaceAll("%\\{database\\}", r.getDatabase()).replaceAll("%\\{table\\}", r.getTable());
else
return topic;
}

@Override
Expand Down

0 comments on commit cfe8095

Please sign in to comment.