PubsubGrpc.Application (PubsubGrpc v0.4.2)

View Source

Application module for PubsubGrpc.

This module starts the default gRPC connection pool using the GrpcConnectionPool library. The pool is configured based on application environment settings and supports both production Google Cloud Pub/Sub and emulator environments.

Configuration

Production Configuration (Google Cloud)

# config/prod.exs
config :pubsub_grpc, GrpcConnectionPool,
  endpoint: [
    type: :production,
    host: "pubsub.googleapis.com",
    port: 443,
    ssl: []
  ],
  pool: [
    size: 10,
    name: PubsubGrpc.ConnectionPool
  ],
  connection: [
    keepalive: 30_000,
    ping_interval: 25_000
  ]

Emulator Configuration (Development/Testing)

# config/dev.exs
config :pubsub_grpc, GrpcConnectionPool,
  endpoint: [
    type: :local,
    host: "localhost",
    port: 8085
  ],
  pool: [
    size: 3,
    name: PubsubGrpc.ConnectionPool
  ],
  connection: [
    ping_interval: nil  # Disable pinging for emulator
  ]

Legacy Configuration Support

The following legacy configuration is still supported:

# config/config.exs
config :pubsub_grpc, :default_pool_size, 10
config :pubsub_grpc, :emulator, [
  project_id: "my-project-id",
  host: "localhost",
  port: 8085
]

Custom Pools

You can add additional pools to your own application supervision tree:

# In your application.ex
defmodule MyApp.Application do
  def start(_type, _args) do
    {:ok, config} = GrpcConnectionPool.Config.local(
      host: "localhost",
      port: 8085,
      pool_name: MyApp.CustomPool
    )

    children = [
      # Your other services...
      {GrpcConnectionPool, config}
    ]

    Supervisor.start_link(children, opts)
  end
end