This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from nebula3.gclient.net import ConnectionPool | |
from nebula3.Config import Config | |
# define a config | |
config = Config() | |
config.max_connection_pool_size = 10 | |
# init connection pool | |
connection_pool = ConnectionPool() | |
# if the given servers are ok, return true, else return false | |
ok = connection_pool.init([('127.0.0.1', 9669)], config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import os | |
import grpc | |
from protos import hello_pb2, hello_pb2_grpc | |
def get_filepath(filename, extension): | |
return f'{filename}{extension}' | |
def read_iterfile(filepath, chunk_size=1024): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_filepath(filename, extension): | |
return f'{filename}{extension}' | |
def run(): | |
with grpc.insecure_channel('localhost:50051') as channel: | |
... | |
filename = 'test' | |
extension = '.jpg' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_iterfile(filepath, chunk_size=1024): | |
split_data = os.path.splitext(filepath) | |
filename = split_data[0] | |
extension = split_data[1] | |
metadata = hello_pb2.MetaData(filename=filename, extension=extension) | |
yield hello_pb2.UploadFileRequest(metadata=metadata) | |
with open(filepath, mode="rb") as f: | |
while True: | |
chunk = f.read(chunk_size) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from concurrent import futures | |
import logging | |
import os | |
import grpc | |
from protos import hello_pb2, hello_pb2_grpc | |
def get_filepath(filename, extension): | |
return f'{filename}{extension}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Greeter(hello_pb2_grpc.GreeterServicer): | |
def DownloadFile(self, request, context): | |
chunk_size = 1024 | |
filepath = f'{request.filename}{request.extension}' | |
if os.path.exists(filepath): | |
with open(filepath, mode="rb") as f: | |
while True: | |
chunk = f.read(chunk_size) | |
if chunk: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_filepath(filename, extension): | |
return f'{filename}{extension}' | |
class Greeter(hello_pb2_grpc.GreeterServicer): | |
.... | |
def UploadFile(self, request_iterator, context): | |
data = bytearray() | |
filepath = 'dummy' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syntax = "proto3"; | |
// The greeting service definition. | |
service Greeter { | |
// Sends a greeting | |
rpc SayHello (HelloRequest) returns (StringResponse) {} | |
// Uploads a file | |
rpc UploadFile(stream UploadFileRequest) returns (StringResponse) {} | |
// Downloads a file | |
rpc DownloadFile(MetaData) returns (stream FileResponse) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import os | |
import grpc | |
from protos import hello_pb2, hello_pb2_grpc | |
def run(): | |
with grpc.insecure_channel('localhost:50051') as channel: | |
stub = hello_pb2_grpc.GreeterStub(channel) | |
response = stub.SayHello(hello_pb2.HelloRequest(name='John Doe', age=30)) | |
print("Greeter client received: " + response.message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syntax = "proto3"; | |
// The greeting service definition. | |
service Greeter { | |
// Sends a greeting | |
rpc SayHello (HelloRequest) returns (StringResponse) {} | |
} | |
message HelloRequest { | |
string name = 1; |
NewerOlder