Skip to content

Instantly share code, notes, and snippets.

@yang-g
yang-g / greeter_async_server.cc
Created March 17, 2017 22:26
grpc async server toy example
// Class encompasing the state and logic needed to serve a request.
class CallDataBase {
public:
// Take in the "service" instance (in this case representing an asynchronous
// server) and the completion queue "cq" used for asynchronous communication
// with the gRPC runtime.
CallDataBase(Greeter::AsyncService* service, ServerCompletionQueue* cq)
: service_(service), cq_(cq), status_(PROCESS) {}
virtual ~CallDataBase() {}
@yang-g
yang-g / ciena_server.cc
Last active February 2, 2016 19:15
example grpc ciena server
// Code sample. May need minor fixes to compile.
// Create a sync service handling class
class OpenConfigImpl : public openconfigs::OpenConfig::Service {
public:
::grpc::Status::Subscribe(::grpc::ServerContext* context, ::grpc::ServerReaderWriter<SubscribeResponse, SubscribeRequest>* stream) override;
::grpc::Status::Set(::grpc::ServerContext* context, ::grpc::ServerReaderWriter<SetResponse, SetRequest>* stream) override;
// Get will be handled async.
};
@yang-g
yang-g / gist:257d758cdb990eec42f8
Last active March 21, 2020 00:31
grpc pubsub c++ example
#include <iostream>
#include <grpc++/grpc++.h>
#include <grpc++/security/credentials.h>
#include "pubsub.grpc.pb.h"
int main(int argc, char** argv) {
auto channel = grpc::CreateChannel(“pubsub.googleapis.com”, grpc::GoogleDefaultCredentials());