Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable compression for publishing #1360

Merged
merged 3 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ If you are using Maven, add this to your pom.xml file:
If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-pubsublite:1.11.1'
implementation 'com.google.cloud:google-cloud-pubsublite:1.11.2'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-pubsublite" % "1.11.1"
libraryDependencies += "com.google.cloud" % "google-cloud-pubsublite" % "1.11.2"
```

## Authentication
Expand Down
6 changes: 6 additions & 0 deletions google-cloud-pubsublite/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<method>*</method>
<to>**</to>
</difference>
<difference>
<differenceType>7006</differenceType>
<className>com/google/cloud/pubsublite/internal/**</className>
<method>*</method>
<to>**</to>
</difference>
<difference>
<differenceType>7009</differenceType>
<className>com/google/cloud/pubsublite/internal/**</className>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import com.google.api.gax.batching.BatchingSettings;
import com.google.api.gax.core.CredentialsProvider;
import com.google.api.gax.rpc.ApiCallContext;
import com.google.api.gax.grpc.GrpcCallContext;
import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.StatusCode.Code;
import com.google.auto.value.AutoValue;
Expand Down Expand Up @@ -50,6 +50,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.protobuf.ByteString;
import com.google.pubsub.v1.PubsubMessage;
import io.grpc.CallOptions;
import java.util.Optional;
import org.threeten.bp.Duration;

Expand Down Expand Up @@ -82,11 +83,14 @@ public abstract class PublisherSettings {
abstract BatchingSettings batchingSettings();

/**
* Whether to enable publish idempotence, where the server will ensure that unique messages within
* a single publisher session are stored only once. Default true.
* Whether idempotence is enabled, where the server will ensure that unique messages within a
* single publisher session are stored only once. Default true.
*/
abstract boolean enableIdempotence();

/** Whether request compression is enabled. Default true. */
abstract boolean enableCompression();

/** A provider for credentials. */
abstract CredentialsProvider credentialsProvider();

Expand Down Expand Up @@ -115,6 +119,7 @@ public static Builder newBuilder() {
PublisherServiceSettings.defaultCredentialsProviderBuilder().build())
.setBatchingSettings(DEFAULT_BATCHING_SETTINGS)
.setEnableIdempotence(true)
.setEnableCompression(true)
.setUnderlyingBuilder(SinglePartitionPublisherBuilder.newBuilder());
}

Expand All @@ -137,11 +142,14 @@ public abstract Builder setMessageTransformer(
public abstract Builder setBatchingSettings(BatchingSettings batchingSettings);

/**
* Whether to enable publish idempotence, where the server will ensure that unique messages
* within a single publisher session are stored only once. Default true.
* Whether idempotence is enabled, where the server will ensure that unique messages within a
* single publisher session are stored only once. Default true.
*/
public abstract Builder setEnableIdempotence(boolean enableIdempotence);

/** Whether request compression is enabled. Default true. */
public abstract Builder setEnableCompression(boolean enableCompression);

/** A provider for credentials. */
public abstract Builder setCredentialsProvider(CredentialsProvider credentialsProvider);

Expand Down Expand Up @@ -190,10 +198,14 @@ public com.google.cloud.pubsublite.internal.Publisher<MessageMetadata> newPublis
.setPartition(partition)
.setStreamFactory(
responseStream -> {
ApiCallContext context =
GrpcCallContext context =
getCallContext(
PubsubContext.of(framework()),
RoutingMetadata.of(topicPath(), partition));
if (enableCompression()) {
context =
dpcollins-google marked this conversation as resolved.
Show resolved Hide resolved
context.withCallOptions(CallOptions.DEFAULT.withCompression("gzip"));
}
return client.publishCallable().splitCall(responseStream, context);
});
if (enableIdempotence()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.api.gax.grpc.ChannelPoolSettings;
import com.google.api.gax.grpc.GrpcCallContext;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.api.gax.rpc.ApiCallContext;
import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.ClientSettings;
import com.google.api.gax.rpc.TransportChannelProvider;
Expand Down Expand Up @@ -70,7 +69,7 @@ Settings addDefaultSettings(CloudRegion target, Builder builder) throws ApiExcep
}
}

public static ApiCallContext getCallContext(
public static GrpcCallContext getCallContext(
PubsubContext context, RoutingMetadata routingMetadata) {
return GrpcCallContext.createDefault()
.withExtraHeaders(
Expand Down