BatchingSettings.newBuilder() .setElementCountThreshold(10L) .setRequestByteThreshold(1024L) .setDelayThreshold(Duration.ofMillis(10)) .setFlowControlSettings(
BatchingSettings.newBuilder() .setElementCountThreshold(1000L) .setRequestByteThreshold(1048576L) .setDelayThreshold(Duration.ofMillis(50)) .setFlowControlSettings(
BatchingSettings.newBuilder() .setElementCountThreshold(1000L) .setRequestByteThreshold(1048576L) .setDelayThreshold(Duration.ofMillis(50)) .setFlowControlSettings(
.setDelayThreshold(Duration.ofSeconds(1)) .setElementCountThreshold(4L) .setRequestByteThreshold(null) .setFlowControlSettings( FlowControlSettings.newBuilder()
.setDelayThreshold(Duration.ofSeconds(10)) .setElementCountThreshold(2L) .setRequestByteThreshold(1000L) .build(); FlowControlSettings flowControlSettings =
private void createPublisher() { ProjectTopicName fullTopic = ProjectTopicName.of(cpsProject, cpsTopic); com.google.cloud.pubsub.v1.Publisher.Builder builder = com.google.cloud.pubsub.v1.Publisher.newBuilder(fullTopic) .setCredentialsProvider(gcpCredentialsProvider) .setBatchingSettings( BatchingSettings.newBuilder() .setDelayThreshold(Duration.ofMillis(maxDelayThresholdMs)) .setElementCountThreshold(maxBufferSize) .setRequestByteThreshold(maxBufferBytes) .build()) .setRetrySettings( RetrySettings.newBuilder() // All values that are not configurable come from the defaults for the publisher // client library. .setTotalTimeout(Duration.ofMillis(maxTotalTimeoutMs)) .setMaxRpcTimeout(Duration.ofMillis(maxRequestTimeoutMs)) .setInitialRetryDelay(Duration.ofMillis(5)) .setRetryDelayMultiplier(2) .setMaxRetryDelay(Duration.ofMillis(Long.MAX_VALUE)) .setInitialRpcTimeout(Duration.ofSeconds(10)) .setRpcTimeoutMultiplier(2) .build()); try { publisher = builder.build(); } catch (Exception e) { throw new RuntimeException(e); } }
.setDelayThreshold(Duration.ofSeconds(1)) .setElementCountThreshold(2L) .setRequestByteThreshold(1000L) .build(); FlowControlSettings flowControlSettings =
private static Builder createDefault() { Builder builder = new Builder(); builder.setTransportChannelProvider(defaultTransportChannelProvider()); builder.setExecutorProvider(defaultExecutorProviderBuilder().build()); builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); builder.setHeaderProvider(new NoHeaderProvider()); builder.setInternalHeaderProvider(defaultGoogleServiceHeaderProviderBuilder().build()); builder.setStreamWatchdogProvider(FixedWatchdogProvider.create(null)); builder .fakeMethodSimple() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); builder .fakePagedMethod() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); builder .fakeMethodBatching() .setBatchingSettings( BatchingSettings.newBuilder() .setElementCountThreshold(800L) .setRequestByteThreshold(8388608L) .setDelayThreshold(Duration.ofMillis(100)) .build()); builder .fakeMethodBatching() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); return builder; }
@Provides @Singleton public Publisher publisher() throws IOException { // Publish request based on request size, messages count & time since last publish BatchingSettings batchingSettings = BatchingSettings.newBuilder() .setElementCountThreshold(messageCountBatchSize) .setRequestByteThreshold(requestBytesThreshold) .setDelayThreshold(publishDelayThreshold) .build(); ExecutorProvider executorProvider = InstantiatingExecutorProvider.newBuilder() .setExecutorThreadCount(1).build(); final Publisher.Builder publisher = Publisher.newBuilder(topicName()) .setBatchingSettings(batchingSettings) .setExecutorProvider(executorProvider); final String emulatorHost = System.getenv("PUBSUB_EMULATOR_HOST"); if (emulatorHost != null) { ManagedChannel channel = ManagedChannelBuilder.forTarget(emulatorHost).usePlaintext().build(); TransportChannelProvider channelProvider = FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)); publisher.setChannelProvider(channelProvider); publisher.setCredentialsProvider(NoCredentialsProvider.create()); } return publisher.build(); }
private CPSPublisherTask(StartRequest request) { super(request, "gcloud", MetricsHandler.MetricName.PUBLISH_ACK_LATENCY); try { this.publisher = Publisher.defaultBuilder(TopicName.create(request.getProject(), request.getTopic())) .setBatchingSettings( BatchingSettings.newBuilder() .setElementCountThreshold(950L) .setRequestByteThreshold(9500000L) .setDelayThreshold( Duration.ofMillis(Durations.toMillis(request.getPublishBatchDuration()))) .build()) .build(); } catch (Exception e) { throw new RuntimeException(e); } this.payload = ByteString.copyFromUtf8(LoadTestRunner.createMessage(request.getMessageSize())); this.batchSize = request.getPublishBatchSize(); this.messageSize = request.getMessageSize(); this.id = (new Random()).nextInt(); }
/** Get a new builder. */ public static Builder newBuilder() { return new AutoValue_BatchingSettings.Builder() .setIsEnabled(true) .setElementCountThreshold(1L) .setRequestByteThreshold(1L) .setDelayThreshold(Duration.ofMillis(1)) .setFlowControlSettings( FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Ignore) .build()); }
/** Get a new builder. */ public static Builder newBuilder() { return new AutoValue_BatchingSettings.Builder() .setIsEnabled(true) .setElementCountThreshold(1L) .setRequestByteThreshold(1L) .setDelayThreshold(Duration.ofMillis(1)) .setFlowControlSettings( FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Ignore) .build()); }
Publisher.Builder.DEFAULT_BATCHING_SETTINGS .toBuilder() .setRequestByteThreshold((Long) null) .build()); fail("Should have thrown an NullPointerException"); Publisher.Builder.DEFAULT_BATCHING_SETTINGS .toBuilder() .setRequestByteThreshold(0L) .build()); fail("Should have thrown an IllegalArgumentException"); Publisher.Builder.DEFAULT_BATCHING_SETTINGS .toBuilder() .setRequestByteThreshold(-1L) .build()); fail("Should have thrown an IllegalArgumentException");
public Publisher getPublisherWithCustomBatchSettings(ProjectTopicName topicName) throws Exception { // [START pubsub_publisher_batch_settings] // Batch settings control how the publisher batches messages long requestBytesThreshold = 5000L; // default : 1 byte long messageCountBatchSize = 10L; // default : 1 message Duration publishDelayThreshold = Duration.ofMillis(100); // default : 1 ms // Publish request get triggered based on request size, messages count & time since last publish BatchingSettings batchingSettings = BatchingSettings.newBuilder() .setElementCountThreshold(messageCountBatchSize) .setRequestByteThreshold(requestBytesThreshold) .setDelayThreshold(publishDelayThreshold) .build(); Publisher publisher = Publisher.newBuilder(topicName).setBatchingSettings(batchingSettings).build(); // [END pubsub_publisher_batch_settings] return publisher; }
@Test public void testPublisherGetters() throws Exception { Publisher.Builder builder = Publisher.newBuilder(TEST_TOPIC); builder.setChannelProvider(TEST_CHANNEL_PROVIDER); builder.setExecutorProvider(SINGLE_THREAD_EXECUTOR); builder.setBatchingSettings( BatchingSettings.newBuilder() .setRequestByteThreshold(10L) .setDelayThreshold(Duration.ofMillis(11)) .setElementCountThreshold(12L) .build()); builder.setCredentialsProvider(NoCredentialsProvider.create()); Publisher publisher = builder.build(); assertEquals(TEST_TOPIC, publisher.getTopicName()); assertEquals(10, (long) publisher.getBatchingSettings().getRequestByteThreshold()); assertEquals(Duration.ofMillis(11), publisher.getBatchingSettings().getDelayThreshold()); assertEquals(12, (long) publisher.getBatchingSettings().getElementCountThreshold()); publisher.shutdown(); publisher.awaitTermination(1, TimeUnit.MINUTES); }