use of com.google.pubsub.v1.SchemaSettings in project java-pubsub by googleapis.
the class CreateTopicWithSchemaExample method createTopicWithSchemaExample.
public static void createTopicWithSchemaExample(String projectId, String topicId, String schemaId, Encoding encoding) throws IOException {
TopicName topicName = TopicName.of(projectId, topicId);
SchemaName schemaName = SchemaName.of(projectId, schemaId);
SchemaSettings schemaSettings = SchemaSettings.newBuilder().setSchema(schemaName.toString()).setEncoding(encoding).build();
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
Topic topic = topicAdminClient.createTopic(Topic.newBuilder().setName(topicName.toString()).setSchemaSettings(schemaSettings).build());
System.out.println("Created topic with schema: " + topic.getName());
} catch (AlreadyExistsException e) {
System.out.println(schemaName + "already exists.");
}
}
Aggregations