use of org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.SubscriptionPath in project beam by apache.
the class FhirIOReadIT method setup.
@Before
public void setup() throws Exception {
healthcareDataset = String.format(HEALTHCARE_DATASET_TEMPLATE, project);
if (client == null) {
this.client = new HttpHealthcareApiClient();
}
pubsub = PubsubGrpcClient.FACTORY.newClient(null, null, pipelineOptions);
TopicPath topicPath = PubsubClient.topicPathFromPath(pubsubTopic);
pubsub.createTopic(topicPath);
SubscriptionPath subscriptionPath = PubsubClient.subscriptionPathFromPath(pubsubSubscription);
pubsub.createSubscription(topicPath, subscriptionPath, 60);
client.createFhirStore(healthcareDataset, fhirStoreName, version, pubsubTopic);
// Execute bundles to trigger FHIR notificiations to input topic
FhirIOTestUtil.executeFhirBundles(client, healthcareDataset + "/fhirStores/" + fhirStoreName, FhirIOTestUtil.BUNDLES.get(version));
}
use of org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.SubscriptionPath in project beam by apache.
the class PubsubHelper method subscriptionExists.
/**
* Does subscription corresponding to short name exist?
*/
public boolean subscriptionExists(String shortTopic, String shortSubscription) throws IOException {
TopicPath topic = PubsubClient.topicPathFromName(project, shortTopic);
SubscriptionPath subscription = PubsubClient.subscriptionPathFromName(project, shortSubscription);
return pubsubClient.listSubscriptions(PubsubClient.projectPathFromId(project), topic).stream().anyMatch(subscription::equals);
}
use of org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.SubscriptionPath in project beam by apache.
the class TestPubsubSignal method waitForStart.
/**
* Future that waits for a start signal for {@code duration}.
*
* <p>This future must be created before running the pipeline. A subscription must exist prior to
* the start signal being published, which occurs immediately upon pipeline startup.
*/
public Supplier<Void> waitForStart(Duration duration) throws IOException {
SubscriptionPath startSubscriptionPath = PubsubClient.subscriptionPathFromName(pipelineOptions.getProject(), "start-subscription-" + String.valueOf(ThreadLocalRandom.current().nextLong()));
subscriptionAdmin.createSubscription(startSubscriptionPath.getPath(), startTopicPath.getPath(), PushConfig.getDefaultInstance(), (int) duration.getStandardSeconds());
return Suppliers.memoize(() -> {
try {
String result = pollForResultForDuration(startSubscriptionPath, duration);
checkState(START_SIGNAL_MESSAGE.equals(result));
return null;
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
try {
subscriptionAdmin.deleteSubscription(startSubscriptionPath.getPath());
} catch (ApiException e) {
LOG.error(String.format("Leaked PubSub subscription '%s'", startSubscriptionPath));
}
}
});
}
use of org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.SubscriptionPath in project beam by apache.
the class TestPubsubSignal method waitForSuccess.
/**
* Wait for a success signal for {@code duration}.
*/
public void waitForSuccess(Duration duration) throws IOException {
SubscriptionPath resultSubscriptionPath = PubsubClient.subscriptionPathFromName(pipelineOptions.getProject(), "result-subscription-" + String.valueOf(ThreadLocalRandom.current().nextLong()));
subscriptionAdmin.createSubscription(resultSubscriptionPath.getPath(), resultTopicPath.getPath(), PushConfig.getDefaultInstance(), (int) duration.getStandardSeconds());
String result = pollForResultForDuration(resultSubscriptionPath, duration);
try {
subscriptionAdmin.deleteSubscription(resultSubscriptionPath.getPath());
} catch (ApiException e) {
LOG.error(String.format("Leaked PubSub subscription '%s'", resultSubscriptionPath));
}
if (!RESULT_SUCCESS_MESSAGE.equals(result)) {
throw new AssertionError(result);
}
}
use of org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.SubscriptionPath 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);
}
}
Aggregations