You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by dragos <gi...@git.apache.org> on 2015/02/03 15:24:07 UTC

[GitHub] spark pull request: [Minor][streaming][MQTT streaming] some trivia...

Github user dragos commented on a diff in the pull request:

    https://github.com/apache/spark/pull/4178#discussion_r24005992
  
    --- Diff: examples/src/main/scala/org/apache/spark/examples/streaming/MQTTWordCount.scala ---
    @@ -42,25 +40,30 @@ object MQTTPublisher {
         StreamingExamples.setStreamingLogLevels()
     
         val Seq(brokerUrl, topic) = args.toSeq
    +    
    +    var client: MqttClient = null
     
         try {
    -      var peristance:MqttClientPersistence =new MqttDefaultFilePersistence("/tmp")
    -      client = new MqttClient(brokerUrl, MqttClient.generateClientId(), peristance)
    -    } catch {
    -      case e: MqttException => println("Exception Caught: " + e)
    -    }
    +      val persistence = new MemoryPersistence()
    +      client = new MqttClient(brokerUrl, MqttClient.generateClientId(), persistence)
     
    -    client.connect()
    +      client.connect()
     
    -    val msgtopic: MqttTopic = client.getTopic(topic)
    -    val msg: String = "hello mqtt demo for spark streaming"
    +      val msgtopic  = client.getTopic(topic)
    +      val msgContent = "hello mqtt demo for spark streaming"
    +      val message = new MqttMessage(msgContent.getBytes("utf-8"))
     
    -    while (true) {
    -      val message: MqttMessage = new MqttMessage(String.valueOf(msg).getBytes("utf-8"))
    -      msgtopic.publish(message)
    -      println("Published data. topic: " + msgtopic.getName() + " Message: " + message)
    +      while (true) {
    +        Thread.sleep(100)
    +        msgtopic.publish(message)
    +        println("Published data. topic: %s; Message: %s".format(msgtopic.getName(), message))
    +      }
    +      
    +    } catch {
    +      case e: MqttException => println("Exception Caught: " + e)
    --- End diff --
    
    I don't see the point in swallowing this exception. Why not let it percolate, it will anyway print the stacktrace and stop the process?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org