Skip to content

Commit

Permalink
Update API documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa authored Jun 13, 2022
1 parent 0bca38d commit 98102b7
Showing 1 changed file with 1 addition and 126 deletions.
127 changes: 1 addition & 126 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,132 +129,7 @@ I recommend the [fast-data-dev](https://github.com/lensesio/fast-data-dev) Docke

### The xk6-kafka API

All the exported functions are available by importing them from `k6/x/kafka`. They are subject to change in the future versions when a new major version is released. These are the exported functions and they always reflect the latest changes on the `main` branch.

<details>
<summary>The JavaScript API</summary>

```typescript
/**
* Create a new Writer object for writing messages to Kafka.
*
* @constructor
* @param {[string]} brokers An array of brokers, e.g. ["host:port", ...].
* @param {string} topic The topic to write to.
* @param {object} saslConfig The SASL configuration.
* @param {object} tlsConfig The TLS configuration.
* @param {string} compression The Compression algorithm.
* @returns {[object, error]} An array of two objects: A Writer object and an error object.
*/
function writer(brokers: [string], topic: string, saslConfig: object, tlsConfig: object, compression: string) => [object, error] {}
/**
* Write a sequence of messages to Kafka.
*
* @function
* @param {object} writer The writer object created with the writer constructor.
* @param {[object]} messages An array of message objects containing an optional key and a value. Topic, offset and time and headers are also available and optional. Headers are objects.
* @param {string} keySchema An optional Avro/JSONSchema schema for the key.
* @param {string} valueSchema An optional Avro/JSONSchema schema for the value.
* @param {boolean} autoCreateTopic Automatically creates the topic on the first produced message. Defaults to false.
* @returns {object} A error object.
*/
function produce(writer: object, messages: [object], keySchema: string, valueSchema: string, autoCreateTopic: boolean) => error {}
/**
* Write a sequence of messages to Kafka with a specific serializer/deserializer.
*
* @function
* @param {object} writer The writer object created with the writer constructor.
* @param {[object]} messages An array of message objects containing an optional key and a value. Topic, offset and time and headers are also available and optional. Headers are objects.
* @param {string} configurationJson Serializer, deserializer and schemaRegistry configuration.
* @param {string} keySchema An optional Avro/JSONSchema schema for the key.
* @param {string} valueSchema An optional Avro/JSONSchema schema for the value.
* @param {boolean} autoCreateTopic Automatically creates the topic on the first produced message. Defaults to false.
* @returns {object} A error object.
*/
function produceWithConfiguration(writer: object, messages: [object], configurationJson: string, keySchema: string, valueSchema: string, autoCreateTopic: boolean) => error {}
/**
* Create a new Reader object for reading messages from Kafka.
*
* @constructor
* @param {[string]} brokers An array of brokers, e.g. ["host:port", ...].
* @param {string} topic The topic to read from.
* @param {number} partition The partition.
* @param {number} groupID The group ID.
* @param {number} offset The offset to begin reading from.
* @param {object} saslConfig The SASL configuration.
* @param {object} tlsConfig The TLS configuration.
* @returns {[object, error]} An array of two objects: A Reader object and an error object.
*/
function reader(brokers: [string], topic: string, partition: number, groupID: string, offset: number, saslConfig: object, tlsConfig: object) => [object, error] {}
/**
* Read a sequence of messages from Kafka.
*
* @function
* @param {object} reader The reader object created with the reader constructor.
* @param {number} limit How many messages should be read in one go, which blocks. Defaults to 1.
* @param {string} keySchema An optional Avro/JSONSchema schema for the key.
* @param {string} valueSchema An optional Avro/JSONSchema schema for the value.
* @returns {[[object], error]} An array of two objects: an array of objects and an error object. Each message object can contain a value and an optional set of key, topic, partition, offset, time, highWaterMark and headers. Headers are objects.
*/
function consume(reader: object, limit: number, keySchema: string, valueSchema: string) => [[object], error] {}
/**
* Read a sequence of messages from Kafka.
*
* @function
* @param {object} reader The reader object created with the reader constructor.
* @param {number} limit How many messages should be read in one go, which blocks. Defaults to 1.
* @param {string} configurationJson Serializer, deserializer and schemaRegistry configuration.
* @param {string} keySchema An optional Avro/JSONSchema schema for the key.
* @param {string} valueSchema An optional Avro/JSONSchema schema for the value.
* @returns {[[object], error]} An array of two objects: an array of objects and an error object. Each message object can contain a value and an optional set of key, topic, partition, offset, time, highWaterMark and headers. Headers are objects.
*/
function consumeWithConfiguration(reader: object, limit: number, configurationJson: string, keySchema: string, valueSchema: string) => [[object], error] {}
/**
* Create a topic in Kafka. It does nothing if the topic exists.
*
* @function
* @param {string} address The broker address.
* @param {string} topic The topic name.
* @param {number} partitions The number of partitions.
* @param {number} replicationFactor The replication factor in a clustered setup.
* @param {string} compression The compression algorithm.
* @param {object} saslConfig The SASL configuration.
* @param {object} tlsConfig The TLS configuration.
* @returns {object} A error object.
*/
function createTopic(address: string, topic: string, partitions: number, replicationFactor: number, compression: string, saslConfig: object, tlsConfig: object) => error {}
/**
* Delete a topic from Kafka. It raises an error if the topic doesn't exist.
*
* @function
* @param {string} address The broker address.
* @param {string} topic The topic name.
* @param {object} saslConfig The SASL configuration.
* @param {object} tlsConfig The TLS configuration.
* @returns {object} A error object.
*/
function deleteTopic(address: string, topic: string, saslConfig: object, tlsConfig: object) => error {}
/**
* List all topics in Kafka.
*
* @function
* @param {string} address The broker address.
* @param {object} saslConfig The SASL configuration.
* @param {object} tlsConfig The TLS configuration.
* @returns {[[string]], error]} A nested list of strings containing a list of topics and the error object (if any).
*/
function listTopics(address: string, saslConfig: object, tlsConfig: object) => [[string], error] {}
```
</details>
All the exported functions are available by importing them from `k6/x/kafka`. They are subject to change in the future versions when a new major version is released. The exported functions are available in the [`index.d.ts`](/index.d.ts) file and they always reflect the latest changes on the `main` branch. The generated documentation can be accessed at [`docs/README.md`](/docs/README.md).

### k6 Test Script

Expand Down

0 comments on commit 98102b7

Please sign in to comment.