@@ -44,12 +44,28 @@ def createStream(ssc, brokerUrl, topic,
4444
4545 try :
4646 jstream = ssc ._jvm .MQTTUtils .createStream (ssc ._jssc , brokerUrl , topic , jlevel )
47-
4847 except Py4JError , e :
49- # TODO: use --jar once it also work on driver
50- if not e .message or 'call a package' in e .message :
51- print "No Mqtt package, please put the assembly jar into classpath:"
52- print " $ bin/spark-submit --driver-class-path external/mqtt-assembly/target/" + \
53- "scala-*/spark-streaming-mqtt-assembly-*.jar"
48+ if 'ClassNotFoundException' in str (e .java_exception ):
49+ MQTTUtils ._printErrorMsg (ssc .sparkContext )
5450 raise e
5551 return DStream (jstream , ssc , UTF8Deserializer ())
52+
53+ @staticmethod
54+ def _printErrorMsg (sc ):
55+ print ("""
56+ ________________________________________________________________________________________________
57+
58+ Spark Streaming's MQTT libraries not found in class path. Try one of the following.
59+
60+ 1. Include the MQTT library and its dependencies with in the
61+ spark-submit command as
62+
63+ $ bin/spark-submit --packages org.apache.spark:spark-streaming-mqtt:%s ...
64+
65+ 2. Download the JAR of the artifact from Maven Central http://search.maven.org/,
66+ Group Id = org.apache.spark, Artifact Id = spark-streaming-mqtt-assembly, Version = %s.
67+ Then, include the jar in the spark-submit command as
68+
69+ $ bin/spark-submit --jars <spark-streaming-mqtt-assembly.jar> ...
70+ ________________________________________________________________________________________________
71+ """ % (sc .version , sc .version ))
0 commit comments