[英]Convert Sink to Graph(SinkShape) in Akka Streams?
I have something like this: 我有这样的事情:
implicit val system = ActorSystem("actorSystem")
implicit val materializer = ActorMaterializer()
val (ref: ActorRef, publisher: Publisher[(String, String, String)]) =
Source.actorRef[(String, String, String)](bufferSize = 1000, OverflowStrategy.fail)
.toMat(transferFTP(_))(Keep.both)
.run()
def transferFTP(data: (String, String, String)): Sink[ByteString, Future[IOResult]] = {
// ...
}
In every example I have read, toMat()
takes a Sink
as a parameter, but the compiler expects Graph[SinkShape[(String,String,String)], NotInferedMat2]
. 在我读过的每个例子中,
toMat()
将Sink
作为参数,但编译器需要Graph[SinkShape[(String,String,String)], NotInferedMat2]
。
toMat
does take a Sink
. toMat
确实需要一个Sink
。 A Sink[(String, String, String), _]
is a Graph[SinkShape[(String, String, String)], _]
(in other words, the former is a subclass of the latter). Sink[(String, String, String), _]
是Graph[SinkShape[(String, String, String)], _]
(换句话说,前者是后者的子类)。 One of the problems is that you're passing in a Sink[ByteString, _]
instead. 其中一个问题是你传入了一个
Sink[ByteString, _]
。 Also, you're expecting a Publisher[(String, String, String)]
when the materialized value of your Sink
is a Future[IOResult]
. 此外,当您的
Sink
器的具体化值是Future[IOResult]
时,您期望Publisher[(String, String, String)]
Future[IOResult]
。
The following is an example in which the types align, thus making the compiler happy: 以下是类型对齐的示例,从而使编译器满意:
val tupleToByteString: ((String, String, String)) => ByteString = ???
val transferFTP: Sink[ByteString, Future[IOResult]] = ???
val (ref: ActorRef, sink: Future[IOResult]) =
Source.actorRef[(String, String, String)](bufferSize = 1000, OverflowStrategy.fail)
.via(Flow.fromFunction(tupleToByteString)) // alternatively: .map(tupleToByteString)
.toMat(transferFTP)(Keep.both)
.run()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.