Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/coreyjs/grpc-cache-example
A ruby gRPC server that can store and retrieve files from memcache. A Go client to interact with the server
https://github.com/coreyjs/grpc-cache-example
example-project go golang grpc grpc-server learn learning memcache ruby tutorial
Last synced: 1 day ago
JSON representation
A ruby gRPC server that can store and retrieve files from memcache. A Go client to interact with the server
- Host: GitHub
- URL: https://github.com/coreyjs/grpc-cache-example
- Owner: coreyjs
- Created: 2020-07-23T01:13:14.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-11-22T00:01:29.000Z (almost 2 years ago)
- Last Synced: 2023-08-04T03:07:47.357Z (over 1 year ago)
- Topics: example-project, go, golang, grpc, grpc-server, learn, learning, memcache, ruby, tutorial
- Language: Ruby
- Homepage:
- Size: 48.9 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### This is an example project of connecting two distinct applications over gRPC.
The gRPC server is written in ruby, and can be ran from the main directory, `ruby ./server.rb`. This starts a gRPC server on port `50051`.
```ruby
class CacheHubServer
class << self
def start
start_grpc_server
endprivate
def start_grpc_server
puts 'cache hub server up'
@server = GRPC::RpcServer.new
@server.add_http2_port('0.0.0.0:50052', :this_port_is_insecure)
@server.handle(CacheHubService)
@server.run_till_terminated
end
end
end
```
---There are currently only 2 methods defined in the `cache.proto` file:
### StatusRequest
- Used for basic health check on the server### Upload
- Used as the main file transfer stream method```bash
service CacheHub {
rpc GetStatus(StatusRequest) returns (StatusResponse) {}
rpc Upload(stream Chunk) returns (UploadStatus) {}
}
```
---
### Client
The gRPC client in written in Go, and can be found in `/golang_client/`. You can interact with the client from the command line:```
> go run client.go -h
-a string
action to preform. status, get, store
-f string
file name
exit status 2
```### To store a file in memcache:
`> go run client.go -a=store -f=/path/to/file/myfile.pdf`
### To get a file from the cache:
`go run client.go -a=get -f=myfile.pdf`
`File Location: /tmp/myfile.pdf -- md5: 61e4b830ec5baea0fa9ff430e8ddcfa7% `
Note: this returns a file path location from the local system, for learning purposes only.---
### The Ruby FileHandler and CacheBroker classes
TODO: Documentation
---
### Misc Notes:To generate go client files:
`protoc -I ../protos ../protos/cache.proto --go_out=plugins=grpc:cache`
To generate ruby server files:
`grpc_tools_ruby_protoc -I protos --ruby_out=lib --grpc_out=lib protos/cache.proto`
To start ruby gRPC server:
`ruby ./server.rb`