eleks.comeleks.com
RPC. part 2. My Project.
Using some patterns
Improve proto types for using them in
collections
- Add Empty message type for void input or output
parameters.
- Add some repeatable types for data collections.
- Improve Client and server to use those types
- Don’t forget to add “Google.Protobuf.Custom v3.0.0-beta”
reference to Client and Server
// The request message containing the user's name.
message stringRequest {
string str = 1;
}
// The response message containing User
message User {
int32 id = 1;
string name = 2;
string surname = 3;
}
// The response message containing the USERS
message UsersCollection {
repeated User users = 1;
}
message Empty {
}
Server side code sample
//private server field
Google.Protobuf.Collections.RepeatedField<User> users;
public Task<UsersCollection> GetUserByName(stringRequest request, ServerCallContext context)
{
var reply = new UsersCollection();
var enumerator = users.GetEnumerator();
do
{
if (enumerator.Current != null)
{
if (enumerator.Current.Name == request.Str)
{
reply.Users.Add(enumerator.Current);
}
}
} while (enumerator.MoveNext());
return Task.FromResult(reply);
}
Client side code sample
var users = client.GetUserByName(new stringRequest { Str = user }).Users;
var enumerator = users.GetEnumerator();
do
{
if (enumerator.Current != null)
{
//do smth with user element
}
}
while (enumerator.MoveNext());
Online Shop sample
Interfaces
Client:
- Order a good (returns order id, or 0)
- Cancel order (by order id)
- Get my orders
Server:
- Buy, Cancel handling
- Some internal logic
Lets CODE IT!
Server Internal Logic. How to
implement?
What is Template Method?
Can we use it here?
What to do, if need to switch between
RPC and non-RPC Server ?
Need to Adapt!
Real-Time Switching (Strategy)
To Learn From:
I Strongly Recommend this book for Patterns explanation:
“Freeman Er, Freeman El - design patterns”
(clear explanation, funny)
eleks.com
Thanks!
eleks.com
Inspired by Technology.
Driven by Value.

Improving rpc bkp

  • 1.
    eleks.comeleks.com RPC. part 2.My Project. Using some patterns
  • 2.
    Improve proto typesfor using them in collections - Add Empty message type for void input or output parameters. - Add some repeatable types for data collections. - Improve Client and server to use those types - Don’t forget to add “Google.Protobuf.Custom v3.0.0-beta” reference to Client and Server
  • 3.
    // The requestmessage containing the user's name. message stringRequest { string str = 1; } // The response message containing User message User { int32 id = 1; string name = 2; string surname = 3; } // The response message containing the USERS message UsersCollection { repeated User users = 1; } message Empty { }
  • 4.
    Server side codesample //private server field Google.Protobuf.Collections.RepeatedField<User> users; public Task<UsersCollection> GetUserByName(stringRequest request, ServerCallContext context) { var reply = new UsersCollection(); var enumerator = users.GetEnumerator(); do { if (enumerator.Current != null) { if (enumerator.Current.Name == request.Str) { reply.Users.Add(enumerator.Current); } } } while (enumerator.MoveNext()); return Task.FromResult(reply); }
  • 5.
    Client side codesample var users = client.GetUserByName(new stringRequest { Str = user }).Users; var enumerator = users.GetEnumerator(); do { if (enumerator.Current != null) { //do smth with user element } } while (enumerator.MoveNext());
  • 6.
  • 7.
    Interfaces Client: - Order agood (returns order id, or 0) - Cancel order (by order id) - Get my orders Server: - Buy, Cancel handling - Some internal logic
  • 8.
  • 9.
    Server Internal Logic.How to implement? What is Template Method? Can we use it here?
  • 10.
    What to do,if need to switch between RPC and non-RPC Server ? Need to Adapt! Real-Time Switching (Strategy)
  • 11.
    To Learn From: IStrongly Recommend this book for Patterns explanation: “Freeman Er, Freeman El - design patterns” (clear explanation, funny)
  • 12.
  • 13.