Skip to content
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

Support returning multiple streaming responses for a unary gRPC request #134

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

subnova
Copy link

@subnova subnova commented Jan 23, 2025

Support returning multiple streaming responses for a unary gRPC request.

Implementation

The JSON response is parsed into a JSON tree using Jackson's MappingIterator. Each JSON document is then mapped to a gRPC response as before and emitted using the gRPC stub response observer.

References

#55

Submitter checklist

  • Recommended: Join WireMock Slack to get any help in #help-contributing or a project-specific channel like #wiremock-java
  • The PR request is well described and justified, including the body and the references
  • The PR title represents the desired changelog entry
  • The repository's code style is followed (see the contributing guide)
  • Test coverage that demonstrates that the change works as expected
  • For new features, there's necessary documentation in this pull request or in a subsequent PR to wiremock.org

@tomakehurst
Copy link
Member

Thanks for contributing this. I'm going to hold off merging it though, as we plan to expand WireMock's core model for streaming/multi chunk responses and then utilise this for gRPC streaming.

@subnova
Copy link
Author

subnova commented Jan 26, 2025

Look forward to seeing a more complete solution - but this would be a useful stop-gap for those of us who desperately need this feature.

@tomakehurst
Copy link
Member

OK, that's fair enough, but let's find a way to enable this explicitly rather than it being the default behaviour when there's a streamed response defined.

I suggest adding a response definition transformer that's enabled per-stub, that sets a response header indicating this behaviour be enabled. So e.g. the transformer would add grpc-convert-response-body-array-to-stream:true to the headers, then there'd be an if block around the code you've already written that checks this is true.

@@ -50,6 +52,17 @@ public static GrpcResponseDefinitionBuilder message(MessageOrBuilder messageOrBu
return new GrpcResponseDefinitionBuilder(Status.OK).fromJson(json);
}

public static GrpcResponseDefinitionBuilder messages(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest adding an overload taking a vararg so that it's not necessary to put List.of(...) when calling.

List<MessageOrBuilder> messageOrBuilderList) {
final String json =
"[\n"
+ messageOrBuilderList.stream()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is serialising the whole list not possible?

Seems a bit messy to have to do string concat like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants