Skip to content

Instantly share code, notes, and snippets.

@mrcmatuszak
Last active July 19, 2017 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrcmatuszak/f29438f0e178c04bc5f2d6c937c70945 to your computer and use it in GitHub Desktop.
Save mrcmatuszak/f29438f0e178c04bc5f2d6c937c70945 to your computer and use it in GitHub Desktop.
Illegal GraphDSL usage
[error] (run-main-0) java.lang.IllegalStateException: Illegal GraphDSL usage. Inlets [GraphStages$Identity$.in] were not returned in the resulting shape and not connected. Outlets [Collect.out, Map.out] were not returned in the resulting shape and not connected.
java.lang.IllegalStateException: Illegal GraphDSL usage. Inlets [GraphStages$Identity$.in] were not returned in the resulting shape and not connected. Outlets [Collect.out, Map.out] were not returned in the resulting shape and not connected.
at akka.stream.scaladsl.GraphDSL$Builder.result(Graph.scala:1163)
at akka.stream.scaladsl.GraphApply.createGraph(GraphApply.scala:539)
at akka.stream.scaladsl.GraphApply.create(GraphApply.scala:19)
at akka.stream.scaladsl.GraphApply.create$(GraphApply.scala:15)
at akka.stream.scaladsl.GraphDSL$.create(Graph.scala:1036)
at Main2$.delayedEndpoint$com$ryanair$bi$ngmcs$Main2$1(App.scala:91)
at Main2$delayedInit$body.apply(App.scala:22)
at scala.Function0.apply$mcV$sp(Function0.scala:34)
at scala.Function0.apply$mcV$sp$(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App.$anonfun$main$1$adapted(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:389)
at scala.App.main(App.scala:76)
at scala.App.main$(App.scala:74)
at Main2$.main(App.scala:22)
at Main2.main(App.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
[trace] Stack trace suppressed: run last compile:run for the full output.
final case class MyShape(
in: Inlet[String],
out1: Outlet[String],
out2: Outlet[Int]
) extends Shape {
override def inlets: immutable.Seq[Inlet[_]] = immutable.Seq(in)
override def outlets: immutable.Seq[Outlet[_]] = immutable.Seq(out1,out2)
override def deepCopy(): Shape = MyShape(
in.carbonCopy(),
out1.carbonCopy(),
out2.carbonCopy()
)
}
object MyShape {
def apply(implicit actorSystem: ActorSystem, materializer: Materializer): Graph[MyShape, NotUsed] = {
GraphDSL.create() { implicit builder =>
import GraphDSL.Implicits._
val source: FlowShape[String, String] = builder.add(Flow[String])
val either: EitherFanOutShape[Throwable, Int] = builder.add(EitherFanOutShape[Throwable, Int])
val toInt = builder.add(Flow[String].map(r => Try(r.toInt).toEither))
val toString = builder.add(Flow[Throwable].map(_.getMessage))
source ~> toInt ~> either.eitherIn
either.errorsOut ~> toString
MyShape(source.in, toString.out, either.resultsOut)
}
}
}
object Main extends App {
RunnableGraph.fromGraph(GraphDSL.create() { implicit builder =>
import GraphDSL.Implicits._
val source: SourceShape[String] = builder.add(Source.single("2"))
val shape = builder.add(MyShape.apply)
source ~> shape.in
shape.out2 ~> Sink.foreach(println)
shape.out1 ~> Sink.foreach(println)
ClosedShape
}).run()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment