当前位置: 首页>>代码示例>>Java>>正文


Java PublishResponse类代码示例

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


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

示例1: testFlushWithPublishInPut

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

import com.google.pubsub.v1.PublishResponse; //导入依赖的package包/类
@Override
public void flush(Map<TopicPartition, OffsetAndMetadata> partitionOffsets) {
  log.debug("Flushing...");
  // Publish all messages that have not been published yet.
  for (Map.Entry<String, Map<Integer, UnpublishedMessagesForPartition>> entry :
      allUnpublishedMessages.entrySet()) {
    for (Map.Entry<Integer, UnpublishedMessagesForPartition> innerEntry :
        entry.getValue().entrySet()) {
      publishMessagesForPartition(
          entry.getKey(), innerEntry.getKey(), innerEntry.getValue().messages);
    }
  }
  allUnpublishedMessages.clear();
  // Process results of all the outstanding futures specified by each TopicPartition.
  for (Map.Entry<TopicPartition, OffsetAndMetadata> partitionOffset :
      partitionOffsets.entrySet()) {
    log.trace("Received flush for partition " + partitionOffset.getKey().toString());
    Map<Integer, OutstandingFuturesForPartition> outstandingFuturesForTopic =
        allOutstandingFutures.get(partitionOffset.getKey().topic());
    if (outstandingFuturesForTopic == null) {
      continue;
    }
    OutstandingFuturesForPartition outstandingFutures =
        outstandingFuturesForTopic.get(partitionOffset.getKey().partition());
    if (outstandingFutures == null) {
      continue;
    }
    try {
      for (ListenableFuture<PublishResponse> publishFuture : outstandingFutures.futures) {
        publishFuture.get();
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
  allOutstandingFutures.clear();
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:38,代码来源:CloudPubSubSinkTask.java

示例3: testFlushWithNoPublishInPut

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

示例4: testFlushExceptionCase

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

示例5: publish

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

示例6: publish

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

示例7: publish

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

示例8: publishOneMessage

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

示例9: publish

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


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