Hi Team, I am running flink cluster locally. I am ...
# troubleshooting
s
Hi Team, I am running flink cluster locally. I am trying to run the given example python progrram like
Copy code
./bin/flink run --python examples/python/datastream/connectors/kafka_json_format.py --jarfile lib/flink-sql-connector-kafka-3.1-SNAPSHOT.jar
Following is the python code.
Copy code
################################################################################
#  Licensed to the Apache Software Foundation (ASF) under one
#  or more contributor license agreements.  See the NOTICE file
#  distributed with this work for additional information
#  regarding copyright ownership.  The ASF licenses this file
#  to you under the Apache License, Version 2.0 (the
#  "License"); you may not use this file except in compliance
#  with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
# limitations under the License.
################################################################################
import logging
import sys
import os
from pyflink.common import Types
from pyflink.datastream import StreamExecutionEnvironment
from pyflink.datastream.connectors.kafka import FlinkKafkaProducer, FlinkKafkaConsumer
from pyflink.datastream.formats.json import JsonRowSerializationSchema, JsonRowDeserializationSchema
from pyflink.common.serialization import DeserializationSchema, SimpleStringSchema
from pyflink.common.configuration import Configuration

def read_from_kafka(env):
    # deserialization_schema = JsonRowDeserializationSchema.Builder() \
    #     .type_info(Types.ROW([Types.INT(), Types.STRING()])) \
    #     .build()
    kafka_consumer = FlinkKafkaConsumer(
        topics='tick_data',
        deserialization_schema=SimpleStringSchema(),
        properties={'bootstrap.servers': 'localhost:9092', 'group.id': 'test_group_1'}
    )
    kafka_consumer.set_start_from_earliest()

    env.add_source(kafka_consumer).print()
    env.execute()


if __name__ == '__main__':
    logging.basicConfig(stream=sys.stdout, level=logging.INFO, format="%(message)s")

    env = StreamExecutionEnvironment.get_execution_environment()
    # jar_files = ["flink-sql-connector-kafka-3.1-SNAPSHOT.jar"]
    # SRC_DIR = os.path.dirname(os.path.realpath(__file__))
    # jar_paths = tuple([f"file:///{os.path.join(SRC_DIR, 'jars', name)}" for name in jar_files])
    # print(jar_paths)
    # env.add_jars(*jar_paths)
    env.add_jars("file:///Users/stanlythomas/Documents/MyProjects/DataAnalyzerSheets/server/data/flink-sql-connector-kafka-3.1-SNAPSHOT.jar")
    # env.add_classpaths("file:///Users/stanlythomas/Documents/MyProjects/DataAnalyzerSheets/server/data/flink-sql-connector-kafka-3.1-SNAPSHOT.jar")
    # env.add_jars("file://flink-sql-connector-kafka-1.17.2.jar")
    conf = Configuration()
    # conf.set_string("rest.address", "localhost")
    # conf.set_integer("rest.port", 8081)
    # env.configure(conf)
    conf.set_string("execution.target", "remote")
    conf.set_string("jobmanager.rpc.address", "localhost")
    conf.set_integer("jobmanager.rpc.port", 8081)
    # env.configure(conf)
    # print("start writing data to kafka")
    # write_to_kafka(env)

    print("start reading data from kafka")
    read_from_kafka(env)
But I am getting the following error
Copy code
start reading data from kafka
Traceback (most recent call last):
  File "/Users/stanlythomas/Downloads/flink-1.19.0/examples/python/datastream/connectors/kafka_json_format.py", line 67, in <module>
    read_from_kafka(env)
  File "/Users/stanlythomas/Downloads/flink-1.19.0/examples/python/datastream/connectors/kafka_json_format.py", line 40, in read_from_kafka
    env.execute()
  File "/Users/stanlythomas/Downloads/flink-1.19.0/opt/python/pyflink.zip/pyflink/datastream/stream_execution_environment.py", line 813, in execute
  File "/Users/stanlythomas/Downloads/flink-1.19.0/opt/python/py4j-0.10.9.7-src.zip/py4j/java_gateway.py", line 1322, in __call__
  File "/Users/stanlythomas/Downloads/flink-1.19.0/opt/python/pyflink.zip/pyflink/util/exceptions.py", line 146, in deco
  File "/Users/stanlythomas/Downloads/flink-1.19.0/opt/python/py4j-0.10.9.7-src.zip/py4j/protocol.py", line 326, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling o0.execute.
: java.net.MalformedURLException: no protocol: ['file:/Users/stanlythomas/Downloads/flink-1.19.0/lib/flink-sql-connector-kafka-3.1-SNAPSHOT.jar', 'file:/Users/stanlythomas/Downloads/flink-1.19.0/opt/flink-python-1.19.0.jar']
        at java.base/java.net.URL.<init>(URL.java:772)
        at java.base/java.net.URL.<init>(URL.java:654)
        at java.base/java.net.URL.<init>(URL.java:590)
        at org.apache.flink.configuration.ConfigUtils.decodeListFromConfig(ConfigUtils.java:133)
        at org.apache.flink.client.cli.ExecutionConfigAccessor.getJars(ExecutionConfigAccessor.java:77)
        at org.apache.flink.client.deployment.executors.PipelineExecutorUtils.getJobGraph(PipelineExecutorUtils.java:77)
        at org.apache.flink.client.deployment.executors.AbstractSessionClusterExecutor.execute(AbstractSessionClusterExecutor.java:72)
        at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.executeAsync(StreamExecutionEnvironment.java:2440)
        at org.apache.flink.client.program.StreamContextEnvironment.executeAsync(StreamContextEnvironment.java:188)
        at org.apache.flink.client.program.StreamContextEnvironment.execute(StreamContextEnvironment.java:117)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
        at org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:374)
        at org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282)
        at org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
        at org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79)
        at org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238)
        at java.base/java.lang.Thread.run(Thread.java:1570)

org.apache.flink.client.program.ProgramAbortException: java.lang.RuntimeException: Python process exits with code: 1
        at org.apache.flink.client.python.PythonDriver.main(PythonDriver.java:134)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:355)
        at org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:222)
        at org.apache.flink.client.ClientUtils.executeProgram(ClientUtils.java:108)
        at org.apache.flink.client.cli.CliFrontend.executeProgram(CliFrontend.java:1026)
        at org.apache.flink.client.cli.CliFrontend.run(CliFrontend.java:247)
        at org.apache.flink.client.cli.CliFrontend.parseAndRun(CliFrontend.java:1270)
        at org.apache.flink.client.cli.CliFrontend.lambda$mainInternal$10(CliFrontend.java:1367)
        at org.apache.flink.runtime.security.contexts.NoOpSecurityContext.runSecured(NoOpSecurityContext.java:28)
        at org.apache.flink.client.cli.CliFrontend.mainInternal(CliFrontend.java:1367)
        at org.apache.flink.client.cli.CliFrontend.main(CliFrontend.java:1335)
Caused by: java.lang.RuntimeException: Python process exits with code: 1
        at org.apache.flink.client.python.PythonDriver.main(PythonDriver.java:124)
        ... 12 more
Can someone help?