Hello,
I would like to configure my websocket client connection to work on
2-way communication, but I have problems with that. My code :
Sink and Source flow creation:
def myFlow(): Flow[String, SlackMessageStreamPacket, Any] = {
val in = Flow[String]
.map(SlackMessageStreamPacket(_))
.to(Sink.actorRef[SlackMessageStreamPacket](actorRef, PoisonPill))
val out = Source.actorRef[SlackMessageStreamPacket](100,
OverflowStrategy.fail)
.mapMaterializedValue(actorRef ! Initiate2(_))
Flow.fromSinkAndSource(in, out)
}
Webscoket flow creation via myFlow:
val websocketFlow = Flow[Message].filter{
case TextMessage.Strict(_) => true
case TextMessage.Streamed(_) => false
case binary: BinaryMessage => false
}.collect {
case TextMessage.Strict(msg) => msg
}
.via(myFlow)
.map {
case msg: SlackMessageStreamPacket => TextMessage.Strict(msg.message)
case _ => null
}
Connection:
val (fut, promise) = http.singleWebSocketRequest(WebSocketRequest(uri), wsFlow)
fut.map {
case v: ValidUpgrade =>
println("connection ok!...")
case InvalidUpgradeResponse(response, cause) =>
throw new RuntimeException(s"Connection to chat at $uri failed with $cause")
}
PS.: Another way with no success :
val websocketFlow: Flow[Message, Message, Any] =
Flow.fromGraph(GraphDSL.create(outputSource) {
implicit builder =>
os =>
builder.materializedValue.to(Sink.foreach(queue => actorRef !
Initiate(queue)))
val inlet = builder.add(Flow[Message].filter({
case TextMessage.Strict(_) => true
case TextMessage.Streamed(_) => false
case binary: BinaryMessage => false
})
.map({
case TextMessage.Strict(text) => SlackMessageStreamPacket(text)
case _ => null
})
.to(Sink.actorRef[SlackMessageStreamPacket](actorRef, PoisonPill))).in
FlowShape(inlet, os.out)
})
Its connect well but not keep connected :( . Can anyone help me on that ?
Thanks!
--
>>>>>>>>>> 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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.