Improving rpc bkp

Preview:

Citation preview

eleks.com eleks.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 Usermessage User { int32 id = 1; string name = 2; string surname = 3;}

// The response message containing the USERSmessage UsersCollection { repeated User users = 1;}message Empty {}

Server side code sample//private server fieldGoogle.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

InterfacesClient:

- 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.