Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 106 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,22 @@ import ballerinax/confluent.cregistry;
### Step 2: Instantiate a new connector

```ballerina
configurable string baseUrl = ?;
configurable int identityMapCapacity = ?;
configurable map<anydata> originals = ?;
configurable map<string> headers = ?;

cregistry:Client schemaRegistryClient = check new ({
baseUrl,
identityMapCapacity,
originals,
headers
});
configurable string schemaRegistryUrl = ?;
configurable string apiKey = ?;
configurable string apiSecret = ?;
configurable string truststorePath = ?;
configurable string truststorePassword = ?;

cregistry:Client schemaRegistryClient = check new (
baseUrl = schemaRegistryUrl,
originals = {
"basic.auth.credentials.source": "USER_INFO",
"basic.auth.user.info": string `${apiKey}:${apiSecret}`
// Truststore configurations are optional when the schema registry's HTTP(S) endpoint is secured with a publicly trusted certificate.
"schema.registry.ssl.truststore.location": truststorePath,
"schema.registry.ssl.truststore.password": truststorePassword,
}
);
```

### Step 3: Invoke the connector operation
Expand Down Expand Up @@ -140,6 +145,96 @@ Execute the commands below to build from the source.
./gradlew clean build -PpublishToCentral=true
```

## Examples

1. Register a schema in the schema registry and retrieve it by ID:

```ballerina
import ballerinax/confluent.cregistry;

configurable string baseUrl = ?;
configurable int identityMapCapacity = ?;
configurable map<anydata> & readonly originals = ?;
configurable map<string> & readonly headers = ?;

public function main() returns error? {
cregistry:Client schemaRegistryClient = check new (
baseUrl = baseUrl,
identityMapCapacity = identityMapCapacity,
originals = originals,
headers = headers
);
string schema = string `
{
"namespace": "example.avro",
"type": "record",
"name": "Student",
"fields": [
{"name": "name", "type": "string"},
{"name": "favorite_color", "type": ["string", "null"]}
]
}`;
int schemaID = check schemaRegistryClient->register("student", schema);

string schemaResp = check schemaRegistryClient->getSchemaById(schemaID);
}
```

2. Producing Avro Messages to Kafka with Schema Registry:

``` ballerina
import ballerinax/kafka;

type Student record {
string name;
string favorite_color;
};

public function main() returns error? {
string valueSchema = string `{
"namespace": "example.avro",
"type": "record",
"name": "Student",
"fields": [
{"name": "name", "type": "string"},
{"name": "favorite_color", "type": ["string", "null"]}
]
}`;
string keySchema = string `{
"type": "string",
"name" : "stringValue",
"namespace": "data"
}`;
kafka:ProducerConfiguration config = {
compressionType: kafka:COMPRESSION_SNAPPY,
auth: {
username: "<USERNAME>",
password: "<PASSWORD>"
},
securityProtocol: kafka:PROTOCOL_SASL_SSL,
keySerializerType: kafka:SER_AVRO,
valueSerializerType: kafka:SER_AVRO,
keySchema: keySchema,
valueSchema: valueSchema,
schemaRegistryConfig: {
"baseUrl": baseUrl,
"originals": originals,
"headers": headers
}
};
kafka:Producer producer = check new ("<BOOTSTRAP_SERVERS>", config);

Student student = {
name: "John Doe",
favorite_color: "Red"
};
check producer->send({
topic: "students",
value: student
});
}
```

## Contributing to Ballerina

As an open source project, Ballerina welcomes contributions from the community.
Expand Down
27 changes: 16 additions & 11 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@ import ballerinax/confluent.cregistry;
### Step 2: Instantiate a new connector

```ballerina
configurable string baseUrl = ?;
configurable int identityMapCapacity = ?;
configurable map<anydata> originals = ?;
configurable map<string> headers = ?;

cregistry:Client schemaRegistryClient = check new ({
baseUrl,
identityMapCapacity,
originals,
headers
});
configurable string schemaRegistryUrl = ?;
configurable string apiKey = ?;
configurable string apiSecret = ?;
configurable string truststorePath = ?;
configurable string truststorePassword = ?;

cregistry:Client schemaRegistryClient = check new (
baseUrl = schemaRegistryUrl,
originals = {
"basic.auth.credentials.source": "USER_INFO",
"basic.auth.user.info": string `${apiKey}:${apiSecret}`
// Truststore configurations are optional when the schema registry's HTTP(S) endpoint is secured with a publicly trusted certificate.
"schema.registry.ssl.truststore.location": truststorePath,
"schema.registry.ssl.truststore.password": truststorePassword,
}
);
```

### Step 3: Invoke the connector operation
Expand Down
27 changes: 16 additions & 11 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@ import ballerinax/confluent.cregistry;
### Step 2: Instantiate a new connector

```ballerina
configurable string baseUrl = ?;
configurable int identityMapCapacity = ?;
configurable map<anydata> originals = ?;
configurable map<string> headers = ?;

cregistry:Client schemaRegistryClient = check new ({
baseUrl,
identityMapCapacity,
originals,
headers
});
configurable string schemaRegistryUrl = ?;
configurable string apiKey = ?;
configurable string apiSecret = ?;
configurable string truststorePath = ?;
configurable string truststorePassword = ?;

cregistry:Client schemaRegistryClient = check new (
baseUrl = schemaRegistryUrl,
originals = {
"basic.auth.credentials.source": "USER_INFO",
"basic.auth.user.info": string `${apiKey}:${apiSecret}`
// Truststore configurations are optional when the schema registry's HTTP(S) endpoint is secured with a publicly trusted certificate.
"schema.registry.ssl.truststore.location": truststorePath,
"schema.registry.ssl.truststore.password": truststorePassword,
}
);
```

### Step 3: Invoke the connector operation
Expand Down
Loading