Important

You are viewing documentation for an older version of Confluent Platform. For the latest, click here.

Hybrid Kafka Clusters

This Confluent Cloud demo showcases a hybrid Kafka cluster: one cluster is a self-managed cluster running locally, the other is a Confluent Cloud cluster. The use case is “Bridge to Cloud” as customers migrate from on premises to cloud.

image

Overview

The major components of the demo are:

  • Two Kafka clusters: one cluster is a self-managed cluster running locally, the other is a Confluent Cloud cluster.
  • Confluent Control Center: manages and monitors the deployment. Use it for topic inspection, viewing the schema, viewing and creating KSQL queries, streams monitoring, and more.
  • KSQL: stream processing on topics users and pageviews in Confluent Cloud. The KSQL queries resemble those in the KSQL Tutorial , but instead of KSQL streams backed to a local cluster, they are backed to your Confluent Cloud cluster. The KSQL server itself is running locally.
  • Two Kafka Connect clusters: one cluster connects to the local self-managed cluster and one connects to the Confluent Cloud cluster. Both Connect worker processes themselves are running locally.
    • One instance of kafka-connect-datagen: a source connector that produces mock data to prepopulate the topic pageviews locally
    • One instance of kafka-connect-datagen: a source connector that produces mock data to prepopulate the topic users in the Confluent Cloud cluster
    • Confluent Replicator: copies the topic pageviews from the local cluster to the Confluent Cloud cluster
  • Confluent Schema Registry: by default, the demo runs with a locally-running Schema Registry and the Kafka data is written in Avro format.

Note

This is a demo environment and has many services running on one host. Do not use this demo in production, and do not use Confluent CLI in production. This is meant exclusively to easily demo the Confluent Platform and Confluent Cloud with KSQL.

Run demo

Demo validated with:

  • Confluent Platform 5.1
  • Confluent Cloud
  • Confluent Cloud CLI
  • Java version 1.8.0_162
  • MacOS 10.12
  1. Clone the examples GitHub repository.

    $ git clone https://github.com/confluentinc/examples
    
  2. Change directory to the Confluent Cloud demo.

    $ cd examples/ccloud
    
  3. By default, the demo runs with a locally running Schema Registry. If you prefer to use Confluent Cloud Schema Registry instead:

    image
    1. Enable Confluent Cloud Schema Registry prior to running the demo
    2. Modify the appropriate start script (see next step) and set USE_CONFLUENT_CLOUD_SCHEMA_REGISTRY=true
  4. Start the entire demo by running a single command. You have two choices: using a Confluent Platform local install or Docker Compose. This will take less than 5 minutes to complete.

    # For Confluent Platform local install using Confluent CLI
    $ ./start.sh
    
    # For Docker Compose
    $ ./start-docker.sh
    
  5. Use Google Chrome to view the Confluent Control Center GUI at http://localhost:9021 . Click on the top-right button that shows the current date, and change Last 4 hours to Last 30 minutes.

Playbook

Confluent Cloud

  1. You must have access to an initialized, working Confluent Cloud cluster. To sign up for the service, go to Confluent Cloud page. Validate you have a configuration file for your Confluent Cloud cluster.

    $ cat ~/.ccloud/config
    
  2. You must have locally installed Confluent Cloud CLI. To install the CLI, follow these steps. Validate you can list topics in your cluster.

    $ ccloud topic list
    
  3. Get familiar with the Confluent Cloud CLI. For example, create a new topic called test, produce some messages to that topic, and then consume from that topic.

    $ ccloud topic create test
    Topic "test" created.
    $ ccloud produce -t test
    a
    b
    c
    ^C
    $ ccloud consume -b -t test
    a
    b
    c
    ^CProcessed a total of 3 messages.
    

Confluent Control Center

  1. Monitoring –> Data Streams –> Message Delivery: hover over any chart to see number of messages and average latency within a minute time interval.

    image
  2. Management –> Kafka Connect: Confluent Control Center uses the Kafka Connect API to manage Kafka connectors, and more specifically for this demo, Confluent Replicator.

    • Kafka Connect Sources tab shows the connector replicator. Click Edit to see the details of the connector configuration.

      image
  3. Management –> Topics –> Topic Information: For a given topic, click on the three dots ... next to the topic name to see more options per topic including in sync replicas, schema, topic messages, and configuration settings. Shown below is replica info.

    image

Note

There will not be any details on the Confluent Control Center System Health pages about brokers or topics because Confluent Cloud does not provide the Confluent Metrics Reporter instrumentation outside of the Confluent Cloud. Therefore, you should expect to see the following graphic on the System Health page.

image

KSQL

  1. View the KSQL server configuration file.

    # KSQL bootstrap servers point to Confluent Cloud
    $ cat `confluent current | tail -1`/ksql-server/ksql-server-ccloud.properties
    
  2. The KSQL server that is connected to Confluent Cloud is listening on port 8089 for KSQL CLI connections. You have two options for interfacing with KSQL.

    1. Run KSQL CLI to get to the KSQL CLI prompt.

      $ ksql http://localhost:8089
      
    2. Run the preview KSQL web interface. Navigate your browser to http://localhost:8089/index.html

  3. At the KSQL prompt, view the configured KSQL properties that were set with the KSQL server configuration file shown earlier.

    ksql> SHOW PROPERTIES;
    
  4. View the existing KSQL streams and describe one of those streams called PAGEVIEWS_FEMALE_LIKE_89.

    ksql> SHOW STREAMS;
    
     Stream Name              | Kafka Topic              | Format
    --------------------------------------------------------------
     PAGEVIEWS_ORIGINAL       | pageviews                | AVRO
     PAGEVIEWS_FEMALE         | PAGEVIEWS_FEMALE         | AVRO
     PAGEVIEWS_FEMALE_LIKE_89 | pageviews_enriched_r8_r9 | AVRO
    --------------------------------------------------------------
    
    
    ksql> DESCRIBE PAGEVIEWS_FEMALE_LIKE_89;
    
     Field    | Type
    --------------------------------------
     ROWTIME  | BIGINT           (system)
     ROWKEY   | VARCHAR(STRING)  (system)
     USERID   | VARCHAR(STRING)  (key)
     PAGEID   | VARCHAR(STRING)
     REGIONID | VARCHAR(STRING)
     GENDER   | VARCHAR(STRING)
    --------------------------------------
    For runtime statistics and query details run: DESCRIBE EXTENDED <Stream,Table>;
    
  5. View the existing KSQL tables and describe one of those tables called PAGEVIEWS_REGIONS.

    ksql> SHOW TABLES;
    
     Table Name        | Kafka Topic       | Format | Windowed
    -----------------------------------------------------------
     PAGEVIEWS_REGIONS | PAGEVIEWS_REGIONS | AVRO   | true
     USERS_ORIGINAL    | users             | AVRO   | false
    -----------------------------------------------------------
    
    
    ksql> DESCRIBE PAGEVIEWS_REGIONS;
    
     Field    | Type
    --------------------------------------
     ROWTIME  | BIGINT           (system)
     ROWKEY   | VARCHAR(STRING)  (system)
     GENDER   | VARCHAR(STRING)  (key)
     REGIONID | VARCHAR(STRING)  (key)
     NUMUSERS | BIGINT
    --------------------------------------
    For runtime statistics and query details run: DESCRIBE EXTENDED <Stream,Table>;
    
  6. View the existing KSQL queries, which are continuously running, and explain one of those queries called CSAS_PAGEVIEWS_FEMALE_LIKE_89.

    ksql> SHOW QUERIES;
    
     Query ID                      | Kafka Topic              | Query String
    ----------------------------------------------------------------------------------------------------------
     CTAS_PAGEVIEWS_REGIONS        | PAGEVIEWS_REGIONS        | CREATE TABLE pageviews_regions WITH (value_format='avro') AS SELECT gender, regionid , COUNT(*) AS numusers FROM pageviews_female WINDOW TUMBLING (size 30 second) GROUP BY gender, regionid HAVING COUNT(*) > 1;
     CSAS_PAGEVIEWS_FEMALE         | PAGEVIEWS_FEMALE         | CREATE STREAM pageviews_female AS SELECT users_original.userid AS userid, pageid, regionid, gender FROM pageviews_original LEFT JOIN users_original ON pageviews_original.userid = users_original.userid WHERE gender = 'FEMALE';
     CSAS_PAGEVIEWS_FEMALE_LIKE_89 | pageviews_enriched_r8_r9 | CREATE STREAM pageviews_female_like_89 WITH (kafka_topic='pageviews_enriched_r8_r9', value_format='AVRO') AS SELECT * FROM pageviews_female WHERE regionid LIKE '%_8' OR regionid LIKE '%_9';
    ----------------------------------------------------------------------------------------------------------
    
    
    
    ksql> EXPLAIN CSAS_PAGEVIEWS_FEMALE_LIKE_89;
    
    Type                 : QUERY
    SQL                  : CREATE STREAM pageviews_female_like_89 WITH (kafka_topic='pageviews_enriched_r8_r9', value_format='AVRO') AS SELECT * FROM pageviews_female WHERE regionid LIKE '%_8' OR regionid LIKE '%_9';
    
    
    Local runtime statistics
    ------------------------
    messages-per-sec:         0   total-messages:        43     last-message: 4/23/18 10:28:29 AM EDT
     failed-messages:         0 failed-messages-per-sec:         0      last-failed:       n/a
    (Statistics of the local KSQL server interaction with the Kafka topic pageviews_enriched_r8_r9)
    
  7. At the KSQL prompt, view three messages from different KSQL streams and tables.

    ksql> SELECT * FROM PAGEVIEWS_FEMALE_LIKE_89 LIMIT 3;
    ksql> SELECT * FROM USERS_ORIGINAL LIMIT 3;
    
  8. In this demo, KSQL is run with Confluent Monitoring Interceptors configured which enables Confluent Control Center Data Streams to monitor KSQL queries. The consumer group names _confluent-ksql-default_query_ correlate to the KSQL query names shown above, and Confluent Control Center is showing the records that are incoming to each query.

For example, view throughput and latency of the incoming records for the persistent KSQL “Create Stream As Select” query CSAS_PAGEVIEWS_FEMALE, which is displayed as _confluent-ksql-default_query_CSAS_PAGEVIEWS_FEMALE in Confluent Control Center.

image

Confluent Replicator

Confluent Replicator copies data from a source Kafka cluster to a destination Kafka cluster. In this demo, the source cluster is a local install that represents a self-managed cluster, and the destination cluster is Confluent Cloud.

  1. View the Confluent Replicator configuration files. Note that in this demo, Replicator is run as a standalone binary.

    # Replicator's consumer points to the local cluster
    $ cat `confluent current | tail -1`/connect/replicator-to-ccloud-consumer.properties
    bootstrap.servers=localhost:9092
    
    # Replicator's producer points to the Confluent Cloud cluster and configures
    # Confluent Monitoring Interceptors for Control Center stream monitoring to work
    $ cat `confluent current | tail -1`/connect/replicator-to-ccloud-producer.properties
    ssl.endpoint.identification.algorithm=https
    confluent.monitoring.interceptor.ssl.endpoint.identification.algorithm=https
    sasl.mechanism=PLAIN
    confluent.monitoring.interceptor.sasl.mechanism=PLAIN
    security.protocol=SASL_SSL
    confluent.monitoring.interceptor.security.protocol=SASL_SSL
    retry.backoff.ms=500
    bootstrap.servers=<broker1>,<broker2>,<broker3>
    confluent.monitoring.interceptor.bootstrap.servers=<broker1>,<broker2>,<broker3>
    sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="<username>" password="<password>";
    confluent.monitoring.interceptor.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="<username>" password="<password>";
    
    # General Replicator properties define the replication policy
    $ cat `confluent current | tail -1`/connect/replicator-to-ccloud.properties
    topic.whitelist=pageviews
    
  2. View topics pageviews in the local cluster

    $ kafka-topics --zookeeper localhost:2181  --describe --topic pageviews
    Topic:pageviews    PartitionCount:12       ReplicationFactor:1     Configs:
            Topic: pageviews   Partition: 0    Leader: 0       Replicas: 0     Isr: 0
            Topic: pageviews   Partition: 1    Leader: 0       Replicas: 0     Isr: 0
            Topic: pageviews   Partition: 2    Leader: 0       Replicas: 0     Isr: 0
            Topic: pageviews   Partition: 3    Leader: 0       Replicas: 0     Isr: 0
            Topic: pageviews   Partition: 4    Leader: 0       Replicas: 0     Isr: 0
            Topic: pageviews   Partition: 5    Leader: 0       Replicas: 0     Isr: 0
            Topic: pageviews   Partition: 6    Leader: 0       Replicas: 0     Isr: 0
            Topic: pageviews   Partition: 7    Leader: 0       Replicas: 0     Isr: 0
            Topic: pageviews   Partition: 8    Leader: 0       Replicas: 0     Isr: 0
            Topic: pageviews   Partition: 9    Leader: 0       Replicas: 0     Isr: 0
            Topic: pageviews   Partition: 10   Leader: 0       Replicas: 0     Isr: 0
            Topic: pageviews   Partition: 11   Leader: 0       Replicas: 0     Isr: 0
    
  3. View the replicated topics pageviews in the Confluent Cloud cluster. In Confluent Control Center, for a given topic listed in Management –> Topics, click on the three dots ... next to the topic name to see more options per topic including in sync replicas, schema, topic messages, and configuration settings. Shown below is replica info.

    image
  4. You can manage Confluent Replicator in the Management –> Kafka Connect page. The Sources tab shows the connector replicator. Click Edit to see the details of the connector configuration.

    image

Confluent Schema Registry

The connectors used in this demo are configured to automatically write Avro-formatted data, leveraging the Confluent Schema Registry . Depending on how you set USE_CONFLUENT_CLOUD_SCHEMA_REGISTRY in the start script, you may be running Confluent Schema Registry locally or Confluent Cloud Schema Registry. Either way, you will get a consistent experience with Schema Registry.

  1. View all the Schema Registry subjects.

    # Locally running Schema Registry
    $ curl http://localhost:8085/subjects/ | jq .
    
    # Confluent Cloud Schema Registry
    $ curl -u <SR API KEY>:<SR API SECRET> https://<SR ENDPOINT>/subjects
    
  2. From Confluent Control Center, under MANAGEMENT –> Topics -> Schema: view the schema for pageviews and users. The topic value is using a Schema registered with Schema Registry (the topic key is just a String).

    image
  3. From Confluent Control Center, view the KSQL streams which are configured for Avro format.

    image
  4. To migrate schemas from on-prem Schema Registry to Confluent Cloud Schema Registry, follow this step-by-step guide. Refer to the file submit_replicator_schema_migration_config.sh for an example of a working Replicator configuration for schema migration.

Confluent Cloud Configurations

  1. View the the template delta configuration for Confluent Platform components and clients to connect to Confluent Cloud:

    $ ls template_delta_configs/
    
  2. View your Confluent Cloud configuration file

    $ cat $HOME/.ccloud/config
    
  3. Generate the per-component delta configuration parameters, automatically derived from your Confluent Cloud configuration file:

    $ ./ccloud-generate-cp-configs.sh
    
  4. If you ran this demo as start.sh which uses Confluent CLI, it saves all configuration files and log files in the respective component subfolders in the current Confluent CLI temp directory (requires demo to be actively running):

    # For Confluent Platform local install using Confluent CLI
    $ ls `confluent current | tail -1`
    
  5. If you ran this demo as start-docker.sh, the configuration is available in the docker-compose.yml file.

    # For Docker Compose
    $ cat docker-compose.yml
    

Troubleshooting the demo

  1. If you can’t run the demo due to error messages such as “‘ccloud’ is not found” or “‘ccloud’ is not initialized”, validate that you have access to an initialized, working Confluent Cloud cluster and you have locally installed Confluent Cloud CLI.

  2. To view log files, look in the current Confluent CLI temp director (requires demo to be actively running):

    $ ls `confluent current | tail -1`
    
  3. Or if you ran with Docker, then run docker-compose logs.

Teardown

  1. Stop the demo, destroy all local components.

    # For Confluent Platform local install using Confluent CLI
    $ ./stop.sh
    
    # For Docker Compose
    $ ./stop-docker.sh
    
  2. Delete all Confluent Platform topics in CCloud that this demo used, including topics used for Confluent Control Center, Kafka Connect, KSQL, and Confluent Schema Registry. Warning: this may have unintended consequence of deleting topics that you wanted to keep.

    $ ./ccloud-delete-all-topics.sh