Skip to content

Instantly share code, notes, and snippets.

@akhilvijayan05
Last active October 13, 2018 12:02
Show Gist options
  • Save akhilvijayan05/09dd26a140cc9cd2da511bcc1ae17932 to your computer and use it in GitHub Desktop.
Save akhilvijayan05/09dd26a140cc9cd2da511bcc1ae17932 to your computer and use it in GitHub Desktop.
A simple example for an AMPS subscriber
import com.crankuptheamps.client.Client;
import com.crankuptheamps.client.exception.AMPSException;
import scala.collection.JavaConverters._
object Subscriber extends App {
val client = new Client("subscribe")
try {
client.connect("tcp://127.0.0.1:9007/amps/json")
client.logon()
val messageStream = client.subscribe("messages").iterator().asScala
messageStream.foreach(message => println(message.getData))
} catch {
case ampsException: AMPSException => println(s"Caught exception: ${ampsException.getMessage}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment