SlideShare una empresa de Scribd logo
1 de 54
Descargar para leer sin conexión
RG-DEV #14
MICHAŁ KRUCZEK
So ware Engineer & PHP Developer since 2010
bass guitarist and trumpeter
kruczek.it
Created by /Michał Kruczek @partikus
GRPC
HOW TO COMMUNICATE EFFECTIVELY?
AGENDA
Intro
The RPC story
gRPC
Demo
EFFECTIVE
COMMUNICATION
A two way information sharing process which
involves one party sending a message that is
easily understood by the receiving party.
Accounting
Boss
Employees
Warehouse
Store
Invoices
Reports
Warehouse
Order
InvoiceFactory
NotificationService
THE RPC STORY
~1970 - RPC
~1980 - IMPLEMENTATION
~1990 - OOP & CORBA
WHAT'S RPC?
Remote Procedure Call (RPC) is a protocol that
one program can use to request a service from
a program located in another computer on a
network without having to understand the
network's details. A procedure call is also
sometimes known as a function call or a
subroutine call.
WHY RPC?
WRAPS NETWORKS INTERACTIONS
FLEXIBLE & MAINTAINABLE
EASY TO DEVELOP
DISTRIBUTED SYSTEMS
RPC'S DICTIONARY
STUBS
A stub in distributed computing is a piece of
code that converts parameters passed
between client and server during a remote
procedure call (RPC).
IDL
INTERFACE DEFINITION LANGUAGE
IDL is a specification language used to
describe a so ware component's application
programming interface (API)
CHALLANGE
PHP
GO
PYTHONJAVA
CONTRACT
CLIENTS' IMPLEMENTATIONS
SERVERS' STUBS
PERFORMANCE
GRPC
A HIGH PERFORMANCE,
OPEN-SOURCE UNIVERSAL RPC FRAMEWORK
WHY WOULD I WANT TO
USE GRPC?
LOW LATENCY, HIGHLY SCALABLE, DISTRIBUTED SYSTEMS.
DEVELOPING MOBILE CLIENTS WHICH ARE COMMUNICATING
TO A CLOUD SERVER.
DESIGNING A NEW PROTOCOL THAT NEEDS TO BE ACCURATE,
EFFICIENT AND LANGUAGE INDEPENDENT.
LAYERED DESIGN TO ENABLE EXTENSION EG.
AUTHENTICATION, LOAD BALANCING, LOGGING AND
MONITORING ETC.
HTTP/2
WHAT ARE THE KEY DIFFERENCES TO
HTTP/1.X?
IS BINARY, INSTEAD OF TEXTUAL
IS FULLY MULTIPLEXED, INSTEAD OF ORDERED AND BLOCKING
CAN THEREFORE USE ONE CONNECTION FOR PARALLELISM
USES HEADER COMPRESSION TO REDUCE OVERHEAD
ALLOWS SERVERS TO “PUSH” RESPONSES PROACTIVELY INTO
CLIENT CACHES
PROTOCOL BUFFERS
AS THE IDL
syntax = "proto3";
package Kruczek.RgDev.Twitter;
enum ResultType {
MIXED = 0;
RECENT = 1;
POPULAR = 2;
}
message Query {
string q = 1;
string since = 2;
int32 count = 3;
string lang = 4;
ResultType type = 5;
repeated string tracks = 6;
repeated string follows = 7;
...
message Author {
string id = 1;
string name = 2;
string screenName = 3;
string avatar = 4;
}
message Tweet {
string id = 1;
string text = 2;
Author author = 3;
int32 retweetCount = 4;
int32 favoriteCount = 5;
}
SERVICE METHODS' TYPES
UNARY RPC
rpc SayHello(HelloRequest)
returns (HelloResponse) { }
SERVER STREAMING RPC
rpc LotsOfReplies(HelloRequest)
returns (stream HelloResponse) { }
CLIENT STREAMING RPC
rpc LotsOfGreetings(stream HelloRequest)
returns (HelloResponse) { }
BIDIRECTIONAL STREAMING RPC
rpc BidiHello(stream HelloRequest)
returns (stream HelloResponse) { }
PROS
IDIOMATIC CLIENT LIBRARIES IN 10 LANGUAGES
HIGHLY EFFICIENT ON WIRE AND WITH A SIMPLE SERVICE
DEFINITION FRAMEWORK
BI-DIRECTIONAL STREAMING WITH HTTP/2 BASED TRANSPORT
PLUGGABLE AUTH, TRACING, LOAD BALANCING AND HEALTH
CHECKING
CONS
MISSING PHP SERVER
MISSING OFFICIAL JS-WEB CLIENT
DEMO APP
TWITTER LIVE STREAMING
LET'S DEFINE A CONTRACT
syntax = "proto3";
package Kruczek.RgDev.Twitter;
service TwitterBoard {
rpc GetTweets(Query) returns (stream Tweet) {}
}
...
GENERATE PHP CLIENT
#!/usr/bin/env bash
set -ex
php_output="php/grpc"
rm -rf "$php_output" && mkdir -p "$php_output"
protoc 
--php_out="$php_output" 
--grpc_out="$php_output" 
--plugin=protoc-gen-grpc=/usr/local/bin/grpc_php_plugin 
twitter.proto
GENERATE NODEJS SERVER
#!/usr/bin/env bash
nodejs_output="nodejs/grpc"
rm -rf "$nodejs_output" && mkdir -p "$nodejs_output"
protoc 
--js_out="import_style=commonjs,binary:$nodejs_output" 
--grpc_out="$nodejs_output" 
--plugin=protoc-gen-grpc=/usr/local/bin/grpc_node_plugin 
twitter.proto
NODEJS SERVER THAT USES REST API
import grpc from "grpc";
import twitter from "twitter";
import twitterService from "./../server/twitter.service";
import services from "./../grpc/twitter_grpc_pb";
const client = new twitter(credentials);
const service = new twitterService(client);
function main() {
const server = new grpc.Server();
server.addService(services.TwitterBoardService, service);
server.bind('0.0.0.0:50052', grpc.ServerCredentials.createInsecure())
server.start();
}
main();
NODEJS SERVER THAT USES TWITTER
STREAMING
ANOTHER SERVICE IMPEMENTATION
...
import twitterService from "./../server/streamTwitter.service";
...
<?php
class Client
{
private $client;
public function __construct(string $hostname)
{
$this->client = new TwitterBoardClient($hostname, ['credentials' =
}
}
/**
* @param Query $query
* @return Generator|Tweet[]
*/
public function getTweets(Query $query): Generator
{
/** @var ServerStreamingCall $response */
$response = $this->client->GetTweets($query);
foreach ($response->responses() as $response) {
yield $response;
}
}
LIVE DEMO
LET'S TWEETS ;-)
QUESTIONS?
SLIDES: SLIDESHARE.NET/MICHASZCZUR
TWITTER: @PARTIKUS
HOMEPAGE: KRUCZEK.IT
THANKS!
LINKS
github.com/partikus/grpc-example
grpc.io
developers.google.com/protocol-buffers

Más contenido relacionado

Similar a gRPC - czyli jak skutecznie rozmawiać (rg-dev#14)

[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...
[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...
[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...CODE BLUE
 
REST vs gRPC: Battle of API's
REST vs gRPC: Battle of API'sREST vs gRPC: Battle of API's
REST vs gRPC: Battle of API'sLuram Archanjo
 
Distributes objects and Rmi
Distributes objects and RmiDistributes objects and Rmi
Distributes objects and RmiMayank Jain
 
gRPC Design and Implementation
gRPC Design and ImplementationgRPC Design and Implementation
gRPC Design and ImplementationVarun Talwar
 
Microservices Communication Patterns with gRPC
Microservices Communication Patterns with gRPCMicroservices Communication Patterns with gRPC
Microservices Communication Patterns with gRPCWSO2
 
Remote procedure calls
Remote procedure callsRemote procedure calls
Remote procedure callsimnomus
 
remote procedure calls
  remote procedure calls  remote procedure calls
remote procedure callsAshish Kumar
 
CocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIsCocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIsTim Burks
 
Introduction to C++ Remote Procedure Call (RPC)
Introduction to C++ Remote Procedure Call (RPC)Introduction to C++ Remote Procedure Call (RPC)
Introduction to C++ Remote Procedure Call (RPC)Abdelrahman Al-Ogail
 
Remote Procedure Call
Remote Procedure CallRemote Procedure Call
Remote Procedure CallNadia Nahar
 
Dos(rpc)avishek130650107020
Dos(rpc)avishek130650107020Dos(rpc)avishek130650107020
Dos(rpc)avishek130650107020Avishek Sarkar
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure callSunita Sahu
 

Similar a gRPC - czyli jak skutecznie rozmawiać (rg-dev#14) (20)

[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...
[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...
[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...
 
REST vs gRPC: Battle of API's
REST vs gRPC: Battle of API'sREST vs gRPC: Battle of API's
REST vs gRPC: Battle of API's
 
Distributes objects and Rmi
Distributes objects and RmiDistributes objects and Rmi
Distributes objects and Rmi
 
gRPC Design and Implementation
gRPC Design and ImplementationgRPC Design and Implementation
gRPC Design and Implementation
 
Microservices Communication Patterns with gRPC
Microservices Communication Patterns with gRPCMicroservices Communication Patterns with gRPC
Microservices Communication Patterns with gRPC
 
Remote procedure calls
Remote procedure callsRemote procedure calls
Remote procedure calls
 
remote procedure calls
  remote procedure calls  remote procedure calls
remote procedure calls
 
Lecture9
Lecture9Lecture9
Lecture9
 
CocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIsCocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIs
 
Introduction to C++ Remote Procedure Call (RPC)
Introduction to C++ Remote Procedure Call (RPC)Introduction to C++ Remote Procedure Call (RPC)
Introduction to C++ Remote Procedure Call (RPC)
 
Remote Procedure Call
Remote Procedure CallRemote Procedure Call
Remote Procedure Call
 
gRPC services testing
gRPC services testinggRPC services testing
gRPC services testing
 
abu.rpc intro
abu.rpc introabu.rpc intro
abu.rpc intro
 
Rpc
RpcRpc
Rpc
 
GRPC.pptx
GRPC.pptxGRPC.pptx
GRPC.pptx
 
Well known protocols port numbers
Well known  protocols port numbersWell known  protocols port numbers
Well known protocols port numbers
 
Apa itu gRPC_.pptx
Apa itu gRPC_.pptxApa itu gRPC_.pptx
Apa itu gRPC_.pptx
 
Remote procedure call
Remote procedure callRemote procedure call
Remote procedure call
 
Dos(rpc)avishek130650107020
Dos(rpc)avishek130650107020Dos(rpc)avishek130650107020
Dos(rpc)avishek130650107020
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure call
 

Último

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptJasonTagapanGulla
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the weldingMuhammadUzairLiaqat
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 

Último (20)

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.ppt
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the welding
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 

gRPC - czyli jak skutecznie rozmawiać (rg-dev#14)