-
Notifications
You must be signed in to change notification settings - Fork 420
Try gRPC Swift in Google Cloud Shell
Google Cloud Shell is a free and easy-to-use Linux shell that is available with every Google Cloud developer account. You can sign up for a free Google Cloud developer account here.
Note! Google Cloud Shell runs in a temporary virtual machine that shuts down when you sign out or are inactive. To get the hosting power of a full-time virtual machine, try gRPC-Swift in a Google Compute Engine VM.
Visit console.cloud.google.com and click on the small icon in the top bar that contains the console prompt (>_
). The Google Cloud Shell should open at the bottom of your browser window
(for details about Google Cloud Shell see the online documentation).
sudo apt-get update
sudo apt-get install -y clang clang-3.8 lldb-3.8 libicu-dev libtool \
libcurl4-openssl-dev libbsd-dev build-essential \
libssl-dev uuid-dev curl unzip
cd
mkdir -p local
export PATH=.:$HOME/local/bin:$PATH
source ~/.bashrc
SWIFT_URL=https://swift.org/builds/swift-4.0.3-release/ubuntu1404/swift-4.0.3-RELEASE/swift-4.0.3-RELEASE-ubuntu14.04.tar.gz
echo $SWIFT_URL
curl -fSsL $SWIFT_URL -o swift.tar.gz
tar -xzf swift.tar.gz --strip-components=2 --directory=local
PROTOC_URL=https://github.com/google/protobuf/releases/download/v3.4.0/protoc-3.4.0-linux-x86_64.zip
echo $PROTOC_URL
curl -fSsL $PROTOC_URL -o protoc.zip
unzip protoc.zip -d local
git clone https://github.com/grpc/grpc-swift
cd grpc-swift/Examples/Echo/PackageManager
make
.build/debug/Echo serve &
.build/debug/Echo get
.build/debug/Echo expand
.build/debug/Echo collect
.build/debug/Echo update
The four services that you've called demonstrate the four API modes of gRPC: Unary, Server Streaming, Client Streaming, and Bidirectional Streaming. See echo.proto for the service definition and main.swift and EchoProvider.swift for client and server implementations, respectively. As a gRPC user, that's all the code that you need to write! Everything else is in support libraries or generated by the Protocol Buffer and gRPC plugins.