Skip to content

Commit

Permalink
Fix SSL auth for Azure EventHub's Kafka Broker feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
barnstee committed May 4, 2022
1 parent b52ee4d commit b6fc9e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
19 changes: 14 additions & 5 deletions KafkaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ public void Connect()
_consumer = null;
}

// read password
string password = Settings.Instance.BrokerPassword;

// create Kafka client
var config = new ProducerConfig { BootstrapServers = Settings.Instance.BrokerUrl + ":" + Settings.Instance.BrokerPort };
var config = new ProducerConfig {
BootstrapServers = Settings.Instance.BrokerUrl + ":" + Settings.Instance.BrokerPort,
RequestTimeoutMs = 60000,
MessageTimeoutMs = 30000,
SecurityProtocol = SecurityProtocol.SaslSsl,
SaslMechanism = SaslMechanism.Plain,
SaslUsername = Settings.Instance.BrokerUsername,
SaslPassword = Settings.Instance.BrokerPassword
};

// If serializers are not specified, default serializers from
// `Confluent.Kafka.Serializers` will be automatically used where
Expand All @@ -65,7 +70,11 @@ public void Connect()
// topic/partitions of interest. By default, offsets are committed
// automatically, so in this example, consumption will only start from the
// earliest message in the topic 'my-topic' the first time you run the program.
AutoOffsetReset = AutoOffsetReset.Earliest
AutoOffsetReset = AutoOffsetReset.Earliest,
SecurityProtocol= SecurityProtocol.SaslSsl,
SaslMechanism = SaslMechanism.Plain,
SaslUsername = Settings.Instance.BrokerUsername,
SaslPassword= Settings.Instance.BrokerPassword
};

_consumer = new ConsumerBuilder<Ignore, string>(conf).Build();
Expand Down
9 changes: 7 additions & 2 deletions Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"ASPNETCORE_ENVIRONMENT": "Development",
"USE_KAFKA": "1"
}
},
"UACloudPublisher": {
Expand All @@ -28,7 +29,11 @@
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"publishAllPorts": true,
"useSSL": true
"useSSL": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"USE_KAFKA": "1"
}
}
}
}

0 comments on commit b6fc9e7

Please sign in to comment.