Skip to main content

Listeners and Rules

When you create a Connector, you define listeners that specify how clients connect to it.

Listeners

A listener monitors a specific port for incoming client connections. You can define multiple listeners on different ports for different use cases.
Port 8080 is reserved for the Connector’s health check endpoint and cannot be used for listeners.

Listener Rules

Each listener uses routing rules to determine where to forward requests. There are three types of rules:
Routes all connections to a specific resource.Example: All traffic on port 5432 goes to the production-postgres database.
Routes connections to all resources of a specific technology (e.g., all PostgreSQL databases). When multiple resources match, smart routing automatically selects the correct resource based on the connection string.
Only supported for PostgreSQL and HTTP. Use Spaces to limit which resources are accessible.
Routes to any resource using deep packet inspection to detect the protocol automatically.Supported protocols: PostgreSQL, MongoDB, HTTP, S3, SSH, Kubernetes.This is the most flexible option but requires the Connector to inspect traffic to determine routing.
A single listener can have multiple rules, and you can combine different rule types.

Terraform Example

The following example demonstrates how to deploy a Connector linked to all PostgreSQL resources:
terraform {
  required_providers {
    formal = {
      source  = "formalco/formal"
      version = "4.12.8"
    }
  }
}

provider "formal" {
  api_key = var.formal_api_key
}

resource "formal_connector" "main" {
  name = var.name
}

resource "formal_connector_listener" "postgres_listener" {
  name = "postgres-listener"
  port = 5432
}

resource "formal_connector_listener_rule" "postgres_rule" {
  connector_listener_id = formal_connector_listener.postgres_listener.id
  type                  = "technology"
  rule                  = "postgres"
}
This configuration creates:
  • A Connector named main
  • A listener on the specified port for PostgreSQL connections
  • A technology rule that routes all PostgreSQL traffic to any PostgreSQL resource in your organization