Open Source API Gateway

kafkaProducer

Version

Publishes the body of the request or the response as a message to an Apache Kafka topic.

In the flow of an API, the interceptor sends a message for the request and another one for the response. Put it into request or response to send only one of them.

The interceptor needs the Membrane Kafka Extension. Without the extension Membrane does not start. Contact predic8 for the extension.

Example Configuration

api:
port: 2000
flow:
- request:
- kafkaProducer:
bootstrapServers: kafka.example.com:9092
topic: orders
key: headers['X-Order-Id']
- return:
status: 202
api:
  port: 2000
  flow:
    - request:
        - kafkaProducer:
            bootstrapServers: kafka.example.com:9092
            topic: orders
            key: headers['X-Order-Id']
    - return:
        status: 202

Syntax

kafkaProducer:
bootstrapServers: <string> # required
topic: <string> # required
'$ref': <string>
acks: <string>
batchSize: <int>
clientId: <string>
compressionType: <string>
deliveryTimeoutMs: <int>
enableIdempotence: <boolean>
key: <string>
language: <groovy|spel|xpath|jsonpath>
lingerMs: <int>
maxRequestSize: <int>
requestTimeoutMs: <int>
saslJaasConfig: <string>
saslMechanism: <string>
securityProtocol: <string>
xmlConfig: {}
kafkaProducer:
  bootstrapServers: <string> # required
  topic: <string> # required
  '$ref': <string>
  acks: <string>
  batchSize: <int>
  clientId: <string>
  compressionType: <string>
  deliveryTimeoutMs: <int>
  enableIdempotence: <boolean>
  key: <string>
  language: <groovy|spel|xpath|jsonpath>
  lingerMs: <int>
  maxRequestSize: <int>
  requestTimeoutMs: <int>
  saslJaasConfig: <string>
  saslMechanism: <string>
  securityProtocol: <string>
  xmlConfig: {}

Attributes

NameRequiredDefaultDescriptionExamples
acksallNumber of brokers that must acknowledge a message before it counts as sent.0 | 1 | all
batchSize16384Maximum size of a batch of messages in bytes.-
bootstrapServersrequired-Comma separated list of Kafka brokers used for the initial connection.kafka1.example.com:9092,kafka2.example.com:9092
clientId-Client id sent to the brokers, useful for logging and quotas on the Kafka side.membrane
compressionTypenoneCompression of the message batches.none | gzip | snappy | lz4 | zstd
deliveryTimeoutMs120000Upper bound in milliseconds for reporting success or failure of a send, including retries.-
enableIdempotencetruePrevents duplicate messages when the producer retries. Requires acks=all.-
key-Expression computing the record key. The key determines the partition. Without a key Kafka distributes the messages over the partitions.headers['X-Order-Id']
languageSpELLanguage of the plugin's expressions.SpEL | groovy | jsonpath | xpath
lingerMs0Time in milliseconds to wait for more messages before a batch is sent.-
maxRequestSize1048576Maximum size of a single message in bytes.-
requestTimeoutMs30000Time in milliseconds to wait for the answer of a broker.-
saslJaasConfig-JAAS login configuration for SASL authentication.org.apache.kafka.common.security.plain.PlainLoginModule required username="user" password="secret";
saslMechanism-SASL mechanism for authentication, used with the security protocols SASL_PLAINTEXT and SASL_SSL.PLAIN | SCRAM-SHA-256 | SCRAM-SHA-512
securityProtocol-Protocol used to talk to the brokers. Kafka default is PLAINTEXT.PLAINTEXT | SSL | SASL_PLAINTEXT | SASL_SSL
topicrequired-Topic the messages are sent to.orders
$ref-Reference a component defined under components.-

Child Structure

ElementCardinalityDescription
xmlConfig0..1XML namespace declarations for the plugin's XPath expressions.

Can be used in

Show all 24 parent elements