liveh2o / active_remote

Active Remote provides Active Record-like object-relational mapping over RPC. It's Active Record for your platform.
MIT License
63 stars 23 forks source link

Working example #84

Closed guilhermegazzinelli closed 3 years ago

guilhermegazzinelli commented 3 years ago

I'm working with an integration with Active_remote, do you have any sample or tutorial for the library?

I have a scenario running Gruf, and I implemented some abstraction to deal with "remote models". After that solution I found ActiveRemote gem, but I was unable to make it work.

The thing is, I am using GRUF, both server and client sides, to handle grpc calls, and I do need to make it work with Active_remote on the client.

My service is something like that

    require 'grpc'
    require 'app/proto/Clients_pb'

    module RemoteProto
      module Clients
        class Service

          include GRPC::GenericService

          self.marshal_class_method = :encode
          self.unmarshal_class_method = :decode
          self.service_name = 'remote_proto.Clients'

          rpc :Index, ::RemoteProto::IndexReq, stream(::RemoteProto::ClientModel)
          rpc :Show, ::RemoteProto::ShowReq, ::RemoteProto::ShowResp
        end

        Stub = Service.rpc_stub_class
      end
    end

and my proto is

    syntax = "proto3";

    import "AddressModel.proto";
    import "Filter.proto";

    package remote_proto;

    service Clients {
      rpc Index(IndexReq) returns (stream ClientModel) {}
      rpc Show(ShowReq) returns (ShowResp) { }
    }

    message ClientModel {
      uint32 id = 1;
      string name = 2;
      float price = 3;
      repeated Address addresses = 4;
    }

    message IndexReq {
      uint32 limit = 1;
      uint32 page = 2;
      Filter filter = 3;
    }

    message ShowReq {
      uint64 id = 1;
    }

    message ShowResp {
      ClientModel client = 1;
    }

Reading your lib, I think that I have to change the rpc_adapter, but I don have no idea how to work on that based on my service, or if I am right.

Is there where I really have to change? Do you have any sugestions? It would be awesome, trully, if you could share some similar working example

Note: BTW, I just started to work with RPC

Thanks a lot...

guilhermegazzinelli commented 3 years ago

I saw #38 but the structure compared to Gruf seems much more simpler, since the protobuf is more direct in methods and scopes for GRPC calls.

Do you see an easier path?

Thanks

film42 commented 3 years ago

Hey @guilhermegazzinelli . I'm not sure if we have a public example, but we use active remote very heavily at MX. One key thing is that the built-in rpc adapter is built around https://github.com/ruby-protobuf/protobuf . It supports protobuf v2. Google now has an official protobuf v3 ruby compiler, but that did not exist when we started. However, this lib should work with any adapter. Even http if you wanted to build it. If you're looking for something out of the box with minimal changes and you can use protobuf v2, consider the protobuf gem and this lib. If you're willing to sketch out an rpc adapter for whatever you're using in your current stack I'd love to review that PR! <3