• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java PushConfig类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中com.google.pubsub.v1.PushConfig的典型用法代码示例。如果您正苦于以下问题:Java PushConfig类的具体用法?Java PushConfig怎么用?Java PushConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

PushConfig类属于com.google.pubsub.v1包,在下文中一共展示了PushConfig类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createSubscription

点赞 3

import com.google.pubsub.v1.PushConfig; //导入依赖的package包/类
/**
 * Create a new subscription on Google Cloud Pub/Sub.
 *
 * @param subscriptionName the name of the new subscription
 * @param topicName the name of the topic being subscribed to
 * @param ackDeadline deadline in seconds before a message is resent. If not provided, set to
 *                    default of 10 seconds
 * @param pushEndpoint URL of the service receiving the push messages. If not provided, uses
 *                     message pulling by default
 * @return the created subscription
 */
public Subscription createSubscription(String subscriptionName, String topicName,
		Integer ackDeadline, String pushEndpoint) {
	Assert.hasText(subscriptionName, "No subscription name was specified.");
	Assert.hasText(topicName, "No topic name was specified.");

	int finalAckDeadline = this.defaultAckDeadline;
	if (ackDeadline != null) {
		Assert.isTrue(ackDeadline >= 0,
				"The acknowledgement deadline value can't be negative.");
		finalAckDeadline = ackDeadline;
	}

	PushConfig.Builder pushConfigBuilder = PushConfig.newBuilder();
	if (pushEndpoint != null) {
		pushConfigBuilder.setPushEndpoint(pushEndpoint);
	}

	return this.subscriptionAdminClient.createSubscription(
			SubscriptionName.of(this.projectId, subscriptionName),
			TopicName.of(this.projectId, topicName),
			pushConfigBuilder.build(),
			finalAckDeadline);
}
 

开发者ID:spring-cloud,
项目名称:spring-cloud-gcp,
代码行数:35,
代码来源:PubSubAdmin.java

示例2: main

点赞 2

import com.google.pubsub.v1.PushConfig; //导入依赖的package包/类
/**
 * Create a pull subscription.
 *
 * @param args topic subscriptionId
 * @throws Exception exception thrown if operation is unsuccessful
 */
public static void main(String... args) throws Exception {

  // Your Google Cloud Platform project ID
  String projectId = ServiceOptions.getDefaultProjectId();

  // Your topic ID, eg. "my-topic"
  String topicId = args[0];

  // Your subscription ID eg. "my-sub"
  String subscriptionId = args[1];

  TopicName topicName = TopicName.of(projectId, topicId);

  // Create a new subscription
  SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId);
  try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
    // create a pull subscription with default acknowledgement deadline (= 10 seconds)
    Subscription subscription =
        subscriptionAdminClient.createSubscription(
            subscriptionName, topicName, PushConfig.getDefaultInstance(), 0);
  } catch (ApiException e) {
    // example : code = ALREADY_EXISTS(409) implies subscription already exists
    System.out.print(e.getStatusCode().getCode());
    System.out.print(e.isRetryable());
  }

  System.out.printf(
      "Subscription %s:%s created.\n",
      subscriptionName.getProject(), subscriptionName.getSubscription());
}
 

开发者ID:GoogleCloudPlatform,
项目名称:java-docs-samples,
代码行数:37,
代码来源:CreatePullSubscriptionExample.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)