本文整理汇总了Java中com.google.cloud.pubsub.TopicInfo类的典型用法代码示例。如果您正苦于以下问题:Java TopicInfo类的具体用法?Java TopicInfo怎么用?Java TopicInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TopicInfo类属于com.google.cloud.pubsub包,在下文中一共展示了TopicInfo类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: declareTopic
import com.google.cloud.pubsub.TopicInfo; //导入依赖的package包/类
public TopicInfo declareTopic(String name, String prefix, Integer partitionIndex) {
TopicInfo topic = null;
String topicName = createTopicName(name, prefix, partitionIndex);
try {
logger.debug("Creating topic: {} ",topic);
topic = client.create(TopicInfo.of(topicName));
}
catch (PubSubException e) {
if (e.reason().equals(PubSubBinder.ALREADY_EXISTS)) {
logger.warn("Topic: {} already exists, reusing definition from remote server",topicName);
topic = Topic.of(topicName);
}
}
return topic;
}
开发者ID:viniciusccarvalho,项目名称:spring-cloud-stream-binder-pubsub,代码行数:18,代码来源:PubSubResourceManager.java
示例2: createProducerDestinationIfNecessary
import com.google.cloud.pubsub.TopicInfo; //导入依赖的package包/类
@Override
protected List<TopicInfo> createProducerDestinationIfNecessary(String name,
ExtendedProducerProperties<PubSubProducerProperties> properties) {
Integer partitionIndex = null;
List<TopicInfo> topics = new LinkedList<>();
if (properties.isPartitioned()) {
for (int i = 0; i < properties.getPartitionCount(); i++) {
if (properties.isPartitioned())
partitionIndex = i;
TopicInfo topic = resourceManager.declareTopic(name,
properties.getExtension().getPrefix(), partitionIndex);
topics.add(topic);
}
}
else {
topics.add(resourceManager.declareTopic(name,
properties.getExtension().getPrefix(), null));
}
return topics;
}
开发者ID:viniciusccarvalho,项目名称:spring-cloud-stream-binder-pubsub,代码行数:23,代码来源:PubSubMessageChannelBinder.java
示例3: createProducerMessageHandler
import com.google.cloud.pubsub.TopicInfo; //导入依赖的package包/类
@Override
protected MessageHandler createProducerMessageHandler(List<TopicInfo> destinations,
ExtendedProducerProperties<PubSubProducerProperties> producerProperties)
throws Exception {
PubSubMessageHandler handler = null;
if (producerProperties.getExtension().isBatchEnabled()) {
handler = new BatchingPubSubMessageHandler(resourceManager,
producerProperties, destinations);
((BatchingPubSubMessageHandler) handler)
.setConcurrency(producerProperties.getExtension().getConcurrency());
}
else {
handler = new SimplePubSubMessageHandler(resourceManager, producerProperties,
destinations);
}
resourceManager.createRequiredMessageGroups(destinations, producerProperties);
return handler;
}
开发者ID:viniciusccarvalho,项目名称:spring-cloud-stream-binder-pubsub,代码行数:22,代码来源:PubSubMessageChannelBinder.java
示例4: createNonPartitionedSubscription
import com.google.cloud.pubsub.TopicInfo; //导入依赖的package包/类
@Test
public void createNonPartitionedSubscription() throws Exception {
PubSubProducerProperties properties = new PubSubProducerProperties();
ExtendedProducerProperties<PubSubProducerProperties> producerProperties = new ExtendedProducerProperties<>(properties);
producerProperties.setRequiredGroups("hdfs", "average");
producerProperties.getExtension().setPrefix("createNonPartitionedSubscription");
List<TopicInfo> topics = new ArrayList<>();
topics.add(resourceManager.declareTopic("test",properties.getPrefix(),null));
resourceManager.createRequiredMessageGroups(topics,producerProperties);
Topic topic = pubSub.getTopic(topics.get(0).name());
Assert.assertNotNull(topic);
topic.listSubscriptions().iterateAll().forEachRemaining(subscriptionId -> {
Assert.assertTrue(subscriptionId.subscription().startsWith("createNonPartitionedSubscription.test."));
});
resourceManager.deleteTopics(topics);
}
开发者ID:viniciusccarvalho,项目名称:spring-cloud-stream-binder-pubsub,代码行数:21,代码来源:ResourceManagerTests.java
示例5: createPartitionedSubscription
import com.google.cloud.pubsub.TopicInfo; //导入依赖的package包/类
@Test
public void createPartitionedSubscription() throws Exception {
PubSubProducerProperties properties = new PubSubProducerProperties();
ExtendedProducerProperties<PubSubProducerProperties> producerProperties = new ExtendedProducerProperties<>(properties);
producerProperties.setRequiredGroups("hdfs", "average");
producerProperties.getExtension().setPrefix("createPartitionedSubscription");
List<TopicInfo> topics = new ArrayList<>();
for(int i=0;i<2;i++){
topics.add(resourceManager.declareTopic("test",properties.getPrefix(),i));
}
resourceManager.createRequiredMessageGroups(topics,producerProperties);
for(int i=0;i<2;i++){
Topic topic = pubSub.getTopic(topics.get(i).name());
Assert.assertNotNull(topic);
topic.listSubscriptions().values().forEach(subscriptionId -> {
Assert.assertTrue(subscriptionId.subscription().startsWith("createPartitionedSubscription.test-"));
});
}
resourceManager.deleteTopics(topics);
}
开发者ID:viniciusccarvalho,项目名称:spring-cloud-stream-binder-pubsub,代码行数:26,代码来源:ResourceManagerTests.java
示例6: consumeMessages
import com.google.cloud.pubsub.TopicInfo; //导入依赖的package包/类
@Test
public void consumeMessages() throws Exception {
int messageCount = 2000;
final AtomicInteger counter = new AtomicInteger(0);
CountDownLatch latch = new CountDownLatch(messageCount);
String baseTopicName = "pubsub-test";
ExtendedProducerProperties<PubSubProducerProperties> extendedProducerProperties = new ExtendedProducerProperties<>(new PubSubProducerProperties());
List<TopicInfo> topics = new ArrayList<>();
topics.add(resourceManager.declareTopic(baseTopicName,"",null));
SubscriptionInfo subscriptionInfo = resourceManager.declareSubscription(topics.get(0).name(),"test-subscription","");
PubSubMessageHandler messageHandler = new BatchingPubSubMessageHandler(resourceManager,extendedProducerProperties,topics);
messageHandler.start();
resourceManager.createConsumer(subscriptionInfo, message -> {
counter.incrementAndGet();
latch.countDown();
});
for(int j=0;j<messageCount;j++){
String payload = "foo-"+j;
messageHandler.handleMessage(MessageBuilder.withPayload(payload.getBytes()).build());
}
latch.await();
Assert.assertEquals(messageCount,counter.get());
}
开发者ID:viniciusccarvalho,项目名称:spring-cloud-stream-binder-pubsub,代码行数:25,代码来源:PubSubMessageHandlerTests.java
示例7: PubSubMessageHandler
import com.google.cloud.pubsub.TopicInfo; //导入依赖的package包/类
public PubSubMessageHandler(PubSubResourceManager resourceManager,
ExtendedProducerProperties<PubSubProducerProperties> producerProperties,
List<TopicInfo> topics) {
this.resourceManager = resourceManager;
this.producerProperties = producerProperties;
this.mapper = new ObjectMapper();
this.topics = topics;
}
开发者ID:viniciusccarvalho,项目名称:spring-cloud-stream-binder-pubsub,代码行数:9,代码来源:PubSubMessageHandler.java
示例8: createRequiredMessageGroups
import com.google.cloud.pubsub.TopicInfo; //导入依赖的package包/类
public void createRequiredMessageGroups(List<TopicInfo> destinations,
ExtendedProducerProperties<PubSubProducerProperties> producerProperties) {
for (String requiredGroupName : producerProperties.getRequiredGroups()) {
for (int i = 0; i < producerProperties.getPartitionCount(); i++) {
String name = destinations.get(i).name();
declareSubscription(destinations.get(i).name(), name, requiredGroupName);
}
}
}
开发者ID:viniciusccarvalho,项目名称:spring-cloud-stream-binder-pubsub,代码行数:11,代码来源:PubSubResourceManager.java
示例9: createConsumerDestinationIfNecessary
import com.google.cloud.pubsub.TopicInfo; //导入依赖的package包/类
@Override
protected Subscription createConsumerDestinationIfNecessary(String name, String group,
ExtendedConsumerProperties<PubSubConsumerProperties> properties) {
boolean partitioned = properties.isPartitioned();
Integer partitionIndex = null;
if (partitioned) {
partitionIndex = properties.getInstanceIndex();
}
TopicInfo topicInfo = resourceManager.declareTopic(name,
properties.getExtension().getPrefix(), partitionIndex);
SubscriptionInfo subscription = resourceManager
.declareSubscription(topicInfo.name(), topicInfo.name(), group);
return resourceManager.createSubscription(subscription);
}
开发者ID:viniciusccarvalho,项目名称:spring-cloud-stream-binder-pubsub,代码行数:15,代码来源:PubSubMessageChannelBinder.java
示例10: deleteTopics
import com.google.cloud.pubsub.TopicInfo; //导入依赖的package包/类
public void deleteTopics(List<TopicInfo> topics) {
for (TopicInfo t : topics) {
client.deleteTopic(t.name());
}
}
开发者ID:viniciusccarvalho,项目名称:spring-cloud-stream-binder-pubsub,代码行数:6,代码来源:PubSubResourceManager.java
示例11: BatchingPubSubMessageHandler
import com.google.cloud.pubsub.TopicInfo; //导入依赖的package包/类
public BatchingPubSubMessageHandler(PubSubResourceManager resourceManager, ExtendedProducerProperties<PubSubProducerProperties> producerProperties, List<TopicInfo> topics) {
super(resourceManager, producerProperties, topics);
this.processor = WorkQueueProcessor.share(true);
}
开发者ID:viniciusccarvalho,项目名称:spring-cloud-stream-binder-pubsub,代码行数:5,代码来源:BatchingPubSubMessageHandler.java
示例12: SimplePubSubMessageHandler
import com.google.cloud.pubsub.TopicInfo; //导入依赖的package包/类
public SimplePubSubMessageHandler(PubSubResourceManager resourceManager, ExtendedProducerProperties<PubSubProducerProperties> producerProperties, List<TopicInfo> topics) {
super(resourceManager, producerProperties, topics);
}
开发者ID:viniciusccarvalho,项目名称:spring-cloud-stream-binder-pubsub,代码行数:4,代码来源:SimplePubSubMessageHandler.java