• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SubscriptionName类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: createSubscription

import com.google.pubsub.v1.SubscriptionName; //导入依赖的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: createPullRequest

import com.google.pubsub.v1.SubscriptionName; //导入依赖的package包/类
@Override
public PullRequest createPullRequest(String subscriptionName, Integer maxMessages,
		Boolean returnImmediately) {
	Assert.hasLength(subscriptionName, "The subscription name must be provided.");

	PullRequest.Builder pullRequestBuilder =
			PullRequest.newBuilder().setSubscriptionWithSubscriptionName(
					SubscriptionName.of(this.projectId, subscriptionName));

	if (maxMessages != null) {
		pullRequestBuilder.setMaxMessages(maxMessages);
	}

	if (returnImmediately != null) {
		pullRequestBuilder.setReturnImmediately(returnImmediately);
	}

	return pullRequestBuilder.build();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:20,代码来源:DefaultSubscriberFactory.java


示例3: getSubscription

import com.google.pubsub.v1.SubscriptionName; //导入依赖的package包/类
/**
 * Get the configuration of a Google Cloud Pub/Sub subscription.
 *
 * @param subscriptionName canonical subscription name, e.g., "subscriptionName"
 * @return subscription configuration or {@code null} if subscription doesn't exist
 */
public Subscription getSubscription(String subscriptionName) {
	Assert.hasText(subscriptionName, "No subscription name was specified");

	try {
		return this.subscriptionAdminClient.getSubscription(
				SubscriptionName.create(this.projectId, subscriptionName));
	}
	catch (ApiException aex) {
		if (aex.getStatusCode().getCode() == StatusCode.Code.NOT_FOUND) {
			return null;
		}

		throw aex;
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:22,代码来源:PubSubAdmin.java


示例4: main

import com.google.pubsub.v1.SubscriptionName; //导入依赖的package包/类
/** Receive messages over a subscription. */
public static void main(String... args) throws Exception {
  // set subscriber id, eg. my-sub
  String subscriptionId = args[0];
  SubscriptionName subscriptionName = SubscriptionName.of(PROJECT_ID, subscriptionId);
  Subscriber subscriber = null;
  try {
    // create a subscriber bound to the asynchronous message receiver
    subscriber =
        Subscriber.newBuilder(subscriptionName, new MessageReceiverExample()).build();
    subscriber.startAsync().awaitRunning();
    // Continue to listen to messages
    while (true) {
      PubsubMessage message = messages.take();
      System.out.println("Message Id: " + message.getMessageId());
      System.out.println("Data: " + message.getData().toStringUtf8());
    }
  } finally {
    if (subscriber != null) {
      subscriber.stopAsync();
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:24,代码来源:SubscriberExample.java


示例5: createSubscriber

import com.google.pubsub.v1.SubscriptionName; //导入依赖的package包/类
@Override
public Subscriber createSubscriber(String subscriptionName, MessageReceiver receiver) {
	Subscriber.Builder subscriberBuilder = Subscriber.newBuilder(
			SubscriptionName.of(this.projectId, subscriptionName), receiver);

	if (this.channelProvider != null) {
		subscriberBuilder.setChannelProvider(this.channelProvider);
	}

	if (this.executorProvider != null) {
		subscriberBuilder.setExecutorProvider(this.executorProvider);
	}

	if (this.credentialsProvider != null) {
		subscriberBuilder.setCredentialsProvider(this.credentialsProvider);
	}

	if (this.headerProvider != null) {
		subscriberBuilder.setHeaderProvider(this.headerProvider);
	}

	if (this.systemExecutorProvider != null) {
		subscriberBuilder.setSystemExecutorProvider(this.systemExecutorProvider);
	}

	if (this.flowControlSettings != null) {
		subscriberBuilder.setFlowControlSettings(this.flowControlSettings);
	}

	if (this.maxAckDurationPeriod != null) {
		subscriberBuilder.setMaxAckExtensionPeriod(this.maxAckDurationPeriod);
	}

	if (this.parallelPullCount != null) {
		subscriberBuilder.setParallelPullCount(this.parallelPullCount);
	}

	return subscriberBuilder.build();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:40,代码来源:DefaultSubscriberFactory.java


示例6: deleteSubscription

import com.google.pubsub.v1.SubscriptionName; //导入依赖的package包/类
/**
 * Delete a subscription from Google Cloud Pub/Sub.
 *
 * @param subscriptionName
 */
public void deleteSubscription(String subscriptionName) {
	Assert.hasText(subscriptionName, "No subscription name was specified");

	this.subscriptionAdminClient.deleteSubscription(
			SubscriptionName.of(this.projectId, subscriptionName));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:12,代码来源:PubSubAdmin.java


示例7: forceDeleteSubscription

import com.google.pubsub.v1.SubscriptionName; //导入依赖的package包/类
public void forceDeleteSubscription(QueueSubscriber qsubscriber) {
    SubscriptionName subscriptionName = SubscriptionName.create(projectId, qsubscriber.getSubscriberId());
    try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
        subscriptionAdminClient.deleteSubscription(subscriptionName);
    } catch (Exception ioe) {
        System.err.println(ExceptionToString.format(ioe));
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:9,代码来源:PubsubPipeline2Handler.java


示例8: CPSSubscriberTask

import com.google.pubsub.v1.SubscriptionName; //导入依赖的package包/类
private CPSSubscriberTask(StartRequest request) {
  super(request, "gcloud", MetricsHandler.MetricName.END_TO_END_LATENCY);
  this.subscription =
      SubscriptionName.create(request.getProject(), request.getPubsubOptions().getSubscription());
  try {
    this.subscriber =
        Subscriber.defaultBuilder(this.subscription, this)
            .setParallelPullCount(Runtime.getRuntime().availableProcessors() * 5)
            .build();
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:14,代码来源:CPSSubscriberTask.java


示例9: main

import com.google.pubsub.v1.SubscriptionName; //导入依赖的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


示例10: deleteTestSubscription

import com.google.pubsub.v1.SubscriptionName; //导入依赖的package包/类
private void deleteTestSubscription() throws Exception {
  try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
    subscriptionAdminClient.deleteSubscription(
        SubscriptionName.of(projectId, subscriptionId));
  } catch (IOException e) {
    System.err.println("Error deleting subscription " + e.getMessage());
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:9,代码来源:QuickStartIT.java


示例11: produce

import com.google.pubsub.v1.SubscriptionName; //导入依赖的package包/类
@Override
public void produce(Map<String, String> lastOffsets, int maxBatchSize) throws StageException {
  SynchronousQueue<MessageReplyConsumerBundle> workQueue = new SynchronousQueue<>();

  SubscriptionName subscriptionName = SubscriptionName.create(conf.credentials.projectId, conf.subscriptionId);

  executor = Executors.newFixedThreadPool(getNumberOfThreads());

  for (int i = 0; i < conf.maxThreads; i++) {
    MessageProcessor messageProcessor = new MessageProcessorImpl(
        getContext(),
        Math.min(maxBatchSize, conf.basic.maxBatchSize),
        conf.basic.maxWaitTime,
        parserFactory,
        workQueue
    );
    executor.submit(messageProcessor);
    messageProcessors.add(messageProcessor);
  }

  ExecutorProvider executorProvider = InstantiatingExecutorProvider.newBuilder()
      .setExecutorThreadCount(conf.advanced.numThreadsPerSubscriber)
      .build();

  ChannelProvider channelProvider = getChannelProvider();
  FlowControlSettings flowControlSettings = getFlowControlSettings();

  for (int i = 0; i < conf.advanced.numSubscribers; i++) {
    Subscriber s = Subscriber.defaultBuilder(subscriptionName, new MessageReceiverImpl(workQueue))
        .setCredentialsProvider(credentialsProvider)
        .setExecutorProvider(executorProvider)
        .setChannelProvider(channelProvider)
        .setFlowControlSettings(flowControlSettings)
        .build();
    s.addListener(new Subscriber.Listener() {
      @Override
      public void failed(Subscriber.State from, Throwable failure) {
        LOG.error("Exception thrown in Subscriber: {}", failure.toString(), failure);
        LOG.error("Subscriber state: {}", from.toString());
        Throwables.propagate(failure);
      }
    }, MoreExecutors.directExecutor());
    subscribers.add(s);
  }

  try {
    subscribers.forEach(Subscriber::startAsync);
  } finally {
    LOG.info("Started {} subscribers.", conf.maxThreads);
  }

  while (!getContext().isStopped()) {
    ThreadUtil.sleep(1000);
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:56,代码来源:PubSubSource.java



注:本文中的com.google.pubsub.v1.SubscriptionName类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ClientSOAPHandlerTube类代码示例发布时间:2022-05-23
下一篇:
Java MenuFactory类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap