forked from thesamet/rpcz
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
226 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
include(library_suffix) | ||
include(ExternalProject) | ||
|
||
# Install GFlags | ||
ExternalProject_Add( | ||
GFlagsLib | ||
URL http://google-gflags.googlecode.com/files/gflags-1.7.tar.gz | ||
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> | ||
) | ||
ExternalProject_Get_Property(GFlagsLib install_dir) | ||
include_directories(${install_dir}/include) | ||
set(GFLAGS_LIBRARIES ${install_dir}/lib/libgflags.${link_library_suffix}) | ||
set(GFLAGS_PREFIX ${install_dir}) | ||
|
||
# Install GLog | ||
ExternalProject_Add( | ||
GLogLib | ||
URL http://google-glog.googlecode.com/files/glog-0.3.1-1.tar.gz | ||
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> --with-gflags=${GFLAGS_PREFIX} | ||
) | ||
ExternalProject_Get_Property(GLogLib install_dir) | ||
include_directories(${install_dir}/include) | ||
set(GLOG_LIBRARIES ${install_dir}/lib/libglog.${link_library_suffix}) | ||
|
||
# Install ZeroMQ | ||
ExternalProject_Add( | ||
ZeroMQ | ||
URL http://download.zeromq.org/zeromq-2.1.11.tar.gz | ||
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> --with-gflags=${GFLAGS_PREFIX} | ||
) | ||
ExternalProject_Get_Property(ZeroMQ install_dir) | ||
include_directories(${install_dir}/include) | ||
set(ZEROMQ_LIBRARIES ${install_dir}/lib/libzmq.${link_library_suffix}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
include(zrpc_functions) | ||
find_package(ProtobufPlugin REQUIRED) | ||
PROTOBUF_GENERATE_CPP(SEARCH_PB_SRCS SEARCH_PB_HDRS search.proto) | ||
PROTOBUF_GENERATE_ZRPC(SEARCH_ZRPC_SRCS SEARCH_ZRPC_HDRS search.proto) | ||
|
||
add_library(example_pb ${SEARCH_PB_SRCS} ${SEARCH_PB_HDRS} ${SEARCH_ZRPC_SRCS} | ||
${SEARCH_ZRPC_HDRS}) | ||
target_link_libraries(example_pb ${PROTOBUF_LIBRARY}) | ||
include_directories(${PROJECT_BINARY_DIR}/examples) | ||
|
||
add_executable(example_client example_client.cc) | ||
target_link_libraries(example_client zrpc example_pb) | ||
|
||
add_executable(example_server example_server.cc) | ||
target_link_libraries(example_server zrpc example_pb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2011 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Author: [email protected] <Nadav Samet> | ||
|
||
#include <ostream> | ||
#include "zrpc/zrpc.h" | ||
#include "glog/logging.h" | ||
#include "search.pb.h" | ||
#include "search.zrpc.h" | ||
|
||
int main() { | ||
zrpc::Application application; | ||
examples::SearchService_Stub search_stub(application.CreateRpcChannel( | ||
"tcp://localhost:5555"), true); | ||
examples::SearchRequest request; | ||
examples::SearchResponse response; | ||
request.set_query("gold"); | ||
|
||
zrpc::RPC rpc; | ||
rpc.SetDeadlineMs(1000); // 1 second | ||
std::cout << "Sending request." << std::endl; | ||
search_stub.Search(&rpc, &request, &response, NULL); | ||
|
||
rpc.Wait(); | ||
std::cout << "Response status: " | ||
<< zrpc::GenericRPCResponse::Status_Name(rpc.GetStatus()) | ||
<< std::endl; | ||
if (rpc.OK()) { | ||
std::cout << response.DebugString() << std::endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2011 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Author: [email protected] <Nadav Samet> | ||
|
||
#include <iostream> | ||
#include "zrpc/zrpc.h" | ||
#include "search.pb.h" | ||
#include "search.zrpc.h" | ||
|
||
namespace examples { | ||
class SearchServiceImpl : public SearchService { | ||
|
||
virtual void Search( | ||
zrpc::RPC* rpc, const SearchRequest* request, | ||
SearchResponse* response, zrpc::Closure* done) { | ||
std::cout << "Got request for '" << request->query() << "'" << std::endl; | ||
response->add_results("result1 for " + request->query()); | ||
response->add_results("this is result2"); | ||
done->Run(); | ||
} | ||
}; | ||
} // namespace examples | ||
|
||
int main() { | ||
zrpc::Application application; | ||
zrpc::Server* server = application.CreateServer("tcp://*:5555"); | ||
examples::SearchServiceImpl search_service; | ||
server->RegisterService(&search_service); | ||
std::cout << "Serving requests on port 5555." << std::endl; | ||
server->Start(); | ||
delete server; | ||
std::cout << "Terminating!" << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package examples; | ||
|
||
message SearchRequest { | ||
required string query = 1; | ||
optional int32 page_number = 2 [default = 1]; | ||
} | ||
|
||
message SearchResponse { | ||
repeated string results = 1; | ||
} | ||
|
||
service SearchService { | ||
rpc Search(SearchRequest) returns(SearchResponse); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2011 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Author: [email protected] <Nadav Samet> | ||
|
||
#ifndef ZRPC_ZRPC_H | ||
#define ZRPC_ZRPC_H | ||
|
||
// Master include file | ||
#include "zrpc/application.h" | ||
#include "zrpc/callback.h" | ||
#include "zrpc/connection_manager.h" | ||
#include "zrpc/event_manager.h" | ||
#include "zrpc/macros.h" | ||
#include "zrpc/rpc.h" | ||
#include "zrpc/rpc_channel.h" | ||
#include "zrpc/server.h" | ||
#include "zrpc/service.h" | ||
#include "zrpc/sync_event.h" | ||
#include "zrpc/zmq_utils.h" | ||
|
||
// Two include files were intentionally left out since they rely on ZeroMQ | ||
// headers being around and probably most people will not need this low-level | ||
// functionality. These files are: | ||
// zmq_utils.h | ||
// remote_response.h | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters