Registering a Kafka data source with DDL

Register a Kafka data source with Flink SQL DDL when you prefer SQL to the Streaming SQL Console forms. The DDL holds the broker, security, and authentication properties as table options.

Collect the broker endpoints and, for OAuth, the client ID, the client secret, the token endpoint URL, and the broker TLS material. If you use project files for the truststores, upload them first. For more information, see Managing project files.

This task runs a CREATE TABLE statement with the Kafka connector, SASL_SSL, and OAUTHBEARER. Adjust the example for your protocol and SASL mechanism.

  1. In the Streaming SQL Console, click Projects in the left navigation pane, and click the name of your project.
    The project opens, with the Explorer panel on the left. To open the Streaming SQL Console, see Accessing Cloudera SQL Stream Builder.
  2. In the Explorer, open the menu of Jobs, and click New Job.
    The Create New Job window opens.
  3. Enter a Job Name, or click Generate Job Name.
  4. Click Create.
    The job opens in a new tab, with an empty SQL editor.
  5. In the SQL editor, enter the following statement.
    CREATE TABLE awc_kafka_table (
      id INT,
      name STRING
    ) WITH (
      'connector' = 'kafka',
      'topic' = '[*** YOUR TOPIC NAME ***]',
      'properties.bootstrap.servers' = '[*** KAFKA BOOTSTRAP HOST AND PORT ***]',
      'properties.security.protocol' = 'SASL_SSL',
      'properties.sasl.mechanism' = 'OAUTHBEARER',
      'properties.ssl.truststore.type' = 'PEM',
      'properties.ssl.truststore.certificates' = '[*** FORMATTED BROKER CERTIFICATE PEM SINGLE LINE ***]',
      'properties.sasl.jaas.config' = 'org.apache.flink.kafka.shaded.org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required sasl.oauthbearer.token.endpoint.url="[*** OAUTH TOKEN ENDPOINT URL ***]" [*** OTHER LOGIN MODULE OPTIONS ***];',
      'properties.sasl.oauthbearer.token.endpoint.url' = '[*** OAUTH TOKEN ENDPOINT URL ***]',
      'properties.sasl.login.callback.handler.class' = 'org.apache.flink.kafka.shaded.org.apache.kafka.common.security.oauthbearer.secured.OAuthBearerLoginCallbackHandler',
      'format' = 'json'
    );

    For more information about the editor, see Streaming SQL Console.

  6. Replace the placeholders with your values.
    For a truststore that you uploaded to the project, use ${ssb.project-file:[***PATH***]} in place of inline PEM where the connector option accepts a file path.
  7. Click the Execute job icon.

You can now use the table in your queries. For the options of the connector, see Kafka connector.

A DDL table can use an existing topic or create a new topic.