How to use the grpc.Server function in grpc

To help you get started, we’ve selected a few grpc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github njpatel / grpcc / examples / example-server.js View on Github external
let grpc = require('grpc');
let proto = grpc.load(__dirname+"/../test/test.proto");
let grpcctest = proto.grpcctest;

let server = new grpc.Server();
server.addService(grpcctest.TestService.service, {
  sayHello: function sayHello(call, done) {
    log('sayHello()');
    log('Metadata', call.metadata);
    log('Request', call.request);

    // Send back the same metadata we received
    call.sendMetadata(call.metadata)
    done(null, { saidWhat: call.request.sayWhat });
  },

  sayClientStream: function sayClientStream(call, done) {
    log('sayClientStream()');
    log('Metadata', call.metadata);

    let agg = [];
github googlesamples / io2015-codelabs / gRPC / step-2-insert-books / server.js View on Github external
var grpc = require('grpc');

var booksProto = grpc.load('books.proto');

// In-memory array of book objects
var books = [{
    id: 123,
    title: 'A Tale of Two Cities',
    author: 'Charles Dickens'
}];

var server = new grpc.Server();
server.addProtoService(booksProto.books.BookService.service, {
    list: function(call, callback) {
        callback(null, books);
    },
    insert: function(call, callback) {
        books.push(call.request);
        callback(null, {});
    }
});

server.bind('127.0.0.1:50051', grpc.ServerCredentials.createInsecure());
server.start();
github muninrpc / muninrpc / app / __tests__ / grpc-server / grpc-server.ts View on Github external
export function getServer(): grpc.Server {
  const server = new grpc.Server();
  server.addService(todo_proto.ListActions.service, {
    GetList: GetList,
    AddItem: AddItem,
    ItemStreamer: ItemStreamer,
    CalculateAverage: CalculateAverage,
    TestServerStream: TestServerStream,
  });
  return server;
}
github agreatfool / SASDN / src / sample / server.ts View on Github external
function main() {
    let server = new grpc.Server();
    server.addService(BookService, {
        getBook: getBook,
        getBooksViaAuthor: getBooksViaAuthor,
        getGreatestBook: getGreatestBook,
        getBooks: getBooks
    });
    server.bind('127.0.0.1:50051', grpc.ServerCredentials.createInsecure());
    console.log('Listening on: 127.0.0.1:50051');
    server.start();
}
main();
github prisma / prisma-examples / node / grpc / server / server.js View on Github external
}

async function publish(call, callback) {
  const { id } = call.request
  try {
    const publishedPost = await prisma.updatePost({
      where: { id },
      data: { published: true },
    })
    callback(null, publishedPost)
  } catch (e) {
    callback(e, null)
  }
}

const server = new grpc.Server()
server.addService(blog.Blog.service, {
  feed,
  post,
  filterPosts,
  signupUser,
  createDraft,
  publish,
  deletePost,
})
server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure())
const message = `
The gRPC server is being started on ${chalk.bold(`0.0.0.0:50051`)}. You now can invoke any client script by its name, e.g.:

${chalk.bold(`$ npm run feed`)}
or
${chalk.bold(`$ npm run signupUser`)}
github rules-proto-grpc / rules_proto_grpc / nodejs / example / routeguide / server.js View on Github external
function getServer() {
  const server = new grpc.Server();
  server.addService(services.RouteGuideService, {
    getFeature: getFeature,
    listFeatures: listFeatures,
    recordRoute: recordRoute,
    routeChat: routeChat
  });
  return server;
}
github grpc / grpc-web / net / grpc / gateway / examples / helloworld / server.js View on Github external
function getServer() {
  var server = new grpc.Server();
  server.addService(helloworld.Greeter.service, {
    sayHello: doSayHello,
    sayRepeatHello: doSayRepeatHello,
    sayHelloAfterDelay: doSayHelloAfterDelay
  });
  return server;
}
github reimagined / resolve / examples / shopping-list / gRPC22222 / route_guide_server.js View on Github external
function getServer() {
  var server = new grpc.Server()
  server.addService(routeguide.RouteGuide.service, {
    getFeature: getFeature
  })
  return server
}
github pubref / rules_protobuf / examples / helloworld / node / greeter_server.js View on Github external
function main() {
  var server = new grpc.Server();
  server.addService(services.GreeterService, { sayHello: sayHello });
  server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
  server.start();
}