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

Java PublishRequest类代码示例

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

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



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

示例1: testFlushWithPublishInPut

import com.google.pubsub.v1.PublishRequest; //导入依赖的package包/类
/**
 * Tests that a call to flush() processes the Futures that were generated during a previous
 * call to put() (i.e enough messages were buffered in put() to trigger a publish).
 */
@Test
public void testFlushWithPublishInPut() throws Exception {
  props.put(CloudPubSubSinkConnector.MAX_BUFFER_SIZE_CONFIG, CPS_MIN_BATCH_SIZE1);
  task.start(props);
  List<SinkRecord> records = getSampleRecords();
  ListenableFuture<PublishResponse> goodFuture =
      spy(Futures.immediateFuture(PublishResponse.getDefaultInstance()));
  when(publisher.publish(any(PublishRequest.class))).thenReturn(goodFuture);
  task.put(records);
  Map<TopicPartition, OffsetAndMetadata> partitionOffsets = new HashMap<>();
  partitionOffsets.put(new TopicPartition(KAFKA_TOPIC, 0), null);
  task.flush(partitionOffsets);
  verify(goodFuture, times(1)).get();
  ArgumentCaptor<PublishRequest> captor = ArgumentCaptor.forClass(PublishRequest.class);
  verify(publisher, times(1)).publish(captor.capture());
  PublishRequest requestArg = captor.getValue();
  assertEquals(requestArg.getMessagesList(), getPubsubMessagesFromSampleRecords());
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:23,代码来源:CloudPubSubSinkTaskTest.java


示例2: publishMessagesForPartition

import com.google.pubsub.v1.PublishRequest; //导入依赖的package包/类
/** Publish all the messages in a partition and store the Future's for each publish request. */
private void publishMessagesForPartition(
    String topic, Integer partition, List<PubsubMessage> messages) {
  // Get a map containing all futures per partition for the passed in topic.
  Map<Integer, OutstandingFuturesForPartition> outstandingFuturesForTopic =
      allOutstandingFutures.get(topic);
  if (outstandingFuturesForTopic == null) {
    outstandingFuturesForTopic = new HashMap<>();
    allOutstandingFutures.put(topic, outstandingFuturesForTopic);
  }
  // Get the object containing the outstanding futures for this topic and partition..
  OutstandingFuturesForPartition outstandingFutures = outstandingFuturesForTopic.get(partition);
  if (outstandingFutures == null) {
    outstandingFutures = new OutstandingFuturesForPartition();
    outstandingFuturesForTopic.put(partition, outstandingFutures);
  }
  int startIndex = 0;
  int endIndex = Math.min(CPS_MAX_MESSAGES_PER_REQUEST, messages.size());
  PublishRequest.Builder builder = PublishRequest.newBuilder();
  // Publish all the messages for this partition in batches.
  while (startIndex < messages.size()) {
    PublishRequest request =
        builder.setTopic(cpsTopic).addAllMessages(messages.subList(startIndex, endIndex)).build();
    builder.clear();
    log.trace("Publishing: " + (endIndex - startIndex) + " messages");
    outstandingFutures.futures.add(publisher.publish(request));
    startIndex = endIndex;
    endIndex = Math.min(endIndex + CPS_MAX_MESSAGES_PER_REQUEST, messages.size());
  }
  messages.clear();
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:32,代码来源:CloudPubSubSinkTask.java


示例3: testPutWhereNoPublishesAreInvoked

import com.google.pubsub.v1.PublishRequest; //导入依赖的package包/类
/**
 * Tests that if there are not enough messages buffered, publisher.publish() is not invoked.
 */
@Test
public void testPutWhereNoPublishesAreInvoked() {
  task.start(props);
  List<SinkRecord> records = getSampleRecords();
  task.put(records);
  verify(publisher, never()).publish(any(PublishRequest.class));
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:11,代码来源:CloudPubSubSinkTaskTest.java


示例4: testPutWherePublishesAreInvoked

import com.google.pubsub.v1.PublishRequest; //导入依赖的package包/类
/**
 * Tests that if there are enough messages buffered, that the PublishRequest sent to the publisher
 * is correct.
 */
@Test
public void testPutWherePublishesAreInvoked() {
  props.put(CloudPubSubSinkConnector.MAX_BUFFER_SIZE_CONFIG, CPS_MIN_BATCH_SIZE1);
  task.start(props);
  List<SinkRecord> records = getSampleRecords();
  task.put(records);
  ArgumentCaptor<PublishRequest> captor = ArgumentCaptor.forClass(PublishRequest.class);
  verify(publisher, times(1)).publish(captor.capture());
  PublishRequest requestArg = captor.getValue();
  assertEquals(requestArg.getMessagesList(), getPubsubMessagesFromSampleRecords());
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:16,代码来源:CloudPubSubSinkTaskTest.java


示例5: testFlushWithNoPublishInPut

import com.google.pubsub.v1.PublishRequest; //导入依赖的package包/类
/**
 * Tests that a call to flush() processes the Futures that were generated during this same call
 * to flush() (i.e buffered messages were not published until the call to flush()).
 */
@Test
public void testFlushWithNoPublishInPut() throws Exception {
  task.start(props);
  Map<TopicPartition, OffsetAndMetadata> partitionOffsets = new HashMap<>();
  partitionOffsets.put(new TopicPartition(KAFKA_TOPIC, 0), null);
  List<SinkRecord> records = getSampleRecords();
  ListenableFuture<PublishResponse> goodFuture =
      spy(Futures.immediateFuture(PublishResponse.getDefaultInstance()));
  when(publisher.publish(any(PublishRequest.class))).thenReturn(goodFuture);
  task.put(records);
  task.flush(partitionOffsets);
  verify(publisher, times(1)).publish(any(PublishRequest.class));
  verify(goodFuture, times(1)).get();
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:19,代码来源:CloudPubSubSinkTaskTest.java


示例6: testFlushExceptionCase

import com.google.pubsub.v1.PublishRequest; //导入依赖的package包/类
/**
 * Tests that if a Future that is being processed in flush() failed with an exception, that an
 * exception is thrown.
 */
@Test(expected = RuntimeException.class)
public void testFlushExceptionCase() throws Exception {
  task.start(props);
  Map<TopicPartition, OffsetAndMetadata> partitionOffsets = new HashMap<>();
  partitionOffsets.put(new TopicPartition(KAFKA_TOPIC, 0), null);
  List<SinkRecord> records = getSampleRecords();
  ListenableFuture<PublishResponse> badFuture = spy(Futures.<PublishResponse>immediateFailedFuture(new Exception()));
  when(publisher.publish(any(PublishRequest.class))).thenReturn(badFuture);
  task.put(records);
  task.flush(partitionOffsets);
  verify(publisher, times(1)).publish(any(PublishRequest.class));
  verify(badFuture, times(1)).get();
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:18,代码来源:CloudPubSubSinkTaskTest.java


示例7: publish

import com.google.pubsub.v1.PublishRequest; //导入依赖的package包/类
@Override
public int publish(TopicPath topic, List<OutgoingMessage> outgoingMessages)
    throws IOException {
  PublishRequest.Builder request = PublishRequest.newBuilder()
                                                 .setTopic(topic.getPath());
  for (OutgoingMessage outgoingMessage : outgoingMessages) {
    PubsubMessage.Builder message =
        PubsubMessage.newBuilder()
                     .setData(ByteString.copyFrom(outgoingMessage.elementBytes));

    if (outgoingMessage.attributes != null) {
      message.putAllAttributes(outgoingMessage.attributes);
    }

    if (timestampAttribute != null) {
      message.getMutableAttributes()
             .put(timestampAttribute, String.valueOf(outgoingMessage.timestampMsSinceEpoch));
    }

    if (idAttribute != null && !Strings.isNullOrEmpty(outgoingMessage.recordId)) {
      message.getMutableAttributes().put(idAttribute, outgoingMessage.recordId);
    }

    request.addMessages(message);
  }

  PublishResponse response = publisherStub().publish(request.build());
  return response.getMessageIdsCount();
}
 
开发者ID:apache,项目名称:beam,代码行数:30,代码来源:PubsubGrpcClient.java


示例8: publish

import com.google.pubsub.v1.PublishRequest; //导入依赖的package包/类
@Override
public ListenableFuture<PublishResponse> publish(PublishRequest request) {
  return publisher.publish(request);
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:5,代码来源:CloudPubSubGRPCPublisher.java


示例9: publish

import com.google.pubsub.v1.PublishRequest; //导入依赖的package包/类
@Override
public ListenableFuture<PublishResponse> publish(PublishRequest request) {
  currentPublisherIndex = (currentPublisherIndex + 1) % publishers.size();
  return publishers.get(currentPublisherIndex).publish(request);
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:6,代码来源:CloudPubSubRoundRobinPublisher.java


示例10: publishOneMessage

import com.google.pubsub.v1.PublishRequest; //导入依赖的package包/类
@Test
public void publishOneMessage() throws IOException {
  String expectedTopic = TOPIC.getPath();
  PubsubMessage expectedPubsubMessage =
      PubsubMessage.newBuilder()
                   .setData(ByteString.copyFrom(DATA.getBytes()))
                   .putAllAttributes(ATTRIBUTES)
                   .putAllAttributes(
                       ImmutableMap.of(TIMESTAMP_ATTRIBUTE, String.valueOf(MESSAGE_TIME),
                                       ID_ATTRIBUTE, RECORD_ID))
                   .build();
  final PublishRequest expectedRequest =
      PublishRequest.newBuilder()
                    .setTopic(expectedTopic)
                    .addAllMessages(
                        ImmutableList.of(expectedPubsubMessage))
                    .build();
  final PublishResponse response =
      PublishResponse.newBuilder()
                     .addAllMessageIds(ImmutableList.of(MESSAGE_ID))
                     .build();

  final List<PublishRequest> requestsReceived = new ArrayList<>();
  PublisherImplBase publisherImplBase = new PublisherImplBase() {
    @Override
    public void publish(
        PublishRequest request, StreamObserver<PublishResponse> responseObserver) {
      requestsReceived.add(request);
      responseObserver.onNext(response);
      responseObserver.onCompleted();
    }
  };
  Server server = InProcessServerBuilder.forName(channelName)
      .addService(publisherImplBase)
      .build()
      .start();
  try {
    OutgoingMessage actualMessage = new OutgoingMessage(
            DATA.getBytes(), ATTRIBUTES, MESSAGE_TIME, RECORD_ID);
    int n = client.publish(TOPIC, ImmutableList.of(actualMessage));
    assertEquals(1, n);
    assertEquals(expectedRequest, Iterables.getOnlyElement(requestsReceived));
  } finally {
    server.shutdownNow();
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:47,代码来源:PubsubGrpcClientTest.java


示例11: publish

import com.google.pubsub.v1.PublishRequest; //导入依赖的package包/类
public ListenableFuture<PublishResponse> publish(PublishRequest request); 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:2,代码来源:CloudPubSubPublisher.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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