Thanks for the quick answer.
With this I can do something with the data, but is it also possible, that
the flow (codec2) sends a bytestring, when it gets produced by the Source?
I tried the following, but here it waits until the source completes before
sending the whole Bytestring. I want that it sends the Bytestringparts
directly when they arrive.
public static final BidiFlow<Message, ByteString, ByteString, Message, NotUsed>
codec2 =
BidiFlow.fromFunctions((x -> {
if(x.isText()) {
log.info("textmessage currently not supported");
return null;
}else{
BinaryMessage binaryMessage = x.asBinaryMessage();
if(binaryMessage.isStrict()) {
log.info("strict Binary Message");
return binaryMessage.getStrictData();
}else{
Source<ByteString, ?> streamedData =
binaryMessage.getStreamedData();
CompletionStage<ByteString> byteStringCompletionStage =
streamedData.runFold(ByteString.empty(), (aggr, next) -> aggr.concat(next),
materializer);
return
byteStringCompletionStage.toCompletableFuture().get();
}
}
}), (x -> BinaryMessage.create(x)));
Am Dienstag, 31. Mai 2016 18:34:37 UTC+2 schrieb Konrad Malawski:
>
> It returned an Akka Stream there :-)
> So you should learn a bit about Akka Streams to know how to handle those:
> http://doc.akka.io/docs/akka/2.4.6/scala/stream/stream-quickstart.html
> <http://www.google.com/url?q=http%3A%2F%2Fdoc.akka.io%2Fdocs%2Fakka%2F2.4.6%2Fscala%2Fstream%2Fstream-quickstart.html&sa=D&sntz=1&usg=AFQjCNEBfFg0IgdVLvhtNScKjxB8WGhJqw>
> and take it from there.
>
> It's basically as simple as
> streamedData.map(_.utf8String).runWith(Sink.foreach(it => println(it))) etc.
>
> Hope this helps!
> --
> Konrad `ktoso` Malawski
> Akka <http://akka.io> @ Lightbend <http://lightbend.com>
>
> On 31 May 2016 at 18:28:49, Qux ([email protected] <javascript:>) wrote:
>
> Hi,
>
> I looked into many nice Examples with Akka Websockets (like
> https://markatta.com/codemonkey/blog/2016/04/18/chat-with-akka-http-websockets/),
>
> but sadly the used flows only handle strict Messages.
>
> Is is possible to write a Flow from Message to Bytestring that handles
> Strict and streamed Messages?
>
> Here my (java-)code so far:
>
> public static final BidiFlow<Message, ByteString, ByteString, Message,
> NotUsed> codec2 =
>> BidiFlow.fromFunctions((x -> {
>> if(x.isText()) {
>> log.info("textmessage currently not supported");
>> return null;
>> }else{
>> BinaryMessage binaryMessage = x.asBinaryMessage();
>> if(binaryMessage.isStrict()) {
>> log.info("strict Binary Message");
>> return binaryMessage.getStrictData();
>> }else{
>> Source<ByteString, ?> streamedData =
>> binaryMessage.getStreamedData();
>> // TODO: WHAT NOW???.
>> return null;
>> }
>> }
>> }), (x -> BinaryMessage.create(x)));
>>
>>
>
> I'm happy for all tips, java/scala-code-snippets and so on :)
>
> Big Thanks
> Qux
> --
> >>>>>>>>>> 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] <javascript:>.
> To post to this group, send email to [email protected]
> <javascript:>.
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>
>
--
>>>>>>>>>> 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.