Forward via port mapping
Map listener ports to forward messages from a Kafka client to a virtual cluster.
Prerequisites
-
A matching mapping port for each broker on the backend cluster.
curl -X POST https://{region}.api.konghq.com/v1/event-gateways/{eventGatewayId}/listeners/{eventGatewayListenerId}/policies \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "forward",
"type": "forward_to_virtual_cluster",
"config": {
"advertised_host": "0.0.0.0",
"bootstrap_port": "at_start",
"destination": {
"name": "example-virtual-cluster"
},
"min_broker_id": 1,
"type": "port_mapping"
}
}
'Make sure to replace the following placeholders with your own values:
-
region: Geographic region where your Kong Konnect is hosted and operates. -
KONNECT_TOKEN: Your Personal Access Token (PAT) associated with your Konnect account. -
virtualClusterId: Theidof the Virtual Cluster. -
eventGatewayId: Theidof the Event Gateway. -
eventGatewayListenerId: Theidof the Event Gateway Listener.
See the Konnect Event Gateway API reference to learn about region-specific URLs and personal access tokens.
Prerequisite: Configure your Personal Access Token
terraform {
required_providers {
konnect-beta = {
source = "kong/konnect-beta"
}
}
}
provider "konnect-beta" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}resource "konnect_event_gateway_listener_policy_forward_to_virtual_cluster" "my_listener_policy_forward_to_virtual_cluster" {
provider = konnect-beta
type = "forward_to_virtual_cluster"
config = {
advertised_host = "0.0.0.0"
bootstrap_port = "at_start"
destination = {
name = "example-virtual-cluster"
}
min_broker_id = 1
type = "port_mapping"
}
event_gateway_listener_id = konnect_event_gateway_listener.my_listener.id
gateway_id = konnect_event_gateway.my_event_gateway.id
}The following example creates a new forward_to_virtual_cluster policy.
Add this snippet to an event_gateways resource in your declarative configuration file, and then manage it with kongctl:
event_gateways:
- ref: eventGatewayName
name: eventGatewayName
listeners:
- ref: listenerName
name: listenerName
policies:
- ref: forward
type: forward_to_virtual_cluster
forward_to_virtual_cluster:
name: forward
config:
advertised_host: 0.0.0.0
bootstrap_port: at_start
destination:
name: example-virtual-cluster
min_broker_id: 1
type: port_mappingMake sure to replace the following placeholders with your own values:
-
eventGatewayName: Thenameof your Event Gateway. -
listenerName: Thenameof the Listener.