New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Reactive Streams
to add stream support to VertxFutureServerInterpreter
#2552
Use Reactive Streams
to add stream support to VertxFutureServerInterpreter
#2552
Conversation
…erpreter` The change is backward compatible and people using `VertxFutureServerInterpreter` shouldn't have to change their endpoints, but if they want they can now use streaming. Using `Reactive Streams` rather than `Vertx Streams` offers more flexibility. Any streaming library implementing `reactivestreams.Publisher` can be used. So even `zio`, `fs2`, `akka-streams` etc can be used to handles streams in `VertxFutureServerInterpreter`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi
Thanks for PR could you please add server streaming tests for vertx.
Such line ++ new ServerStreamingTests(createServerTest, ReactiveStreams).tests()
in VertxServerTest
alongside adding ReactiveStreams type param in tests should do the job. If you will have any questions let me know.
Hi @Pask423, I tried hard to make the tests pass, but there's something I don't understand in Any chance to have a I pushed a new commit with the tests. Thx, cheers. |
I think that it is unlikely, unfortunately - at least I do not know anyone who we could ask. I will try to take a look tomorrow or today. Maybe together we will come up with something. |
Thx, I'll also try to ask the |
Sooooo I tried the all day to make the tests pass with the So I went with another proposition (latest commit) to use directly the What do you think? |
Seems ok I came to similar conclusions some time ago - I think that this reactive streams lib is not intended to use in the way we want to use it here. However I would like you to change a few things in the code. |
build.sbt
Outdated
@@ -1258,7 +1258,8 @@ lazy val vertxServer: ProjectMatrix = (projectMatrix in file("server/vertx-serve | |||
.settings( | |||
name := "tapir-vertx-server", | |||
libraryDependencies ++= Seq( | |||
"io.vertx" % "vertx-web" % Versions.vertx | |||
"io.vertx" % "vertx-web" % Versions.vertx, | |||
"io.vertx" % "vertx-reactive-streams" % Versions.vertx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point I think it is not used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
trait VertxStreams extends Streams[VertxStreams] { | ||
override type BinaryStream = ReadStream[Buffer] | ||
override type Pipe[A, B] = Processor[A, B] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would go with ReadStream[A] => ReadStream[B] to not mix reactive streams and vertx streams
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
import sttp.tapir.tests.{Test, TestSuite} | ||
|
||
import scala.concurrent.ExecutionContext | ||
import scala.concurrent.{ExecutionContext, Future} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this and .asInstanceOf - change VertxTestServerInterpreter
to have VertxStreams
instead of any. You will also have to change route
contract in VertxTestServerBlockingInterpreter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -20,3 +21,10 @@ object ReadStreamCompatible { | |||
override def fromReadStream(s: ReadStream[Buffer]): Nothing = ??? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove incompatible - not needed anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Thanks! :) |
It would also be great to add a |
Following #2533 I gave it a try.
The change is backward compatible and people using
VertxFutureServerInterpreter
shouldn't have to change their endpoints, but if they want they can now use streaming.Using
Reactive Streams
rather thanVertx Streams
offers more flexibility. Any streaming library implementingreactivestreams.Publisher
can be used.So even
zio
,fs2
,akka-streams
etc can be used to handles streams inVertxFutureServerInterpreter
.I could successfully use this in this commit of my project
My endpoint type changed like this:
Using a
streamBody
give me:BaseEndpoint[Address, Publisher[Buffer]]
In my code I then used akka-streams to create a
Publisher
, but I could have used anything else.