Borg
(gerenciamento de containers)
Borg
(gerenciamento de containers)
Stubby
(comunicação)
Borg
(gerenciamento de containers)
Stubby
(comunicação)
Borg
(gerenciamento de containers)
Stubby
(comunicação)
Borg
(gerenciamento de containers)
Stubby
(comunicação)
Borg
(gerenciamento de containers)
Stubby
(comunicação)
Sistema de comunicação client-server
Sistema de comunicação client-server
Cliente chama função normalmente, mas ela é executada remotamente, em outra máquina
Sistema de comunicação client-server
Cliente chama função normalmente, mas ela é executada remotamente, em outra máquina
Tem suas origens nos anos 70, mas vem tendo um forte come-back por conta do conceito de microsserviços
"out of the box"
(pense como sendo o JSON da interação HTTP + JSON)
message MyMessage {
string first_name = 1;
bool is_validated = 2;
}message MyMessage {
string first_name = 1;
bool is_validated = 2;
}Varints
message MyMessage {
string first_name = 1;
bool is_validated = 2;
}Varints
são a "key" do mapa "key-value"
{
"last_name": "dasylva"
}{
"last_name": "dasylva"
}9 bytes
+ 7 bytes
message MyMessage {
string last_name = 2;
}message MyMessage {
string last_name = 2;
}mensagem encodada com "dasylva" vira isso:
12 07 64 61 73 79 6c 76 61
message MyMessage {
string last_name = 2;
}mensagem encodada com "dasylva" vira isso:
12 07 64 61 73 79 6c 76 61
0x12 = field 2, tipo 2 (tipo variável)
o 0x07 ao lado significa que o tamanho variável é 7
message MyMessage {
string last_name = 2;
}Protocol buffers are now Google's lingua franca for data – at time of writing, there are 306,747 different message types defined in the Google code tree across 348,952 .proto files. They're used both in RPC systems and for persistent storage of data in a variety of storage systems.
meu_protinho.proto
syntax = "proto3";
package kotlinconf;
syntax = "proto3";
package kotlinconf;
message Atendee {
string first_name = 1;
string last_name = 2;
int32 meetups_atended = 3;
bool is_cool_person = 4;
}
syntax = "proto3";
package kotlinconf;
message Atendee {
string first_name = 1;
string last_name = 2;
int32 meetups_atended = 3;
bool is_cool_person = 4;
}
service KotlinConfService {
}
syntax = "proto3";
package kotlinconf;
message Atendee {
string first_name = 1;
string last_name = 2;
int32 meetups_atended = 3;
bool is_cool_person = 4;
}
service KotlinConfService {
rpc getKotlinConfAtendees() returns ();
}
syntax = "proto3";
package kotlinconf;
message Atendee {
string first_name = 1;
string last_name = 2;
int32 meetups_atended = 3;
bool is_cool_person = 4;
}
service KotlinConfService {
rpc getKotlinConfAtendees(Input) returns (Output);
}
syntax = "proto3";
package kotlinconf;
message Atendee {
string first_name = 1;
string last_name = 2;
int32 meetups_atended = 3;
bool is_cool_person = 4;
}
service KotlinConfService {
rpc getKotlinConfAtendees(Input) returns (Output);
}
message Input {
int32 year = 1;
}
syntax = "proto3";
package kotlinconf;
message Atendee {
string first_name = 1;
string last_name = 2;
int32 meetups_atended = 3;
bool is_cool_person = 4;
}
service KotlinConfService {
rpc getKotlinConfAtendees(Input) returns (Output);
}
message Input {
int32 year = 1;
}
message Output {
Atendee atendees = 1;
}
syntax = "proto3";
package kotlinconf;
message Atendee {
string first_name = 1;
string last_name = 2;
int32 meetups_atended = 3;
bool is_cool_person = 4;
}
service KotlinConfService {
rpc getKotlinConfAtendees(Input) returns (Output);
}
message Input {
int32 year = 1;
}
message Output {
repeated Atendee atendees = 1;
}
protoc \
--java_out=src/main/kotlin \
--proto_path=src/main/proto \
kotlinconf.protoservice KotlinConfService {
rpc getKotlinConfAtendees(Input) returns (Output);
} class KService {}
class KService:
KotlinConfServiceGrpc.KotlinConfServiceImplBase() {
}
class KService:
KotlinConfServiceGrpc.KotlinConfServiceImplBase() {
// alt enter pra dar override automático
}
class KService:
KotlinConfServiceGrpc.KotlinConfServiceImplBase() {
override fun getKotlinConfAtendees(
request: Kotlinconf.Input?,
responseObserver: StreamObserver<Kotlinconf.Output>?
) {
super.getKotlinConfAtendees(request, responseObserver)
}
}
class KService:
KotlinConfServiceGrpc.KotlinConfServiceImplBase() {
override fun getKotlinConfAtendees(
request: Kotlinconf.Input?,
responseObserver: StreamObserver<Kotlinconf.Output>?
) {
}
}
class KService:
KotlinConfServiceGrpc.KotlinConfServiceImplBase() {
override fun getKotlinConfAtendees(
request: Kotlinconf.Input?,
responseObserver: StreamObserver<Kotlinconf.Output>?
) {
val year = request?.year ?: getCurrentYear()
}
}
class KService:
KotlinConfServiceGrpc.KotlinConfServiceImplBase() {
override fun getKotlinConfAtendees(
request: Kotlinconf.Input?,
responseObserver: StreamObserver<Kotlinconf.Output>?
) {
val year = request?.year ?: getCurrentYear()
// List<AtendeeEntity>
val atendees = KConfUseCase(year)
}
}
class KService:
KotlinConfServiceGrpc.KotlinConfServiceImplBase() {
override fun getKotlinConfAtendees(
request: Kotlinconf.Input?,
responseObserver: StreamObserver<Kotlinconf.Output>?
) {
val year = request?.year ?: getCurrentYear()
// List<AtendeeEntity>
val atendees = KConfUseCase(year)
val listOfAtendees = atendees.map {
Kotlinconf.Atendee.newBuilder()
.setFirstName(it.FirstName)
.setLastName(it.LastName)
.setMeetupsAtended(it.MeetupsAttended)
.setIsCoolPerson(it.IsCool)
.build()
}.toList()
}
}
class KService:
KotlinConfServiceGrpc.KotlinConfServiceImplBase() {
override fun getKotlinConfAtendees(
request: Kotlinconf.Input?,
responseObserver: StreamObserver<Kotlinconf.Output>?
) {
val year = request?.year ?: getCurrentYear()
// List<AtendeeEntity>
val atendees = KConfUseCase(year)
val listOfAtendees = atendees.map {
//map entities...
}.toList()
}
}
class KService:
KotlinConfServiceGrpc.KotlinConfServiceImplBase() {
override fun getKotlinConfAtendees(
request: Kotlinconf.Input?,
responseObserver: StreamObserver<Kotlinconf.Output>?
) {
val year = request?.year ?: getCurrentYear()
// List<AtendeeEntity>
val atendees = KConfUseCase(year)
val listOfAtendees = atendees.map {
//map entities...
}.toList()
val response = Kotlinconf
.Output.newBuilder()
}
}
class KService:
KotlinConfServiceGrpc.KotlinConfServiceImplBase() {
override fun getKotlinConfAtendees(
request: Kotlinconf.Input?,
responseObserver: StreamObserver<Kotlinconf.Output>?
) {
val year = request?.year ?: getCurrentYear()
// List<AtendeeEntity>
val atendees = KConfUseCase(year)
val listOfAtendees = atendees.map {
//map entities...
}.toList()
val response = Kotlinconf
.Output.newBuilder()
.addAllAtendees(listOfAtendees)
}
}
class KService:
KotlinConfServiceGrpc.KotlinConfServiceImplBase() {
override fun getKotlinConfAtendees(
request: Kotlinconf.Input?,
responseObserver: StreamObserver<Kotlinconf.Output>?
) {
val year = request?.year ?: getCurrentYear()
// List<AtendeeEntity>
val atendees = KConfUseCase(year)
val listOfAtendees = atendees.map {
//map entities...
}.toList()
val response = Kotlinconf
.Output.newBuilder()
.addAllAtendees(listOfAtendees)
responseObserver?.onNext(response.build())
responseObserver?.onCompleted()
}
}
fun main() {
}
import io.grpc.ServerBuilder
fun main() {
val s = ServerBuilder
}
import io.grpc.ServerBuilder
fun main() {
val s = ServerBuilder
.forPort(8080)
}
import io.grpc.ServerBuilder
fun main() {
val kService = KService()
val s = ServerBuilder
.forPort(8080)
.addService(kService)
.build()
}
import io.grpc.ServerBuilder
fun main() {
val kService = KService()
val s = ServerBuilder
.forPort(8080)
.addService(kService)
.build()
println("starting server")
s.start().awaitTermination()
}
fun main() {
}
import io.grpc.ManagedChannelBuilder
fun main() {
var channel = ManagedChannelBuilder
.forAddress("localhost", 8080)
.usePlaintext()
.build()
}
import io.grpc.ManagedChannelBuilder
fun main() {
var channel = ManagedChannelBuilder
.forAddress("localhost", 8080)
.usePlaintext()
.build()
var stub = KotlinConfServiceGrpc
.newBlockingStub(channel)
}
import io.grpc.ManagedChannelBuilder
fun main() {
var channel = ManagedChannelBuilder
.forAddress("localhost", 8080)
.usePlaintext()
.build()
var stub = KotlinConfServiceGrpc
.newBlockingStub(channel)
val input = Kotlinconf
.Input.newBuilder()
.setYear(2019)
.build()
val response = stub.getKotlinConfAtendees(input)
println("got response $response")
}
*no processo de serialization e deserialization