Search in sources :

Example 11 with SchemaName

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.");
    }
}
Also used : Schema(com.google.pubsub.v1.Schema) NotFoundException(com.google.api.gax.rpc.NotFoundException) SchemaServiceClient(com.google.cloud.pubsub.v1.SchemaServiceClient) SchemaName(com.google.pubsub.v1.SchemaName)

Example 12 with SchemaName

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()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) DeleteSchemaRequest(com.google.pubsub.v1.DeleteSchemaRequest) SchemaName(com.google.pubsub.v1.SchemaName) Test(org.junit.Test)

Example 13 with SchemaName

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.");
    }
}
Also used : AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) TopicAdminClient(com.google.cloud.pubsub.v1.TopicAdminClient) Topic(com.google.pubsub.v1.Topic) SchemaSettings(com.google.pubsub.v1.SchemaSettings) SchemaName(com.google.pubsub.v1.SchemaName) TopicName(com.google.pubsub.v1.TopicName)

Example 14 with SchemaName

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);
    }
}
Also used : Schema(com.google.pubsub.v1.Schema) SchemaServiceClient(com.google.cloud.pubsub.v1.SchemaServiceClient) SchemaName(com.google.pubsub.v1.SchemaName)

Example 15 with SchemaName

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()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) DeleteSchemaRequest(com.google.pubsub.v1.DeleteSchemaRequest) SchemaName(com.google.pubsub.v1.SchemaName) Test(org.junit.Test)

Aggregations

SchemaName (com.google.pubsub.v1.SchemaName)15 Test (org.junit.Test)8 SchemaServiceClient (com.google.cloud.pubsub.v1.SchemaServiceClient)6 Schema (com.google.pubsub.v1.Schema)6 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 DeleteSchemaRequest (com.google.pubsub.v1.DeleteSchemaRequest)4 StatusRuntimeException (io.grpc.StatusRuntimeException)4 AlreadyExistsException (com.google.api.gax.rpc.AlreadyExistsException)3 NotFoundException (com.google.api.gax.rpc.NotFoundException)2 Empty (com.google.protobuf.Empty)2 GetSchemaRequest (com.google.pubsub.v1.GetSchemaRequest)2 ProjectName (com.google.pubsub.v1.ProjectName)2 TopicAdminClient (com.google.cloud.pubsub.v1.TopicAdminClient)1 SchemaSettings (com.google.pubsub.v1.SchemaSettings)1 Topic (com.google.pubsub.v1.Topic)1 TopicName (com.google.pubsub.v1.TopicName)1