com.google.pubsub.v1.Subscription toPb(String projectId) { com.google.pubsub.v1.Subscription.Builder builder = com.google.pubsub.v1.Subscription.newBuilder(); builder.setTopic(topic.toPb(projectId)); builder.setName(SubscriberApi.formatSubscriptionName(projectId, name)); builder.setAckDeadlineSeconds(ackDeadlineSeconds); if (pushConfig != null) { builder.setPushConfig(pushConfig.toPb()); } return builder.build(); }
static SubscriptionInfo fromPb(com.google.pubsub.v1.Subscription subscription) { Builder builder = builder( TopicId.fromPb(subscription.getTopic()), SubscriberApi.parseSubscriptionFromSubscriptionName(subscription.getName())); builder.ackDeadLineSeconds(subscription.getAckDeadlineSeconds()); // A subscription with an "empty" push config is a pull subscription if (subscription.hasPushConfig() && !subscription.getPushConfig().getPushEndpoint().equals("")) { builder.pushConfig(PushConfig.fromPb(subscription.getPushConfig())); } return builder.build(); }
/** * Creates a push {@code SubscriptionInfo} object given the identity of the topic, the name of the * subscription and the push endpoint. If {@code topic.project()} is {@code null} the topic is * assumed to reside in the {@link PubSubOptions#projectId()} project. * * @param topic the identity of the topic the subscription refers to * @param name the name of the subscription. The name must start with a letter, and contain only * letters ({@code [A-Za-z]}), numbers ({@code [0-9]}), dashes ({@code -}), underscores * ({@code _}), periods ({@code .}), tildes ({@code ~}), plus ({@code +}) or percent signs * ({@code %}). It must be between 3 and 255 characters in length and cannot begin with the * string {@code goog}. * @param endpoint a URL locating the endpoint to which messages should be pushed. For example, an * endpoint might use {@code https://example.com/push}. */ public static SubscriptionInfo of(TopicId topic, String name, String endpoint) { return builder(topic, name).pushConfig(PushConfig.of(endpoint)).build(); }
/** Forms listen URL based on port number */ public static String formPushListenUrl() { String url = "http://:" + PushConfig.getPort(); url += getConnectionSuffix(); return url; }