lidavidm commented on a change in pull request #153:
URL: https://github.com/apache/arrow-cookbook/pull/153#discussion_r814199232
##########
File path: cpp/code/flight.cc
##########
@@ -291,4 +307,99 @@ arrow::Status TestPutGetDelete() {
return arrow::Status::OK();
}
+arrow::Status TestClientOptions() {
+ // Set up server as usual
+ auto fs = std::make_shared<arrow::fs::LocalFileSystem>();
+ ARROW_RETURN_NOT_OK(fs->CreateDir("./flight_datasets/"));
+ ARROW_RETURN_NOT_OK(fs->DeleteDirContents("./flight_datasets/"));
+ auto root =
std::make_shared<arrow::fs::SubTreeFileSystem>("./flight_datasets/", fs);
+
+ arrow::flight::Location server_location;
+ ARROW_RETURN_NOT_OK(
+ arrow::flight::Location::ForGrpcTcp("0.0.0.0", 0, &server_location));
+
+ arrow::flight::FlightServerOptions options(server_location);
+ auto server = std::unique_ptr<arrow::flight::FlightServerBase>(
+ new ParquetStorageService(std::move(root)));
+ ARROW_RETURN_NOT_OK(server->Init(options));
+
+ StartRecipe("TestClientOptions::Connect");
+ auto client_options = arrow::flight::FlightClientOptions::Defaults();
+ // Set a very low limit at the gRPC layer to fail all calls
+
client_options.generic_options.emplace_back(GRPC_ARG_MAX_SEND_MESSAGE_LENGTH,
2);
+
+ arrow::flight::Location location;
+ ARROW_RETURN_NOT_OK(
+ arrow::flight::Location::ForGrpcTcp("localhost", server->port(),
&location));
+
+ std::unique_ptr<arrow::flight::FlightClient> client;
+ ARROW_RETURN_NOT_OK( // pass client_options into Connect()
+ arrow::flight::FlightClient::Connect(location, client_options, &client));
+ rout << "Connected to " << location.ToString() << std::endl;
+ EndRecipe("TestClientOptions::Connect");
+
+ auto descriptor =
arrow::flight::FlightDescriptor::Path({"airquality.parquet"});
+ std::unique_ptr<arrow::flight::FlightInfo> flight_info;
+ return client->GetFlightInfo(descriptor, &flight_info);
+}
+
+arrow::Status TestCustomGrpcImpl() {
+ StartRecipe("CustomGrpcImpl::StartServer");
+ // Build flight service as usual
+ auto fs = std::make_shared<arrow::fs::LocalFileSystem>();
+ ARROW_RETURN_NOT_OK(fs->CreateDir("./flight_datasets/"));
+ ARROW_RETURN_NOT_OK(fs->DeleteDirContents("./flight_datasets/"));
+ auto root =
std::make_shared<arrow::fs::SubTreeFileSystem>("./flight_datasets/", fs);
+
+ arrow::flight::Location server_location;
+ ARROW_RETURN_NOT_OK(
+ arrow::flight::Location::ForGrpcTcp("0.0.0.0", 3000, &server_location));
+
+ arrow::flight::FlightServerOptions options(server_location);
+ auto server = std::unique_ptr<arrow::flight::FlightServerBase>(
+ new ParquetStorageService(std::move(root)));
+
+ // Create hello world service
+ HelloWorldServiceImpl grpc_service;
+ // Both services will be available on both ports
+ int hello_world_port;
+
+ options.builder_hook = [&](void* raw_builder) {
+ auto* builder = reinterpret_cast<grpc::ServerBuilder*>(raw_builder);
+ builder->AddListeningPort("0.0.0.0:5000",
grpc::InsecureServerCredentials(),
+ &hello_world_port);
Review comment:
Hmm, maybe we cut the extra port from this recipe (and slim it down a
bit)? The important part is registering the second service
##########
File path: cpp/source/flight.rst
##########
@@ -83,3 +83,72 @@ Finally, we'll stop our server:
.. recipe:: ../code/flight.cc ParquetStorageService::StopServer
:dedent: 2
+
+
+Setting gRPC client options
+===========================
+
+Options for gRPC clients can be passed in using the ``generic_options`` field
of
+:cpp:class:`arrow::flight::FlightClientOptions`. There is a list of available
+client options in the `gRPC API documentation
<https://grpc.github.io/grpc/cpp/group__grpc__arg__keys.html>`_.
+
+For example, you can change the maximum message length sent with:
+
+.. recipe:: ../code/flight.cc TestClientOptions::Connect
+ :dedent: 2
+
+
+Flight Service with other gRPC endpoints
+========================================
+
+If you are using the gRPC backend, you can add other gRPC endpoints to the
+flight server. While Flight clients won't recognize these endpoints, general
Review comment:
```suggestion
Flight server. While Flight clients won't recognize these endpoints, general
```
##########
File path: cpp/code/CMakeLists.txt
##########
@@ -13,12 +13,21 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_CLANG_TIDY "clang-tidy")
endif()
+# Add protobuf
+find_package(Protobuf REQUIRED)
+find_package(gRPC CONFIG REQUIRED)
+find_package(Threads)
+
+set(PROTO_FILES
+ protos/helloworld.proto
+)
+
# Create test targets
enable_testing()
include(GoogleTest)
-function(RECIPE TARGET)
+function(RECIPE TARGET COMPILE_PROTOS)
Review comment:
This is probably good enough for now and maybe we can add keyword
arguments eventually.
Though, would it work to just drop
```
target_link_libraries(flight ...)
...
protobuf_generate(TARGET flight LANGUAGE ...)
...
```
below without adding a parameter?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]