use of org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.ProjectPath in project beam by apache.
the class PubsubUnboundedSource method createRandomSubscription.
private SubscriptionPath createRandomSubscription(PipelineOptions options) {
TopicPath topicPath = topic.get();
ProjectPath projectPath;
if (project != null) {
projectPath = project.get();
} else {
String projectId = options.as(GcpOptions.class).getProject();
checkState(projectId != null, "Cannot create subscription to topic %s because pipeline option 'project' not specified", topicPath);
projectPath = PubsubClient.projectPathFromId(options.as(GcpOptions.class).getProject());
}
try {
try (PubsubClient pubsubClient = pubsubFactory.newClient(timestampAttribute, idAttribute, options.as(PubsubOptions.class))) {
SubscriptionPath subscriptionPath = pubsubClient.createRandomSubscription(projectPath, topicPath, DEAULT_ACK_TIMEOUT_SEC);
LOG.warn("Created subscription {} to topic {}." + " Note this subscription WILL NOT be deleted when the pipeline terminates", subscriptionPath, topic);
return subscriptionPath;
}
} catch (Exception e) {
throw new RuntimeException(String.format("Failed to create subscription to topic %s on project %s: %s", topicPath, projectPath, e.getMessage()), e);
}
}
use of org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.ProjectPath in project beam by apache.
the class PubsubClientTest method projectPathFromIdWellFormed.
//
// Paths
//
@Test
public void projectPathFromIdWellFormed() {
ProjectPath path = PubsubClient.projectPathFromId("test");
assertEquals("projects/test", path.getPath());
}
Aggregations