Skip to content

lloydmeta/hystrix-scala-scratchpad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Readme

This is Lloyd's Hystrix scratchpad

Examples

Single command returning a Scala Future

import scala.concurrent.ExecutionContext.Implicits.global
import com.beachape.hystrixscratchpad.hystrixcommands._
import scala.concurrent.Future
import scala.util.Success

val newCommand = CommandScrapeUrl("http://amazon.com")
newCommand.future onComplete {
  case Success(Some(x)) => println(x)
  case _  => println("oops")
}

Collapsed Command

import scala.concurrent.ExecutionContext.Implicits.global
import com.beachape.hystrixscratchpad.hystrixcommands._
import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext
import scala.concurrent.Future
import scala.util.Success

// Initialise a HystrixRequestContext. All Hystrix commands that derive
// from a Collapser class are "collapsed" within this context to run inside
// a single command
val context = HystrixRequestContext.initializeContext()

val c1 = CommandCollapserScrapeUrl("http://beachape.com")
val c2 = CommandCollapserScrapeUrl("http://google.com")
val c3 = CommandCollapserScrapeUrl("http://yahoo.com")

val listOfFutures = List(c1, c2, c3).map(_.future)
val futureList = Future.sequence(listOfFutures)

futureList.foreach(_.foreach {
    case Some(x) => println(x)
    case _ => println("oops")
})

// Sleep for 10 seconds to give the requests to come
// back before shutting down the context
Thread.sleep(10000)

// Shut down the context
context.shutdown()

About

Lloyd's Hystrix playground. Exploring Scala + Hystrix.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages