Relay Kafka records over HTTP

Use the record relay to move records from a Kafka topic on a lower security site to a higher security site that does not allow incoming connections from the lower site. The integration flow on the higher site uses the receiveFromRelay source as its poller. The poller opens every connection and fetches batches over HTTPS. Each record starts a separate message. For a new or existing HTTP API instead of the relay API, see Pull Kafka records over HTTP.

Deploy the relay flow on the lower security site

Use a Kafka topic with records and a consumer group dedicated to this relay flow. Never share the group with another consumer or reset its offsets. Size the topic’s retention time and storage for the longest expected outage on the higher site, plus the time it takes the poller to catch up.

Replace lower-org, the broker address, and the topic and consumer group names in the example with your values. If the broker requires authentication, register a Kafka secret in the lower-site organization and set authenticationConfigKey to its name. The example uses events-kafka. If the broker does not require authentication, omit authenticationConfigKey. The relayApi source supplies the API and formats its responses. No OpenAPI resource is needed.

Kotlin imports for the relay flow
import com.greenbird.metercloud.integration.flow.spec.FlowExchangePattern.RequestResponse
import com.greenbird.metercloud.integration.flow.spec.FlowPipelineDeploymentScope.SINGLETON
import com.greenbird.metercloud.integration.flow.spec.dsl.KafkaCursorFormat.OPAQUE
import com.greenbird.metercloud.integration.flow.spec.dsl.KafkaPollMode.RELAY
import com.greenbird.metercloud.integration.flow.spec.dsl.KafkaStartPolicy.EARLIEST
import com.greenbird.metercloud.integration.flow.spec.dsl.flowConfig
import com.greenbird.utilihive.integration.deployment.flow.FlowDeploy
object EventsRelayFlow {
    @FlowDeploy
    fun eventsRelay() = flowConfig {
        id = "events-relay"
        ownerId = "lower-org"
        exchangePattern = RequestResponse
        flowPipelineDeploymentStrategy { scope = SINGLETON }
        maxNumberOfInFlightMessages = 1
        redeliveryStrategy {
            redeliveryMaxNo = 0
            redeliveryMillis = 27_000
        }

        relayApi { id = "relay-api" }

        pollFromKafka {
            id = "read-events"
            brokerList = "kafka.example.com:9093"
            topic = "events"
            groupId = "events.higher-site-relay"
            authenticationConfigKey = "events-kafka"
            mode = RELAY
            cursorFormat = OPAQUE
            startPolicy = EARLIEST
            maxBatchRecords = 100
            maxWaitMillis = 20_000
            kafkaTimeoutMillis = 5_000
            leaseTtlMillis = 60_000
        }
    }
}

Use the SDK Deployer to deploy the flow to the lower site. Use mutual TLS (mTLS) so the lower site can verify the higher site’s client certificate. On the lower site, register the client CA and grant the mTLS service account Flow Access to events-relay.

Deploy the poller flow on the higher security site

In the higher-site organization, register a TLS secret with the client certificate and private key. Add the CA certificate for the relay’s server if the poller does not already trust it. Set sslAuthenticationConfigKey to the secret’s name. The example uses events-relay-tls. Replace higher-org, the mTLS Flow Access URL of the relay flow, and the target URL with your values. Set the receiveFromRelay address to the relay flow URL. Omit /relay/v1: the source appends it. For this example, put JSON text on the Kafka topic and use a target that accepts it as the body of an HTTP POST.

Kotlin imports for the poller flow
import com.greenbird.metercloud.integration.flow.spec.DeliveryGuarantee.BySourceSystem
import com.greenbird.metercloud.integration.flow.spec.FlowExchangePattern.RequestResponse
import com.greenbird.metercloud.integration.flow.spec.dsl.HttpMethod.POST
import com.greenbird.metercloud.integration.flow.spec.dsl.RelayNackStrategy.PAUSE
import com.greenbird.metercloud.integration.flow.spec.dsl.RelayOrderingStrategy.STRICT
import com.greenbird.metercloud.integration.flow.spec.dsl.flowConfig
import com.greenbird.utilihive.integration.deployment.flow.FlowDeploy
object EventsPollerFlow {
    @FlowDeploy
    fun eventsPoller() = flowConfig {
        id = "events-poller"
        ownerId = "higher-org"
        exchangePattern = RequestResponse
        deliveryGuarantee = BySourceSystem
        maxNumberOfInFlightMessages = 8
        redeliveryStrategy {
            redeliveryMaxNo = 0
            redeliveryMillis = 15_000
        }

        receiveFromRelay {
            id = "receive-events"
            address = "https://lower-org.mtls.example.com/connect/flows/rs/events-relay"
            sslAuthenticationConfigKey = "events-relay-tls"
            maxRecords = 100
            waitMillis = 20_000
            receiveTimeoutMillis = 30_000
            orderingStrategy = STRICT
            nackStrategy = PAUSE
        }

        restRequest {
            id = "send-event"
            address = "https://events.example.com/api/events"
            defaultMethod = POST
            defaultEntityContentType = "application/json"
            receiveTimeoutMillis = 5_000
        }
    }
}

Deploy to the higher site and grant a local Poller User service account Flow Access to events-poller. Use PAUSE when you cannot skip failed records. The poller keeps retrying them and does not acknowledge past them.

Verify delivery and acknowledgement

  1. Note the relay group’s committed offsets in Kafka, if any. Produce two JSON records with distinct event IDs to the same partition.

  2. Check the target for both event IDs in the order you sent them. The poller sends each record as its own POST.

  3. After the target accepts both records, check the group again from the lower site. The committed offset for the partition should be greater than the second record’s offset. The poller acknowledges on a later fetch, so allow time for the next request.

    kafka-consumer-groups.sh --bootstrap-server kafka.example.com:9093 \
      --command-config kafka-client.properties \
      --describe --group events.higher-site-relay

    Use your broker’s client configuration, or omit --command-config if it is not needed. Read the CURRENT-OFFSET column for the partition.

Handle duplicates and late updates

STRICT starts one record at a time for each orderingKey. For a Kafka relay, that means order within a partition, not across partitions. An HTTP call can still finish after Connect times it out. If a late update must not overwrite a newer one, have the target reject stale updates using a sequence number or version. Records delivered but not yet acknowledged can be delivered again after a restart or lease loss. Use a stable event ID from the record to deduplicate. relayCursor tracks progress and can change on redelivery.

Set timeouts and the poller lease

Give each caller enough time to receive a response:

Where What to set

Relay flow

Set redeliveryMillis above maxWaitMillis plus kafkaTimeoutMillis plus 1 s. The example uses 27 s for a 20 s wait and a 5 s Kafka deadline.

receiveFromRelay

Keep waitMillis at or below the relay’s maxWaitMillis. Set receiveTimeoutMillis above waitMillis and above the relay’s longest response time, with room for network delay. The HTTP source can wait up to the relay flow’s redeliveryMillis minus 1 s. Gateway and proxy timeouts must allow for that response time too.

pollFromKafka

Set leaseTtlMillis above the poller’s receiveTimeoutMillis plus 5 s for its maximum retry delay. The example uses 60 s with a 30 s receive timeout.

Poller flow

Set redeliveryMillis above the time for one attempt to send a record to the target, including downstream timeouts and a buffer. See Design a flow.

Run one poller per relay flow. Each answered fetch renews its lease, even when there are no new records. A second poller receives HTTP 409 while the first holds the lease. Stop the first poller gracefully to release the lease for immediate takeover. After a crash, the replacement waits for the lease to expire, then resumes from Kafka’s committed position.

Transform records on the lower site

Leave the request payload intact before pollFromKafka. After it, use map to change or filter the list of relayed records. Filtering skips records: when the poller finishes the retained records, the batch acknowledgement advances past the dropped records too. Keep the mapping free of side effects because a retry can run it again. Preserve the fields required by the Relay API, and leave timestamp, orderingKey, cursor and the relay* batch exchange properties unchanged.