tableProperties,
String clientId,
String clientSecret,
StreamConfigurationOptions options
)
```
--------------------------------
### Documenting Java API with Javadoc
Source: https://github.com/databricks/zerobus-sdk-java/blob/main/CONTRIBUTING.md
This snippet demonstrates adding Javadoc comments to public methods in the Java SDK. It includes standard tags like @param, @return, and @throws to describe parameters, return values, and exceptions. The method ingests records asynchronously using CompletableFuture, with potential blocking on high in-flight records; it requires valid stream state and throws ZerobusException on errors.
```java
/**
* Ingests a single record into the stream.
*
* Returns a CompletableFuture that completes when the record is durably written to storage.
* This method may block if the maximum number of in-flight records has been reached.
*
* @param record The protobuf message to ingest
* @return A CompletableFuture that completes when the record is acknowledged
* @throws ZerobusException if the stream is not in a valid state for ingestion
*/
public CompletableFuture ingestRecord(RecordType record) throws ZerobusException {
// ...
}
```
--------------------------------
### Create TableProperties for Zerobus Stream in Java
Source: https://github.com/databricks/zerobus-sdk-java/blob/main/README.md
Illustrates the constructor for `TableProperties`, which is used to configure the target table for a Zerobus stream. It requires the fully qualified table name and a Protobuf message default instance.
```java
TableProperties(String tableName, RecordType defaultInstance)
```
--------------------------------
### Git Feature Branch Workflow
Source: https://github.com/databricks/zerobus-sdk-java/blob/main/CONTRIBUTING.md
Complete sequence of Git commands for feature development workflow. Creates a feature branch, stages changes, commits with sign-off, and pushes to remote repository. Follows the project's pull request process for contributing changes.
```bash
git checkout -b feature/your-feature-name
```
```bash
git add .
```
```bash
git commit -s -m "Add feature: description of your changes"
```
```bash
git push origin feature/your-feature-name
```
--------------------------------
### Maven Dependency for Logback
Source: https://github.com/databricks/zerobus-sdk-java/blob/main/README.md
Includes the logback-classic library in Maven dependencies, recommended for production logging with the Zerobus SDK. Logback provides a robust and configurable logging framework that integrates seamlessly with SLF4J.
```xml
ch.qos.logback
logback-classic
1.2.11
```
--------------------------------
### Create Delta Table for Ingestion
Source: https://github.com/databricks/zerobus-sdk-java/blob/main/README.md
SQL statement to create a Delta table named 'air_quality' with specified columns: device_name (STRING), temp (INT), and humidity (BIGINT). This table will receive data ingested via the Zerobus SDK. Replace `` with your actual catalog.
```sql
CREATE TABLE .default.air_quality (
device_name STRING,
temp INT,
humidity BIGINT
)
USING DELTA;
```
--------------------------------
### Define Unity Catalog Table Schema
Source: https://github.com/databricks/zerobus-sdk-java/blob/main/README.md
SQL statement that creates a Delta table with columns for device name, temperature, and humidity. Serves as the source schema from which the SDK generates the protobuf message. Execute in a Databricks SQL notebook or cluster.
```sql
CREATE TABLE main.default.air_quality (
device_name STRING,
temp INT,
humidity BIGINT
)
USING DELTA;
```
--------------------------------
### Generate Protobuf Schema from Unity Catalog Table
Source: https://context7.com/databricks/zerobus-sdk-java/llms.txt
This bash script uses a Zerobus ingest SDK JAR to generate a Protocol Buffer schema from an existing Delta table in Unity Catalog. It requires the JAR file, Unity Catalog endpoint, credentials, table name, and output path for the proto file. Optionally specifies the Protobuf message name.
```bash
# Download the fat JAR with all dependencies
wget https://repo1.maven.org/maven2/com/databricks/zerobus-ingest-sdk/0.1.0/zerobus-ingest-sdk-0.1.0-jar-with-dependencies.jar
# Run the proto generation tool
java -jar zerobus-ingest-sdk-0.1.0-jar-with-dependencies.jar \
--uc-endpoint "https://dbc-a1b2c3d4-e5f6.cloud.databricks.com" \
--client-id "your-service-principal-application-id" \
--client-secret "your-service-principal-secret" \
--table "main.default.air_quality" \
--output "src/main/proto/record.proto" \
--proto-msg "AirQuality"
```
--------------------------------
### Define Protocol Buffer Schema
Source: https://github.com/databricks/zerobus-sdk-java/blob/main/README.md
Defines a sample schema for air quality data using Protocol Buffers. This schema is used by the Zerobus SDK to structure and validate ingested data. Ensure the generated Java classes match this schema for successful ingestion.
```protobuf
syntax = "proto3";
package com.databricks.zerobus.ingest.example;
option java_package = "com.databricks.zerobus.ingest.example";
option java_multiple_files = true;
message AirQuality {
string device_name = 1;
int32 temp = 2;
int64 humidity = 3;
}
```
--------------------------------
### Include Zerobus SDK and all Dependencies in Gradle (Fat JAR)
Source: https://github.com/databricks/zerobus-sdk-java/blob/main/README.md
Gradle dependency declaration for including the Zerobus Ingest SDK with all its dependencies bundled into a single artifact. This simplifies deployment for standalone applications.
```groovy
dependencies {
implementation 'com.databricks:zerobus-ingest-sdk:0.1.0:jar-with-dependencies'
}
```
--------------------------------
### Blocking Ingestion with Durability Guarantee (Java)
Source: https://context7.com/databricks/zerobus-sdk-java/llms.txt
Demonstrates synchronous ingestion of records into a Zerobus stream, waiting for each record to be durably written before proceeding. Utilizes the Zerobus SDK for stream creation and record building with protobuf. Takes client credentials and a list of records as inputs; ensures durability but may have lower throughput due to blocking.
```java
import com.databricks.zerobus.*;
import com.example.proto.Record.AirQuality;
ZerobusSdk sdk = new ZerobusSdk(serverEndpoint, workspaceUrl);
TableProperties tableProperties = new TableProperties<>(
"main.default.air_quality",
AirQuality.getDefaultInstance()
);
ZerobusStream stream = sdk.createStream(
tableProperties,
clientId,
clientSecret
).join();
try {
for (int i = 0; i < 1000; i++) {
AirQuality record = AirQuality.newBuilder()
.setDeviceName("sensor-" + i)
.setTemp(20 + (i % 15))
.setHumidity(50 + (i % 40))
.build();
// Wait for durability acknowledgment before proceeding
stream.ingestRecord(record).join();
if ((i + 1) % 100 == 0) {
System.out.println("Ingested " + (i + 1) + " records");
}
}
System.out.println("All 1000 records ingested successfully");
} catch (ZerobusException e) {
System.err.println("Ingestion failed: " + e.getMessage());
throw e;
} finally {
stream.close();
}
```
--------------------------------
### Handle Zerobus SDK Exceptions in Java
Source: https://github.com/databricks/zerobus-sdk-java/blob/main/README.md
Demonstrates how to handle retriable and non-retriable exceptions thrown by the Zerobus SDK. It includes specific catch blocks for NonRetriableException and ZerobusException, suggesting appropriate logging and retry strategies.
```java
try {
stream.ingestRecord(record);
} catch (NonRetriableException e) {
// Fatal error - do not retry
logger.error("Non-retriable error: " + e.getMessage());
throw e;
} catch (ZerobusException e) {
// Retriable error - can retry with backoff
logger.warn("Retriable error: " + e.getMessage());
// Implement retry logic
}
```
--------------------------------
### Include Zerobus SDK and all Dependencies in Maven (Fat JAR)
Source: https://github.com/databricks/zerobus-sdk-java/blob/main/README.md
Maven dependency configuration to include the Zerobus Ingest SDK along with all its transitive dependencies in a single JAR. This is useful for creating self-contained applications.
```xml
com.databricks
zerobus-ingest-sdk
0.1.0
jar-with-dependencies
```
--------------------------------
### Define Protocol Buffer Schema (Protobuf)
Source: https://github.com/databricks/zerobus-sdk-java/blob/main/README.md
A Protocol Buffer 2 (proto2) schema definition for an AirQuality message, including optional fields for device name, temperature, and humidity. This file is used to generate Java code for data serialization and deserialization.
```protobuf
syntax = "proto2";
package com.example;
option java_package = "com.example.proto";
option java_outer_classname = "Record";
message AirQuality {
optional string device_name = 1;
optional int32 temp = 2;
optional int64 humidity = 3;
}
```