As you've probably noticed in the migration documentation, the migration path for GraphStage is not yet documented.
http://doc.akka.io/docs/akka-stream-and-http-experimental/2.0-M1/scala/migration-guide-1.0-2.x-scala.html#FlexiMerge_an_FlexiRoute_has_been_replaced_by_GraphStage If I were you, I'd start with the implementation of Broadcast, here: https://github.com/akka/akka/blob/releasing-akka-stream-and-http-experimental-2.0-M1/akka-stream/src/main/scala/akka/stream/scaladsl/Graph.scala#L254 Then, replace with your custom shape, etc. Hope that helps. On Thursday, November 12, 2015 at 1:46:48 PM UTC-7, tigerfoot wrote: > > Hello, > > I have a "switch" code shown below in Akka stream 1.0. I'll be totally > honest, I don't understand 100% of what's going on here--I reworked it from > a sample found someplace. Is there an example somewhere of what an > equivalent structure would look like in 2.0-M1? > > Thanks for any hints! > > import FanOutShape._ > class CommandShape(_init: Init[QM[Command]] = > Name[QM[Command]]("CommandRouter")) extends FanOutShape[QM[Command]](_init) > { > val outMsg = newOutlet[QM[MessageCommand]]("message") > val outFallthru = newOutlet[QM[Command]]("fallthru") // unknown message > protected override def construct(i: Init[QM[Command]]) = new > CommandShape(i) > } > > // This next bit is the Flow (FlexiRoute) that does the "smart fanout" > based on the switch logic > // using the FanOutShape designed above. > case class CommandRouter() extends FlexiRoute[QM[Command], > CommandShape](new CommandShape, Attributes.name("CommandRouter")) { > import FlexiRoute._ > > override def createRouteLogic(p: PortT) = new RouteLogic[QM[Command]] { > override def initialState = State[Any](DemandFromAll(p.outMsg, > p.outFallthru)) { (ctx, _, element) => > element.body match { > case c: MessageCommand => ctx.emit(p.outMsg){ > val mc = element.body.asInstanceOf[MessageCommand] > element.copy( > metaTags = List( // Add meaningful metatags to message for error output > mc.recipient.firstName, > mc.recipient.lastName > ) ++ mc.recipient.contacts.map{case(k,v) => k+":"+v}.toList, > body = mc > ) > } > // case other commands here... > case unknown => ctx.emit(p.outFallthru)(element) > } > SameState > } > > override def initialCompletionHandling = eagerClose > } > } > > To use it in a flow I would do something like: > > val commandSwitch = builder.add(CommandRouter()) > -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
