Commits

Scott Bennett-McLeish  committed 6e16abe

Added some exception handling to processBOM as sometimes the BOM site might not be available (and it threw exception and exited).

  • Participants
  • Parent commits fafcb21

Comments (0)

Files changed (2)

File rabbitmq_messaging/ExtractTemperatures.groovy

 
 class ExtractTemperatures {
 	
-	def processBOM(Expando site) {
+	def processBOM(Expando site) throws UnknownHostException {
 		//create a URL and get the text from it
 		def content = new URL(site.source).text
 

File rabbitmq_messaging/WeatherProducer.groovy

 		def extractTemperatures = new ExtractTemperatures()
 
 		while (true) {
-			int sleepTime = Math.random()*30000
+			int sleepTime = 30000 + (Math.random()*30000) //30secs + 0-30
 			
-			String myData = extractTemperatures.processBOM(bomSite)
-			
-			channel.basicPublish(exchangeName, routingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, myData.getBytes())
+			try {
+				String myData = extractTemperatures.processBOM(bomSite)
+				channel.basicPublish(exchangeName, routingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, myData.getBytes())
+			} catch (UnknownHostException uhe) {
+				println "${uhe.getMessage()}"
+			}
 
 			println "Sleeping for ${sleepTime}ms"
 			sleep(sleepTime)