The Active RPC
ActiveRpc
ActiveRecord associations for gRPC services.
Quick start
class Employee < ApplicationRecord
include ActiveRpc::ModelExtensions
active_rpc :core, :User, foreign_key: :user_id do
attribute :name, :string
attribute :email, :string
attribute :department, :string
end
end
# Bulk load user data in one gRPC call
Employee.all.with_user_data
# Filter employees by remote user attribute
Employee.where_rpc(:user_ids, department: 'Engineering')
Features
- rpc_belongs_to — Treat remote gRPC resources like local associations
- Bulk loading —
with_user_datafetches all related records in one gRPC call - Cross-service filtering —
where_rpcfilters local records by remote attributes - Dirty tracking — Change remote attributes locally, propagate on save
- Bidirectional create/update — Creating/updating local records creates/updates remote resources
Installation
Add to your Gemfile:
gem 'the-active-rpc'
Configuration
ActiveRpc.configure do |config|
config.service_resolver = ->(subsystem, service_name) {
"::MyApp::#{subsystem.camelize}::#{service_name}".constantize
}
end
License
MIT