Kafka Producer
#
DescriptionCreate an API to send a message to Kafka.
This Service uses the Kafka producer library to connect to an active instance of Kafka and send messages.
Note: Only a single message can be sent per rest call at this time
#
UIAccess the DataTrucker URL via a browser
#
Create a credentials- Go to Credentials in the sidebar > Kafka Credentials
- Scroll down to Credential Management
- Fill the form to create the credential
- Credential name – an arbitrary value to identify the credential object
- The hostname is a list of comma-separated brokers
- example: ” ‘localhost:9092′,’host1:9091’ “
- Click on Create
#
Make an API- Go to IoT API in the Sidebar > Kafka APIs
- Fill the form to create the API
- Resource Name: an arbitrary name to identify the resource
- The Credential linked to the resources
- Method: The type of REST Call
- Script: identifying the topic to send messages to.
- Validation Regex of Input values, input sanitization before querying
- Examples provided in the UI when you try to create a new API
#
Query the resource you created################################ send an message to Kafka#############################URL: /api/v1/jobs/<resource name>TYPE: <method defined>HEADER: Authorization: "Bearer <JWT Token>"BODY (JSON): { "key": "abcd", "value": "123456"}
Response: 200 OK{ jsondata....}
#
As a CRD in Openshift / KubernetesFor credentials use the the API below to the management end point
---apiVersion: datatrucker.datatrucker.io/v1kind: DatatruckerFlowmetadata: name: datatruckerflow-samplespec: Resources: requests: memory: "256Mi" cpu: "250m" limits: memory: "256Mi" cpu: "500m" JobDefinitions: - resourcename: kafka1 name: kafka1 type: IOT-Kafka-Producer tenant: Admin restmethod: PATCH target_type: topic: test credentialname: kafkaconnect1 validations: type: object properties: message: type: string pattern: "^[a-z0-9A-Z_]*$" maxLength: 8 Keys: configmap: placeholder Scripts: configmap: placeholder Type: Job DatatruckerConfig: datatruckerconfig-sample Replicas: 1 API: name: api Image: repository: docker.io imageName: datatruckerio/datatrucker-api tagName: latest
#
API#
Create a credential via RESTURL: /api/v1/credentials/TYPE: POSTHEADER: Authorization: "Bearer <JWT Token>"BODY (JSON): { "credentialname": "kafkaconnect1", "type": "IOT-Kafka-Producer", "hostname": "localhost:9092"}
Response: 201 OK
#
Create the API via REST############################### create a Kafka Producer request #############################
URL: /api/v1/resourcesTYPE: POSTHEADER: Authorization: "Bearer <JWT Token>"BODY (JSON): { "resourcename": "kafka1", "type": "IOT-Kafka-Producer", "restmethod": "PATCH", "target_type": { "topic": "test" }, "credentialname": "kafkaconnect1", "validations": { "type": "object", "properties": { "message": { "type": "string", "pattern": "^[a-z0-9A-Z_]*$", "maxLength": 8 } } } }
Response: 201 OK