use of com.google.pubsub.v1.SchemaName in project java-pubsub by googleapis.
the class GetSchemaExample method getSchemaExample.
public static void getSchemaExample(String projectId, String schemaId) throws IOException {
SchemaName schemaName = SchemaName.of(projectId, schemaId);
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
Schema schema = schemaServiceClient.getSchema(schemaName);
System.out.println("Got a schema:\n" + schema);
} catch (NotFoundException e) {
System.out.println(schemaName + "not found.");
}
}
use of com.google.pubsub.v1.SchemaName in project java-pubsub by googleapis.
the class SchemaServiceClientTest method deleteSchemaTest.
@Test
public void deleteSchemaTest() throws Exception {
Empty expectedResponse = Empty.newBuilder().build();
mockSchemaService.addResponse(expectedResponse);
SchemaName name = SchemaName.of("[PROJECT]", "[SCHEMA]");
client.deleteSchema(name);
List<AbstractMessage> actualRequests = mockSchemaService.getRequests();
Assert.assertEquals(1, actualRequests.size());
DeleteSchemaRequest actualRequest = ((DeleteSchemaRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.pubsub.v1.SchemaName 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.");
}
}
use of com.google.pubsub.v1.SchemaName in project gapic-generator-java by googleapis.
the class SyncGetSchemaSchemaname method syncGetSchemaSchemaname.
public static void syncGetSchemaSchemaname() throws Exception {
// It may require modifications to work in your environment.
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
SchemaName name = SchemaName.of("[PROJECT]", "[SCHEMA]");
Schema response = schemaServiceClient.getSchema(name);
}
}
use of com.google.pubsub.v1.SchemaName in project gapic-generator-java by googleapis.
the class SchemaServiceClientTest method deleteSchemaTest.
@Test
public void deleteSchemaTest() throws Exception {
Empty expectedResponse = Empty.newBuilder().build();
mockSchemaService.addResponse(expectedResponse);
SchemaName name = SchemaName.of("[PROJECT]", "[SCHEMA]");
client.deleteSchema(name);
List<AbstractMessage> actualRequests = mockSchemaService.getRequests();
Assert.assertEquals(1, actualRequests.size());
DeleteSchemaRequest actualRequest = ((DeleteSchemaRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations