Skip to content

Commit b50e5e5

Browse files
author
Jon Godbout
committed
Adding the server file as well as the asd file for gRPC hello world.
0 parents  commit b50e5e5

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

hello.proto

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Use of this source code is governed by an MIT-style
4+
// license that can be found in the LICENSE file or at
5+
// https://opensource.org/licenses/MIT.
6+
7+
syntax = "proto3";
8+
9+
message HelloRequest {
10+
optional string name = 1;
11+
}
12+
13+
message HelloReply {
14+
optional string message = 1;
15+
}
16+
17+
service HelloWorld {
18+
rpc SayHello(HelloRequest) returns (HelloReply) {}
19+
}

hw-grpc.asd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(defsystem :hw-grpc
2+
:author "Jonathan Godbout <[email protected]>"
3+
:description
4+
"Tutorial Program to go along with blog posts about using gRPC."
5+
:license "MIT"
6+
:defsystem-depends-on (:cl-protobufs.asdf)
7+
:depends-on (:cl-protobufs :grpc)
8+
:serial t
9+
:components ((:protobuf-source-file "hello")
10+
(:file "server")))

server.lisp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
;; Implement a gRPC server for Hellow World.
2+
3+
(defpackage #:grpc-server
4+
(:use #:cl)
5+
(:local-nicknames
6+
(#:hello-rpc #:cl-protobufs.hello-rpc)
7+
(#:hello #:cl-protobufs.hello)))
8+
9+
(in-package #:grpc-server)
10+
11+
;; A defgeneric is generated by protoc from the SayHello
12+
;; rpc line inside of the HellowWorld service in hello.proto.
13+
(defmethod hello-rpc:say-hello ((request hello:hello-request) rpc)
14+
;; The RPC contains useful data for more intricate requests.
15+
(declare (ignore rpc))
16+
(hello:make-hello-reply
17+
:message (concatenate 'string "Hello " (hello:hello-request.name request))))
18+
19+
(defconstant hostname "127.0.0.1" "Hostname for our server.")
20+
(defconstant port-number "8080" "Port for our server.")
21+
22+
(defun main ()
23+
;; Before we use gRPC we need to init-grpc, this sets up
24+
;; low-level gRPC internals.
25+
(grpc:init-grpc)
26+
;; This starts the server.
27+
(grpc::run-grpc-proto-server
28+
(concatenate 'string
29+
hostname ":"
30+
(write-to-string port-number))
31+
'hello:hello-world))

0 commit comments

Comments
 (0)