Managed Kafka services¶
On a managed service, prepare what it needs as well as the steps in Prepare Kafka.
Azure Event Hubs¶
Event Hubs offers a Kafka endpoint in its Standard, Premium and Dedicated tiers (not Basic). An event hub is a Kafka topic.
- In the Event Hubs namespace, create an event hub named like the topic (the group name with underscores for spaces, or the Event hub you enter), with the partitions you want (see Topics).
- Create a shared access policy with the Send claim, on the namespace or the event hub, and copy its connection
string (
Endpoint=sb://...;SharedAccessKeyName=...;SharedAccessKey=...). - Note the namespace host name,
<namespace>.servicebus.windows.net. The Kafka endpoint is on port 9093.
Event Hubs compresses only with gzip or not at all, so the Event Hubs template has no Compression.
To keep the messages in Azure Storage or Azure Data Lake Storage as well, turn on Capture on the event hub (see Microsoft: Capture events through Azure Event Hubs).
Confluent Cloud and other API keys¶
- Create a service account for SQDR and a cluster API key for it.
- Allow the service account to write to the topic: ACLs
WRITEandDESCRIBEon the topic, or a role binding such as DeveloperWrite on clusters with role-based access. - Note the cluster's bootstrap server.
Confluent with Schema Registry (Avro)¶
For consumers that read Avro through a schema registry, such as Confluent's sink connectors (to BigQuery, Snowflake,
SQL Server, MySQL, PostgreSQL and others), use the Apply extension KafkaConfluentAvroProcessor. Unlike the JSON
format, it:
- writes one topic per table, which it creates through the Confluent REST API (with
topic.partitions_countpartitions, 1 by default, andtopic.replication_factorreplicas, 3 by default); - registers each table's Avro schema in Schema Registry, under the subject
<topic>-value, and sends one Avro record per row change with the fieldsgroup,txid,seq,operationanddest(as in JSON) and one field per destination column.
The topic name comes from the topic parameter, a pattern in which {1} is the destination schema and {2} the
table, for example stelo.{1}.{2}. Without topic, it's <schema>.<table>.
Prepare Confluent Cloud:
- Create an environment and a cluster, and note their IDs (the environment ID starts with
env-, the cluster ID withlkc-). - Create a Cloud API key (in Confluent Cloud's API keys settings) and a cluster API key for SQDR. The cluster key must be allowed to create topics and write to them (for example a key with global access, or a service account with the matching ACLs or role bindings).
- Enable Schema Registry for the environment, note its ID (it starts with
lsrc-), and create a Schema Registry API key.
Create the destination as in Create the destination, from any template, and replace the parameters (in Raw) with these:
className=com.starquest.sqdr.apply.kafka.KafkaConfluentAvroProcessor
confluent.cloud.api.key=<Cloud API key>
confluent.cloud.api.secret=$$CONFLUENT_CLOUD_SECRET$$
confluent.environment.id=env-xxxxxx
confluent.kafka.cluster.id=lkc-xxxxxx
confluent.kafka.cluster.api.key=<cluster API key>
confluent.kafka.cluster.api.secret=$$CONFLUENT_CLUSTER_SECRET$$
confluent.schema.registry.cluster.id=lsrc-xxxxxx
confluent.schema.registry.cluster.api.key=<Schema Registry API key>
confluent.schema.registry.cluster.api.secret=$$CONFLUENT_SR_SECRET$$
topic=stelo.{1}.{2}
With the Cloud API key, the extension looks up the cluster's bootstrap server and REST endpoint and the Schema
Registry URL; to set them yourself, add bootstrap.servers and schema.registry.url. The $$name$$ values are
secrets.
Confluent Platform (your own cluster): give the endpoints instead of the Cloud keys:
className=com.starquest.sqdr.apply.kafka.KafkaConfluentAvroProcessor
confluent.platform.enable=true
confluent.kafka.cluster.rest.endpoint=http://confluent-host:8082
confluent.kafka.cluster.id=<cluster ID>
bootstrap.servers=confluent-host:9092
schema.registry.url=http://confluent-host:8081
topic=stelo.{1}.{2}
topic.replication_factor=1
Add the Kafka producer's security settings if your cluster needs them.
Then create the incremental group and its members as usual. After the first baseline, the topics and their schemas appear in Confluent; create the sink connectors from them. Sample parameter files: Confluent Cloud and Confluent Platform. Messages about missing or wrong values name the parameters to check (see Troubleshooting).
Oracle Cloud Infrastructure Streaming¶
The OCI Streaming service has a Kafka-compatible endpoint: a stream is a Kafka topic, in a stream pool. Use the template Kafka with SASL PLAIN over TLS - API key and secret.
- Check the tenancy's service limits for Streaming: at least one connect harness, and enough partitions for the streams you plan.
- In a stream pool, create the stream named like the topic, or turn on Auto create topics in the pool's settings.
-
Create a user for SQDR, generate an auth token for it (copy it: it can't be shown again), put it in a group, and give the group a policy such as:
allow group StreamingUsers to manage streams in tenancy allow group StreamingUsers to manage stream-push in tenancy -
Open the pool's Kafka Connection Settings: they give the bootstrap server and the user name to use,
<tenancy>/<user>/<stream pool OCID>. - In the template, enter the bootstrap server, that user name as API key, the auth token as API secret, and the topic.
Amazon MSK¶
SQDR connects to MSK with SASL/SCRAM or IAM access control. There's no MSK template: start from the template for a broker without authentication, switch View to Raw, and enter the parameters below.
SASL/SCRAM. In MSK, create the user name and password as a secret in AWS Secrets Manager and associate it with the cluster. Use the cluster's SASL/SCRAM bootstrap brokers (port 9096). MSK lets every principal use a resource that has no ACLs; if you set ACLs on the topic, add the ones in Permissions.
className=com.starquest.sqdr.apply.kafka.KafkaSparkProcessor
bootstrap.servers=<the SASL/SCRAM bootstrap brokers from the MSK console>
topic=SALES_GROUP
security.protocol=SASL_SSL
sasl.mechanism=SCRAM-SHA-512
sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="<user>" password="<password>";
To keep the password out of the parameters, store the whole sasl.jaas.config value as a
secret and write sasl.jaas.config=$$MSK_JAAS$$: in Apply extension parameters, a
secret must be the whole value.
Network access. The bootstrap brokers are on the cluster's View client information page. The Stelo VM must reach them: from inside the cluster's VPC, allow it in the cluster's security group (an inbound rule for the broker ports from the Stelo VM's security group); from another VPC, through VPC peering; from outside AWS, through a VPN, AWS Direct Connect or a transit gateway, or through MSK's public access, which needs TLS and an access control method (SASL/SCRAM or IAM).
IAM. Use the cluster's IAM bootstrap brokers (port 9098). Kafka ACLs don't apply to IAM identities; the IAM policy decides.
className=com.starquest.sqdr.apply.kafka.KafkaSparkProcessor
bootstrap.servers=<the IAM bootstrap brokers from the MSK console>
topic=SALES_GROUP
security.protocol=SASL_SSL
sasl.mechanism=AWS_MSK_IAM
sasl.jaas.config=software.amazon.msk.auth.iam.IAMLoginModule required;
sasl.client.callback.handler.class=software.amazon.msk.auth.iam.IAMClientCallbackHandler
- Create an IAM user for SQDR and an access key for it. SQDR authenticates as an IAM user with an access key; it can't assume an IAM role.
-
Give the user a policy with the actions a producer needs. Replace the region, account, cluster name and UUID, and topic:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "kafka-cluster:Connect", "kafka-cluster:DescribeCluster", "kafka-cluster:WriteDataIdempotently" ], "Resource": "arn:aws:kafka:us-east-1:111122223333:cluster/mycluster/<cluster-uuid>" }, { "Effect": "Allow", "Action": [ "kafka-cluster:DescribeTopic", "kafka-cluster:WriteData" ], "Resource": "arn:aws:kafka:us-east-1:111122223333:topic/mycluster/<cluster-uuid>/SALES_GROUP" } ] }Verify uses
DescribeCluster;WriteDataIdempotentlyis needed because the producer is idempotent by default. -
Give the key to Stelo Capture as the environment variables
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYon the Stelo VM, then restart the Stelo Capture services. Without them the connection fails with "Unable to load credentials" errors that name these variables.
Stream from MSK to Amazon S3 with AWS Glue¶
To land the messages in Amazon S3 (or Amazon Redshift), an AWS Glue streaming job can read the topic. In outline (see AWS: Streaming ETL jobs in AWS Glue):
- Allow the Glue job to reach the cluster: a security group with a self-referencing inbound rule for all TCP ports, and an Amazon S3 VPC endpoint (gateway) in the cluster's VPC.
- Create an IAM role for Glue (a name starting with
AWSGlueServiceRole), with theAWSGlueServiceRolepolicy and access to the S3 bucket. - Create a Glue connection of type Kafka with the cluster's TLS bootstrap brokers, its VPC, subnet and security group.
- Create a Glue table for the topic, classification JSON, with the columns
group,txid,seq,operation,beforekey,destandrow, all of typestring. - Create a Spark Streaming job from the table to the S3 bucket, and start it. It writes objects in folders by ingest year, month, day and hour.
Errors from the job are in its run history; the two most common are in Troubleshooting.