Main agent

circle-check

The main agent acts as an aggregator that connects to multiple RPC agents and combines them into a single Forest Admin interface. This works exactly like a classic Forest Admin agent with multiple datasources: once connected, you can define relations across datasources transparently.

Installation

Add the gem to your Gemfile:

gem 'forest_admin_datasource_rpc'

Then run:

bundle install

Configuration

Configure your app/lib/forest_admin_rails/create_agent.rb file to add RPC datasources:

module ForestAdminRails
  class CreateAgent
    def self.setup!
      @agent = ForestAdminAgent::Builder::AgentFactory.instance

      # Add RPC datasources
      @agent.add_datasource(
        ForestAdminDatasourceRpc.build(uri: 'http://customers-app:3002')
      )

      @agent.add_datasource(
        ForestAdminDatasourceRpc.build(
          uri: 'http://billing-app:3003',
          auth_secret: 'YOUR-SHARED-AUTH-SECRET'
        )
      )

      # You can also add local datasources
      @agent.add_datasource(ForestAdminDatasourceMongoid.build)

      @agent.use(ForestAdminDatasourceRpc::ReconciliateRpc)

      @agent.build
    end
  end
end
circle-info

The auth_secret option is optional. If not specified, it defaults to your Forest Admin project's auth_secret. You can override it to use a different shared secret for RPC communication.

Introspection caching

By default, the main agent introspects each RPC agent at startup. Caching the introspection schema provides several benefits:

  • Faster startup: No need to query RPC agents during initialization

  • Resilience: The main agent can start even if an RPC agent is temporarily unavailable

  • Asynchronous deployments: Deploy your services independently without worrying about startup order

Generating the schema

RPC agents automatically generate a .forestadmin-rpc-schema.json file in development mode.

Loading cached introspection

Pass the cached schema when adding a datasource:

circle-info

Cached introspection schemas should be regenerated when the RPC agent's collections change.

Last updated