Java Code Examples for com.google.cloud.pubsub.v1.TopicAdminClient#createTopic()

The following examples show how to use com.google.cloud.pubsub.v1.TopicAdminClient#createTopic() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PubsubHelper.java    From flink with Apache License 2.0 5 votes vote down vote up
public Topic createTopic(String project, String topic) throws IOException {
	deleteTopic(project, topic);
	ProjectTopicName topicName = ProjectTopicName.of(project, topic);
	TopicAdminClient adminClient = getTopicAdminClient();
	LOG.info("CreateTopic {}", topicName);
	return adminClient.createTopic(topicName);
}
 
Example 2
Source File: PubSubConnector.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
private void createTopic(final PubSubConfig config) {
    final TopicAdminClient topicAdminClient = pubSubManager.topicAdminClient(config);

    final ProjectTopicName topicName = ProjectTopicName.of(config.getProjectId(), config.getTopic());

    try {
        topicAdminClient.getTopic(topicName);
    } catch (final NotFoundException nf) {
        try {
            topicAdminClient.createTopic(topicName);
        } catch (final AlreadyExistsException ae) {
            log.topicExistAlready(topicName, ae);
        }
    }
}
 
Example 3
Source File: Connection.java    From heroic with Apache License 2.0 5 votes vote down vote up
void createTopic() throws IOException {
    log.info("Creating topic {}", topicName);
    TopicAdminClient topicAdminClient = TopicAdminClient.create(
        TopicAdminSettings.newBuilder()
            .setTransportChannelProvider(channelProvider)
            .setCredentialsProvider(credentialsProvider)
            .build()
    );
    try {
        topicAdminClient.createTopic(topicName);
    } catch (AlreadyExistsException e) {
        log.info("Topic already exists");
    }
}
 
Example 4
Source File: PubsubHelper.java    From flink with Apache License 2.0 5 votes vote down vote up
public Topic createTopic(String project, String topic) throws IOException {
	deleteTopic(project, topic);
	ProjectTopicName topicName = ProjectTopicName.of(project, topic);
	TopicAdminClient adminClient = getTopicAdminClient();
	LOG.info("CreateTopic {}", topicName);
	return adminClient.createTopic(topicName);
}
 
Example 5
Source File: RealTimeFeed.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void createTopic() throws Exception {
  TopicAdminClient topicAdminClient = TopicAdminClient.create();
  topicAdminClient.createTopic(topicName);
}