31 | * The number of partitions in the topic. 32 | *33 | * 34 | *
int64 partition_count = 1;
35 | *
36 | * @return The partitionCount.
37 | */
38 | long getPartitionCount();
39 | }
40 |
--------------------------------------------------------------------------------
/proto-google-cloud-pubsublite-v1/src/main/java/com/google/cloud/pubsublite/proto/CursorOrBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | // Generated by the protocol buffer compiler. DO NOT EDIT!
17 | // source: google/cloud/pubsublite/v1/common.proto
18 |
19 | // Protobuf Java Version: 3.25.8
20 | package com.google.cloud.pubsublite.proto;
21 |
22 | public interface CursorOrBuilder
23 | extends
24 | // @@protoc_insertion_point(interface_extends:google.cloud.pubsublite.v1.Cursor)
25 | com.google.protobuf.MessageOrBuilder {
26 |
27 | /**
28 | *
29 | *
30 | * 31 | * The offset of a message within a topic partition. Must be greater than or 32 | * equal 0. 33 | *34 | * 35 | *
int64 offset = 1;
36 | *
37 | * @return The offset.
38 | */
39 | long getOffset();
40 | }
41 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/ErrorCodes.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite;
18 |
19 | import com.google.api.gax.rpc.StatusCode.Code;
20 | import com.google.common.collect.ImmutableSet;
21 |
22 | /** Pub/Sub Lite retryable error codes. */
23 | public final class ErrorCodes {
24 | public static final ImmutableSet STREAM_RETRYABLE_CODES =
25 | ImmutableSet.of(
26 | Code.DEADLINE_EXCEEDED,
27 | Code.ABORTED,
28 | Code.INTERNAL,
29 | Code.UNAVAILABLE,
30 | Code.UNKNOWN,
31 | Code.RESOURCE_EXHAUSTED,
32 | Code.CANCELLED);
33 |
34 | public static boolean IsRetryableForStreams(Code code) {
35 | return STREAM_RETRYABLE_CODES.contains(code);
36 | }
37 |
38 | private ErrorCodes() {}
39 | }
40 |
--------------------------------------------------------------------------------
/samples/README.md:
--------------------------------------------------------------------------------
1 | # Getting Started with Pub/Sub Lite Samples
2 |
3 | ## Running samples and tests using Cloud Shell
4 |
5 | [Google Cloud Shell](https://cloud.google.com/shell) has application default credentials from its compute instance which will allow you to run an integration test without having to obtain `GOOGLE_APPLICATION_CREDENTIALS`.
6 |
7 | However, tests require an additional environment variable `GOOGLE_CLOUD_PROJECT_NUMBER` to run. For instance,
8 |
9 | In [`QuickStartIT.java`](snippets/src/test/java/pubsublite/QuickStartIT.java):
10 |
11 | ```java
12 | private static final String GOOGLE_CLOUD_PROJECT_NUMBER =
13 | System.getenv("GOOGLE_CLOUD_PROJECT_NUMBER");
14 | ```
15 | Here, the program needs you to provide your [Google Cloud Project Number](https://cloud.google.com/resource-manager/docs/creating-managing-projects) in an environment variable.
16 |
17 | To run a sample's integration test in Cloud Shell:
18 |
19 | 1. `cd samples/` - all samples are located in `java-pubsublite/samples/snippets` directory.
20 |
21 | 1. `mvn clean -Dtest=QuickStartIT test` - this runs the integration test for `UpdateTopicExample.java`.
22 |
23 | To run a sample, update the developer's TODO section in the snippet, then:
24 |
25 | 1. `cd samples/snippets/` - all samples are located in `java-pubsublite/samples/snippets` directory.
26 |
27 | 1. `mvn compile exec:java -Dexec.mainClass=pubsublite.ListTopicsExample` - this should list the topics in your project.
28 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/ReservationName.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite;
18 |
19 | import static com.google.cloud.pubsublite.internal.UncheckedApiPreconditions.checkArgument;
20 |
21 | import com.google.api.gax.rpc.ApiException;
22 | import com.google.auto.value.AutoValue;
23 | import java.io.Serializable;
24 |
25 | /** A string wrapper for the name of a reservation. */
26 | @AutoValue
27 | public abstract class ReservationName implements Serializable {
28 | public abstract String value();
29 |
30 | @Override
31 | public String toString() {
32 | return value();
33 | }
34 |
35 | public static ReservationName of(String value) throws ApiException {
36 | checkArgument(!value.isEmpty());
37 | return new AutoValue_ReservationName(value);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/testing/FakeApiService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal.testing;
18 |
19 | import com.google.api.core.AbstractApiService;
20 |
21 | /**
22 | * Fake Pub/Sub Lite service for testing. Used like:
23 | *
24 | *
25 | * static abstract class SubscriberFakeService extends FakeApiService implements Subscriber {};
26 | * @Spy private SubscriberFakeService wireSubscriber;
27 | *
28 | */
29 | public abstract class FakeApiService extends AbstractApiService {
30 | public void fail(Throwable t) {
31 | notifyFailed(t);
32 | }
33 |
34 | @Override
35 | protected void doStart() {
36 | notifyStarted();
37 | }
38 |
39 | @Override
40 | protected void doStop() {
41 | notifyStopped();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/SubscriptionName.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite;
18 |
19 | import static com.google.cloud.pubsublite.internal.UncheckedApiPreconditions.checkArgument;
20 |
21 | import com.google.api.gax.rpc.ApiException;
22 | import com.google.auto.value.AutoValue;
23 | import java.io.Serializable;
24 |
25 | /** A string wrapper for the name of a subscription. */
26 | @AutoValue
27 | public abstract class SubscriptionName implements Serializable {
28 | public abstract String value();
29 |
30 | @Override
31 | public String toString() {
32 | return value();
33 | }
34 |
35 | public static SubscriptionName of(String value) throws ApiException {
36 | checkArgument(!value.isEmpty());
37 | return new AutoValue_SubscriptionName(value);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/test/java/com/google/cloud/pubsublite/internal/CursorClientSettingsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal;
18 |
19 | import static org.mockito.Mockito.mock;
20 |
21 | import com.google.cloud.pubsublite.CloudRegion;
22 | import com.google.cloud.pubsublite.v1.CursorServiceClient;
23 | import org.junit.Test;
24 | import org.junit.runner.RunWith;
25 | import org.junit.runners.JUnit4;
26 |
27 | @RunWith(JUnit4.class)
28 | public class CursorClientSettingsTest {
29 | @Test
30 | public void testSettings() {
31 | CursorClient unusedClient =
32 | CursorClientSettings.newBuilder()
33 | .setRegion(CloudRegion.of("us-central1"))
34 | .setServiceClient(mock(CursorServiceClient.class))
35 | .build()
36 | .instantiate();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 |
5 | ---
6 |
7 | Thanks for stopping by to let us know something could be better!
8 |
9 | **PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response.
10 |
11 | Please run down the following list and make sure you've tried the usual "quick fixes":
12 |
13 | - Search the issues already opened: https://github.com/googleapis/java-pubsublite/issues
14 | - Check for answers on StackOverflow: http://stackoverflow.com/questions/tagged/google-cloud-platform
15 |
16 | If you are still having issues, please include as much information as possible:
17 |
18 | #### Environment details
19 |
20 | 1. Specify the API at the beginning of the title. For example, "BigQuery: ...").
21 | General, Core, and Other are also allowed as types
22 | 2. OS type and version:
23 | 3. Java version:
24 | 4. version(s):
25 |
26 | #### Steps to reproduce
27 |
28 | 1. ?
29 | 2. ?
30 |
31 | #### Code example
32 |
33 | ```java
34 | // example
35 | ```
36 |
37 | #### Stack trace
38 | ```
39 | Any relevant stacktrace here.
40 | ```
41 |
42 | #### External references such as API reference guides
43 |
44 | - ?
45 |
46 | #### Any additional information below
47 |
48 |
49 | Following these steps guarantees the quickest resolution possible.
50 |
51 | Thanks!
52 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/wire/RetryingConnection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal.wire;
18 |
19 | import com.google.api.core.ApiService;
20 | import com.google.cloud.pubsublite.internal.CheckedApiException;
21 | import java.util.Optional;
22 |
23 | interface RetryingConnection extends ApiService {
24 | // Reinitialize the stream. Must be called in a downcall to prevent deadlock.
25 | void reinitialize(StreamRequestT initialRequest);
26 |
27 | interface Modifier {
28 | void modify(Optional connectionOr) throws CheckedApiException;
29 | }
30 |
31 | // Run modification on the current connection or empty if not connected.
32 | void modifyConnection(Modifier modifier) throws CheckedApiException;
33 | }
34 |
--------------------------------------------------------------------------------
/.github/.OwlBot-hermetic.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | deep-remove-regex:
15 | - "/samples/snippets/generated"
16 | - "/grpc-google-.*/src"
17 | - "/proto-google-.*/src"
18 | - "/google-.*/src/main/java/com/google/cloud/pubsublite/v1"
19 |
20 | deep-preserve-regex:
21 | - "/google-.*/src/test/java/com/google/cloud/.*/v.*/it/IT.*Test.java"
22 |
23 | deep-copy-regex:
24 | - source: "/google/cloud/pubsublite/(v.*)/.*-java/proto-google-.*/src"
25 | dest: "/owl-bot-staging/$1/proto-google-cloud-pubsublite-$1/src"
26 | - source: "/google/cloud/pubsublite/(v.*)/.*-java/grpc-google-.*/src"
27 | dest: "/owl-bot-staging/$1/grpc-google-cloud-pubsublite-$1/src"
28 | - source: "/google/cloud/pubsublite/(v.*)/.*-java/gapic-google-.*/src"
29 | dest: "/owl-bot-staging/$1/google-cloud-pubsublite/src"
30 | - source: "/google/cloud/pubsublite/(v.*)/.*-java/samples/snippets/generated"
31 | dest: "/owl-bot-staging/$1/samples/snippets/generated"
32 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/test/java/com/google/cloud/pubsublite/internal/TopicStatsClientSettingsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal;
18 |
19 | import static org.mockito.Mockito.mock;
20 |
21 | import com.google.cloud.pubsublite.CloudRegion;
22 | import com.google.cloud.pubsublite.v1.TopicStatsServiceClient;
23 | import org.junit.Test;
24 | import org.junit.runner.RunWith;
25 | import org.junit.runners.JUnit4;
26 |
27 | @RunWith(JUnit4.class)
28 | public class TopicStatsClientSettingsTest {
29 | @Test
30 | public void testSettings() throws CheckedApiException {
31 | TopicStatsClient unusedClient =
32 | TopicStatsClientSettings.newBuilder()
33 | .setRegion(CloudRegion.of("us-central1"))
34 | .setServiceClient(mock(TopicStatsServiceClient.class))
35 | .build()
36 | .instantiate();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/wire/UuidBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal.wire;
18 |
19 | import com.google.protobuf.ByteString;
20 | import java.nio.ByteBuffer;
21 | import java.util.UUID;
22 |
23 | /** Utilities for generating and converting 128-bit UUIDs. */
24 | public final class UuidBuilder {
25 |
26 | /** Generates a random UUID. */
27 | public static UUID generate() {
28 | return UUID.randomUUID();
29 | }
30 |
31 | /** Converts a UUID to a ByteString. */
32 | public static ByteString toByteString(UUID uuid) {
33 | ByteBuffer uuidBuffer = ByteBuffer.allocate(16);
34 | uuidBuffer.putLong(uuid.getMostSignificantBits());
35 | uuidBuffer.putLong(uuid.getLeastSignificantBits());
36 | return ByteString.copyFrom(uuidBuffer.array());
37 | }
38 |
39 | private UuidBuilder() {}
40 | }
41 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/wire/ResetSignal.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal.wire;
18 |
19 | import com.google.cloud.pubsublite.ErrorCodes;
20 | import com.google.cloud.pubsublite.internal.CheckedApiException;
21 | import com.google.cloud.pubsublite.internal.ExtractStatus;
22 |
23 | // Pub/Sub Lite's stream RESET signal is sent by the server to instruct the client to reset the
24 | // stream state.
25 | public final class ResetSignal {
26 | private static final String REASON = "RESET";
27 |
28 | public static boolean isResetSignal(CheckedApiException checkedApiException) {
29 | if (!ErrorCodes.IsRetryableForStreams(checkedApiException.code())) {
30 | return false;
31 | }
32 | return ExtractStatus.getErrorInfoReason(checkedApiException).equals(REASON);
33 | }
34 |
35 | private ResetSignal() {}
36 | }
37 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/Partition.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite;
18 |
19 | import static com.google.cloud.pubsublite.internal.UncheckedApiPreconditions.checkArgument;
20 |
21 | import com.google.api.gax.rpc.ApiException;
22 | import com.google.auto.value.AutoValue;
23 | import java.io.Serializable;
24 |
25 | /** A partition of a topic. */
26 | @AutoValue
27 | public abstract class Partition implements Serializable {
28 | private static final long serialVersionUID = 7583927435022345L;
29 |
30 | /** Create a partition from its long value. */
31 | public static Partition of(long partition) throws ApiException {
32 | checkArgument(partition >= 0, "Partitions are zero indexed.");
33 | return new AutoValue_Partition(partition);
34 | }
35 |
36 | /** The long value of this partition. */
37 | public abstract long value();
38 | }
39 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/Constants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite;
18 |
19 | import com.google.api.gax.retrying.RetrySettings;
20 | import java.time.Duration;
21 |
22 | /** Useful general constants for Pub/Sub Lite. */
23 | public class Constants {
24 | public static final RetrySettings DEFAULT_RETRY_SETTINGS =
25 | RetrySettings.newBuilder()
26 | .setInitialRetryDelayDuration(Duration.ofMillis(100))
27 | .setRetryDelayMultiplier(1.3)
28 | .setMaxRetryDelayDuration(Duration.ofSeconds(60))
29 | .setJittered(true)
30 | .setTotalTimeoutDuration(Duration.ofMinutes(10))
31 | .build();
32 |
33 | public static final long MAX_PUBLISH_BATCH_COUNT = 1_000;
34 | public static final long MAX_PUBLISH_BATCH_BYTES = 1024 * 1024 * 7 / 2; // 3.5 MiB
35 |
36 | private Constants() {}
37 | }
38 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/cloudpubsub/internal/AckSetTracker.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.cloudpubsub.internal;
18 |
19 | import com.google.api.core.ApiService;
20 | import com.google.cloud.pubsublite.SequencedMessage;
21 | import com.google.cloud.pubsublite.internal.CheckedApiException;
22 |
23 | interface AckSetTracker extends ApiService {
24 | // Track the given message. Returns a Runnable to ack this message if the message is a valid one
25 | // to add to the ack set. Must be called with strictly increasing offset messages.
26 | Runnable track(SequencedMessage message) throws CheckedApiException;
27 |
28 | // Discard all outstanding acks and wait for any pending commit offset to be acknowledged by the
29 | // server. Throws an exception if the committer shut down due to a permanent error.
30 | void waitUntilCommitted() throws CheckedApiException;
31 | }
32 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/cloudpubsub/KeyExtractor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.cloudpubsub;
18 |
19 | import com.google.api.gax.rpc.ApiException;
20 | import com.google.protobuf.ByteString;
21 | import com.google.pubsub.v1.PubsubMessage;
22 |
23 | /**
24 | * A KeyExtractor can extract the Pub/Sub Lite 'key' field used for message routing from a
25 | * PubsubMessage. It will by default use the ordering_key field directly for this if it exists.
26 | *
27 | * An empty ByteString implies that the message should have no ordering key.
28 | */
29 | public interface KeyExtractor {
30 | /** An extractor that gets the routing key from the ordering key field. */
31 | KeyExtractor DEFAULT = PubsubMessage::getOrderingKeyBytes;
32 |
33 | /** Extract the ByteString routing key from a PubsubMessage. */
34 | ByteString extractKey(PubsubMessage message) throws ApiException;
35 | }
36 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/testing/TestResetSignal.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal.testing;
18 |
19 | import com.google.api.gax.rpc.StatusCode.Code;
20 | import com.google.cloud.pubsublite.internal.CheckedApiException;
21 | import com.google.protobuf.Any;
22 | import com.google.rpc.ErrorInfo;
23 | import com.google.rpc.Status;
24 | import io.grpc.protobuf.StatusProto;
25 |
26 | public final class TestResetSignal {
27 | public static CheckedApiException newCheckedException() {
28 | ErrorInfo errorInfo =
29 | ErrorInfo.newBuilder().setReason("RESET").setDomain("pubsublite.googleapis.com").build();
30 | Status status =
31 | Status.newBuilder().setCode(Code.ABORTED.ordinal()).addDetails(Any.pack(errorInfo)).build();
32 | return new CheckedApiException(StatusProto.toStatusRuntimeException(status), Code.ABORTED);
33 | }
34 |
35 | private TestResetSignal() {}
36 | }
37 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/wire/RetryingConnectionObserver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal.wire;
18 |
19 | import com.google.cloud.pubsublite.internal.CheckedApiException;
20 |
21 | public interface RetryingConnectionObserver {
22 | // Trigger reinitialization. This cannot be an upcall. It needs to be atomic so there is no
23 | // possibility for other client messages to be sent on the stream between the new stream being
24 | // created and the client initialization occurring. It cannot be called with connectionMonitor
25 | // held since all locks need to be acquired in concrete then abstract class order to avoid
26 | // deadlocks.
27 | //
28 | // `streamError` is the error that caused the connection to break.
29 | void triggerReinitialize(CheckedApiException streamError);
30 |
31 | void onClientResponse(ClientResponseT value) throws CheckedApiException;
32 | }
33 |
--------------------------------------------------------------------------------
/.repo-metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "api_shortname": "pubsublite",
3 | "name_pretty": "Cloud Pub/Sub Lite",
4 | "product_documentation": "https://cloud.google.com/pubsub/lite/docs",
5 | "api_description": "is designed to provide reliable, many-to-many, asynchronous messaging between applications. Publisher\\napplications can send messages to a topic and other applications can\\nsubscribe to that topic to receive the messages. By decoupling senders and\\nreceivers, Google Cloud Pub/Sub allows developers to communicate between\\nindependently written applications.\\n\\nCompared to Google Pub/Sub, Pub/Sub Lite provides partitioned zonal data\\nstorage with predefined capacity. Both products present a similar API, but\\nPub/Sub Lite has more usage caveats.\\n\\nSee the [Google Pub/Sub Lite docs](https://cloud.google.com/pubsub/quickstart-console#before-you-begin) for more details on how to activate\\nPub/Sub Lite for your project, as well as guidance on how to choose between\\nCloud Pub/Sub and Pub/Sub Lite.",
6 | "client_documentation": "https://cloud.google.com/java/docs/reference/google-cloud-pubsublite/latest/history",
7 | "release_level": "stable",
8 | "transport": "grpc",
9 | "language": "java",
10 | "repo": "googleapis/java-pubsublite",
11 | "repo_short": "java-pubsublite",
12 | "distribution_name": "com.google.cloud:google-cloud-pubsublite",
13 | "api_id": "pubsublite.googleapis.com",
14 | "library_type": "GAPIC_COMBO",
15 | "requires_billing": true,
16 | "codeowner_team": "@googleapis/api-pubsublite",
17 | "recommended_package": "com.google.cloud.pubsublite.cloudpubsub",
18 | "min_java_version": 8
19 | }
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/Publisher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal;
18 |
19 | import com.google.api.core.ApiFuture;
20 | import com.google.api.core.ApiService;
21 | import com.google.cloud.pubsublite.proto.PubSubMessage;
22 | import java.io.Flushable;
23 |
24 | /** A generic PubSub Lite publisher. Errors are handled out of band. Thread safe. */
25 | public interface Publisher extends ApiService, Flushable {
26 | // Publish a new message. Behavior is undefined if a call to flush() is outstanding or close() has
27 | // already been called. This method never blocks.
28 | //
29 | // Guarantees that if a single publish future has an exception set, all publish calls made after
30 | // that will also have an exception set.
31 | ApiFuture publish(PubSubMessage message);
32 |
33 | // Attempts to cancel all outstanding publishes.
34 | void cancelOutstandingPublishes();
35 | }
36 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/cloudpubsub/internal/MultiPartitionSubscriber.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.cloudpubsub.internal;
18 |
19 | import com.google.api.core.ApiService;
20 | import com.google.api.gax.rpc.ApiException;
21 | import com.google.cloud.pubsublite.cloudpubsub.Subscriber;
22 | import com.google.cloud.pubsublite.internal.ProxyService;
23 | import java.util.List;
24 |
25 | // A MultiPartitionSubscriber wraps multiple subscribers into a single ApiService that can be
26 | // interacted with. If any single subscriber fails, all others are stopped.
27 | public class MultiPartitionSubscriber extends ProxyService implements Subscriber {
28 | public static Subscriber of(List services) throws ApiException {
29 | return new MultiPartitionSubscriber(services);
30 | }
31 |
32 | private MultiPartitionSubscriber(List subscribers) throws ApiException {
33 | super(subscribers);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/wire/StreamFactories.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal.wire;
18 |
19 | import com.google.cloud.pubsublite.proto.PublishRequest;
20 | import com.google.cloud.pubsublite.proto.PublishResponse;
21 | import com.google.cloud.pubsublite.proto.StreamingCommitCursorRequest;
22 | import com.google.cloud.pubsublite.proto.StreamingCommitCursorResponse;
23 | import com.google.cloud.pubsublite.proto.SubscribeRequest;
24 | import com.google.cloud.pubsublite.proto.SubscribeResponse;
25 |
26 | public final class StreamFactories {
27 | public interface PublishStreamFactory extends StreamFactory {}
28 |
29 | public interface SubscribeStreamFactory
30 | extends StreamFactory {}
31 |
32 | public interface CursorStreamFactory
33 | extends StreamFactory {}
34 | }
35 |
--------------------------------------------------------------------------------
/.kokoro/nightly/samples.cfg:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | # Format: //devtools/kokoro/config/proto/build.proto
16 |
17 | # Download secrets from Cloud Storage.
18 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/java-docs-samples"
19 |
20 | # Configure the docker image for kokoro-trampoline.
21 | env_vars: {
22 | key: "TRAMPOLINE_IMAGE"
23 | value: "gcr.io/cloud-devrel-kokoro-resources/java8"
24 | }
25 |
26 | env_vars: {
27 | key: "JOB_TYPE"
28 | value: "samples"
29 | }
30 |
31 | env_vars: {
32 | key: "GCLOUD_PROJECT"
33 | value: "java-docs-samples-testing"
34 | }
35 |
36 | env_vars: {
37 | key: "GOOGLE_CLOUD_PROJECT"
38 | value: "java-docs-samples-testing"
39 | }
40 |
41 | env_vars: {
42 | key: "GOOGLE_CLOUD_PROJECT_NUMBER"
43 | value: "779844219229"
44 | }
45 |
46 | env_vars: {
47 | key: "GOOGLE_APPLICATION_CREDENTIALS"
48 | value: "secret_manager/java-docs-samples-service-account"
49 | }
50 |
51 | env_vars: {
52 | key: "SECRET_MANAGER_KEYS"
53 | value: "java-docs-samples-service-account"
54 | }
--------------------------------------------------------------------------------
/proto-google-cloud-pubsublite-v1/src/main/java/com/google/cloud/pubsublite/proto/SequencedCommitCursorResponseOrBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | // Generated by the protocol buffer compiler. DO NOT EDIT!
17 | // source: google/cloud/pubsublite/v1/cursor.proto
18 |
19 | // Protobuf Java Version: 3.25.8
20 | package com.google.cloud.pubsublite.proto;
21 |
22 | public interface SequencedCommitCursorResponseOrBuilder
23 | extends
24 | // @@protoc_insertion_point(interface_extends:google.cloud.pubsublite.v1.SequencedCommitCursorResponse)
25 | com.google.protobuf.MessageOrBuilder {
26 |
27 | /**
28 | *
29 | *
30 | *
31 | * The number of outstanding SequencedCommitCursorRequests acknowledged by
32 | * this response. Note that SequencedCommitCursorRequests are acknowledged in
33 | * the order that they are received.
34 | *
35 | *
36 | * int64 acknowledged_commits = 1;
37 | *
38 | * @return The acknowledgedCommits.
39 | */
40 | long getAcknowledgedCommits();
41 | }
42 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/v1/stub/PublisherServiceStub.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.v1.stub;
18 |
19 | import com.google.api.gax.core.BackgroundResource;
20 | import com.google.api.gax.rpc.BidiStreamingCallable;
21 | import com.google.cloud.pubsublite.proto.PublishRequest;
22 | import com.google.cloud.pubsublite.proto.PublishResponse;
23 | import javax.annotation.Generated;
24 |
25 | // AUTO-GENERATED DOCUMENTATION AND CLASS.
26 | /**
27 | * Base stub class for the PublisherService service API.
28 | *
29 | * This class is for advanced usage and reflects the underlying API directly.
30 | */
31 | @Generated("by gapic-generator-java")
32 | public abstract class PublisherServiceStub implements BackgroundResource {
33 |
34 | public BidiStreamingCallable publishCallable() {
35 | throw new UnsupportedOperationException("Not implemented: publishCallable()");
36 | }
37 |
38 | @Override
39 | public abstract void close();
40 | }
41 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/v1/stub/SubscriberServiceStub.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.v1.stub;
18 |
19 | import com.google.api.gax.core.BackgroundResource;
20 | import com.google.api.gax.rpc.BidiStreamingCallable;
21 | import com.google.cloud.pubsublite.proto.SubscribeRequest;
22 | import com.google.cloud.pubsublite.proto.SubscribeResponse;
23 | import javax.annotation.Generated;
24 |
25 | // AUTO-GENERATED DOCUMENTATION AND CLASS.
26 | /**
27 | * Base stub class for the SubscriberService service API.
28 | *
29 | * This class is for advanced usage and reflects the underlying API directly.
30 | */
31 | @Generated("by gapic-generator-java")
32 | public abstract class SubscriberServiceStub implements BackgroundResource {
33 |
34 | public BidiStreamingCallable subscribeCallable() {
35 | throw new UnsupportedOperationException("Not implemented: subscribeCallable()");
36 | }
37 |
38 | @Override
39 | public abstract void close();
40 | }
41 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/ProjectNumber.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite;
18 |
19 | import static com.google.cloud.pubsublite.internal.UncheckedApiPreconditions.checkArgument;
20 |
21 | import com.google.api.gax.rpc.ApiException;
22 | import com.google.auto.value.AutoValue;
23 | import java.io.Serializable;
24 |
25 | /**
26 | * A wrapper class for the project
28 | * number.
29 | */
30 | @AutoValue
31 | public abstract class ProjectNumber implements Serializable {
32 | /** The long value of this project number. */
33 | public abstract long value();
34 |
35 | @Override
36 | public String toString() {
37 | return Long.toString(value());
38 | }
39 |
40 | /** Construct a ProjectNumber from its long value. */
41 | public static ProjectNumber of(long value) throws ApiException {
42 | checkArgument(value > 0);
43 | return new AutoValue_ProjectNumber(value);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/MoreApiFutures.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal;
18 |
19 | import com.google.api.core.ApiFuture;
20 | import com.google.api.core.ApiFutureCallback;
21 | import com.google.api.core.ApiFutures;
22 | import com.google.api.core.SettableApiFuture;
23 | import com.google.cloud.pubsublite.internal.wire.SystemExecutors;
24 |
25 | public final class MoreApiFutures {
26 | private MoreApiFutures() {}
27 |
28 | public static void connectFutures(
29 | ApiFuture source, SettableApiFuture super T> toConnect) {
30 | ApiFutures.addCallback(
31 | source,
32 | new ApiFutureCallback() {
33 | @Override
34 | public void onFailure(Throwable throwable) {
35 | toConnect.setException(throwable);
36 | }
37 |
38 | @Override
39 | public void onSuccess(T t) {
40 | toConnect.set(t);
41 | }
42 | },
43 | SystemExecutors.getFuturesExecutor());
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/.kokoro/presubmit/samples.cfg:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | # Format: //devtools/kokoro/config/proto/build.proto
16 |
17 | # Download secrets from Cloud Storage.
18 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/java-docs-samples"
19 |
20 | # Configure the docker image for kokoro-trampoline.
21 | env_vars: {
22 | key: "TRAMPOLINE_IMAGE"
23 | value: "gcr.io/cloud-devrel-kokoro-resources/java8"
24 | }
25 |
26 | env_vars: {
27 | key: "JOB_TYPE"
28 | value: "samples"
29 | }
30 |
31 | env_vars: {
32 | key: "GCLOUD_PROJECT"
33 | value: "java-docs-samples-testing"
34 | }
35 |
36 | env_vars: {
37 | key: "GOOGLE_CLOUD_PROJECT"
38 | value: "java-docs-samples-testing"
39 | }
40 |
41 | env_vars: {
42 | key: "GOOGLE_CLOUD_PROJECT_NUMBER"
43 | value: "779844219229"
44 | }
45 |
46 | env_vars: {
47 | key: "GOOGLE_APPLICATION_CREDENTIALS"
48 | value: "secret_manager/java-docs-samples-service-account"
49 | }
50 |
51 | env_vars: {
52 | key: "SECRET_MANAGER_KEYS"
53 | value: "java-docs-samples-service-account"
54 | }
55 |
56 | env_vars: {
57 | key: "ENABLE_FLAKYBOT"
58 | value: "true"
59 | }
--------------------------------------------------------------------------------
/.kokoro/continuous/samples.cfg:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | # Format: //devtools/kokoro/config/proto/build.proto
16 |
17 | # Download secrets from Cloud Storage.
18 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/java-docs-samples"
19 |
20 | # Configure the docker image for kokoro-trampoline.
21 | env_vars: {
22 | key: "TRAMPOLINE_IMAGE"
23 | value: "gcr.io/cloud-devrel-kokoro-resources/java11"
24 | }
25 |
26 | # Tell trampoline which tests to run.
27 | env_vars: {
28 | key: "TRAMPOLINE_BUILD_FILE"
29 | value: "github/java-pubsublite/.kokoro/run_samples_tests.sh"
30 | }
31 |
32 | env_vars: {
33 | key: "GCLOUD_PROJECT"
34 | value: "java-docs-samples-testing"
35 | }
36 |
37 | env_vars: {
38 | key: "GOOGLE_CLOUD_PROJECT"
39 | value: "java-docs-samples-testing"
40 | }
41 |
42 | env_vars: {
43 | key: "GOOGLE_CLOUD_PROJECT_NUMBER"
44 | value: "779844219229"
45 | }
46 |
47 | env_vars: {
48 | key: "GOOGLE_APPLICATION_CREDENTIALS"
49 | value: "secret_manager/java-docs-samples-service-account"
50 | }
51 |
52 | env_vars: {
53 | key: "SECRET_MANAGER_KEYS"
54 | value: "java-docs-samples-service-account"
55 | }
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/wire/ApiExceptionCommitter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal.wire;
18 |
19 | import static com.google.cloud.pubsublite.internal.ExtractStatus.toClientFuture;
20 |
21 | import com.google.api.core.ApiFuture;
22 | import com.google.api.gax.rpc.ApiException;
23 | import com.google.cloud.pubsublite.Offset;
24 | import com.google.cloud.pubsublite.internal.CheckedApiException;
25 | import com.google.cloud.pubsublite.internal.ProxyService;
26 |
27 | class ApiExceptionCommitter extends ProxyService implements Committer {
28 | private final Committer committer;
29 |
30 | ApiExceptionCommitter(Committer committer) throws ApiException {
31 | super(committer);
32 | this.committer = committer;
33 | }
34 |
35 | @Override
36 | public ApiFuture commitOffset(Offset offset) {
37 | return toClientFuture(committer.commitOffset(offset));
38 | }
39 |
40 | @Override
41 | public void waitUntilEmpty() throws CheckedApiException {
42 | committer.waitUntilEmpty();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/.kokoro/populate-secrets.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Copyright 2020 Google LLC.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | set -eo pipefail
17 |
18 | function now { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n' ;}
19 | function msg { println "$*" >&2 ;}
20 | function println { printf '%s\n' "$(now) $*" ;}
21 |
22 |
23 | # Populates requested secrets set in SECRET_MANAGER_KEYS from service account:
24 | # kokoro-trampoline@cloud-devrel-kokoro-resources.iam.gserviceaccount.com
25 | SECRET_LOCATION="${KOKORO_GFILE_DIR}/secret_manager"
26 | msg "Creating folder on disk for secrets: ${SECRET_LOCATION}"
27 | mkdir -p ${SECRET_LOCATION}
28 | for key in $(echo ${SECRET_MANAGER_KEYS} | sed "s/,/ /g")
29 | do
30 | msg "Retrieving secret ${key}"
31 | docker run --entrypoint=gcloud \
32 | --volume=${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR} \
33 | gcr.io/google.com/cloudsdktool/cloud-sdk \
34 | secrets versions access latest \
35 | --project cloud-devrel-kokoro-resources \
36 | --secret ${key} > \
37 | "${SECRET_LOCATION}/${key}"
38 | if [[ $? == 0 ]]; then
39 | msg "Secret written to ${SECRET_LOCATION}/${key}"
40 | else
41 | msg "Error retrieving secret ${key}"
42 | fi
43 | done
44 |
--------------------------------------------------------------------------------
/.kokoro/readme.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Copyright 2020 Google LLC
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | set -eo pipefail
17 |
18 | cd ${KOKORO_ARTIFACTS_DIR}/github/java-pubsublite
19 |
20 | # Disable buffering, so that the logs stream through.
21 | export PYTHONUNBUFFERED=1
22 |
23 | # Kokoro exposes this as a file, but the scripts expect just a plain variable.
24 | export GITHUB_TOKEN=$(cat ${KOKORO_KEYSTORE_DIR}/73713_yoshi-automation-github-key)
25 |
26 | # Setup git credentials
27 | echo "https://${GITHUB_TOKEN}:@github.com" >> ~/.git-credentials
28 | git config --global credential.helper 'store --file ~/.git-credentials'
29 |
30 | python3.6 -m pip install git+https://github.com/googleapis/synthtool.git#egg=gcp-synthtool
31 |
32 | set +e
33 | python3.6 -m autosynth.synth \
34 | --repository=googleapis/java-pubsublite \
35 | --synth-file-name=.github/readme/synth.py \
36 | --metadata-path=.github/readme/synth.metadata \
37 | --pr-title="chore: regenerate README" \
38 | --branch-suffix="readme"
39 |
40 | # autosynth returns 28 to signal there are no changes
41 | RETURN_CODE=$?
42 | if [[ ${RETURN_CODE} -ne 0 && ${RETURN_CODE} -ne 28 ]]
43 | then
44 | exit ${RETURN_CODE}
45 | fi
46 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/v1/stub/PartitionAssignmentServiceStub.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.v1.stub;
18 |
19 | import com.google.api.gax.core.BackgroundResource;
20 | import com.google.api.gax.rpc.BidiStreamingCallable;
21 | import com.google.cloud.pubsublite.proto.PartitionAssignment;
22 | import com.google.cloud.pubsublite.proto.PartitionAssignmentRequest;
23 | import javax.annotation.Generated;
24 |
25 | // AUTO-GENERATED DOCUMENTATION AND CLASS.
26 | /**
27 | * Base stub class for the PartitionAssignmentService service API.
28 | *
29 | * This class is for advanced usage and reflects the underlying API directly.
30 | */
31 | @Generated("by gapic-generator-java")
32 | public abstract class PartitionAssignmentServiceStub implements BackgroundResource {
33 |
34 | public BidiStreamingCallable
35 | assignPartitionsCallable() {
36 | throw new UnsupportedOperationException("Not implemented: assignPartitionsCallable()");
37 | }
38 |
39 | @Override
40 | public abstract void close();
41 | }
42 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/test/java/com/google/cloud/pubsublite/internal/wire/VersionsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal.wire;
18 |
19 | import static com.google.common.truth.Truth.assertThat;
20 |
21 | import org.junit.Test;
22 | import org.junit.runner.RunWith;
23 | import org.junit.runners.JUnit4;
24 |
25 | @RunWith(JUnit4.class)
26 | public class VersionsTest {
27 | @Test
28 | public void badSplits() {
29 | Versions versions = new Versions("1.1");
30 | assertThat(versions.getMajorVersion()).isEqualTo(0);
31 | assertThat(versions.getMinorVersion()).isEqualTo(0);
32 | }
33 |
34 | @Test
35 | public void garbageMajorVersion() {
36 | Versions versions = new Versions("abc.1.1");
37 | assertThat(versions.getMajorVersion()).isEqualTo(0);
38 | assertThat(versions.getMinorVersion()).isEqualTo(1);
39 | }
40 |
41 | @Test
42 | public void garbageMinorVersion() {
43 | Versions versions = new Versions("1.abc.1");
44 | assertThat(versions.getMajorVersion()).isEqualTo(1);
45 | assertThat(versions.getMinorVersion()).isEqualTo(0);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/PublishSequenceNumber.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal;
18 |
19 | import com.google.auto.value.AutoValue;
20 | import java.io.Serializable;
21 |
22 | /** A sequence number for a published message, for implementing publish idempotency. */
23 | @AutoValue
24 | public abstract class PublishSequenceNumber implements Serializable {
25 |
26 | /** Create a publish sequence number from its long value. */
27 | public static PublishSequenceNumber of(long sequenceNumber) {
28 | return new AutoValue_PublishSequenceNumber(sequenceNumber);
29 | }
30 |
31 | /** The sequence number that should be set for the first message in a publisher session. */
32 | public static final PublishSequenceNumber FIRST = PublishSequenceNumber.of(0);
33 |
34 | /** Returns the next sequence number that follows the current. */
35 | public PublishSequenceNumber next() {
36 | return PublishSequenceNumber.of(value() + 1);
37 | }
38 |
39 | /** The long value of this publish sequence number. */
40 | public abstract long value();
41 | }
42 |
--------------------------------------------------------------------------------
/generation_config.yaml:
--------------------------------------------------------------------------------
1 | gapic_generator_version: 2.64.1
2 | googleapis_commitish: 5342712986262b93211b136eb4bd6fb79b3764af
3 | libraries_bom_version: 26.71.0
4 | libraries:
5 | - api_shortname: pubsublite
6 | name_pretty: Cloud Pub/Sub Lite
7 | product_documentation: https://cloud.google.com/pubsub/lite/docs
8 | api_description: is designed to provide reliable, many-to-many, asynchronous messaging between applications. Publisher\napplications can send messages to a topic and other applications can\nsubscribe to that topic to receive the messages. By decoupling senders and\nreceivers, Google Cloud Pub/Sub allows developers to communicate between\nindependently written applications.\n\nCompared to Google Pub/Sub, Pub/Sub Lite provides partitioned zonal data\nstorage with predefined capacity. Both products present a similar API, but\nPub/Sub Lite has more usage caveats.\n\nSee the [Google Pub/Sub Lite docs](https://cloud.google.com/pubsub/quickstart-console#before-you-begin) for more details on how to activate\nPub/Sub Lite for your project, as well as guidance on how to choose between\nCloud Pub/Sub and Pub/Sub Lite.
9 | client_documentation: https://cloud.google.com/java/docs/reference/google-cloud-pubsublite/latest/history
10 | release_level: stable
11 | transport: grpc
12 | requires_billing: true
13 | language: java
14 | min_java_version: 8
15 | repo: googleapis/java-pubsublite
16 | repo_short: java-pubsublite
17 | distribution_name: com.google.cloud:google-cloud-pubsublite
18 | codeowner_team: '@googleapis/api-pubsublite'
19 | library_type: GAPIC_COMBO
20 | api_id: pubsublite.googleapis.com
21 | recommended_package: com.google.cloud.pubsublite.cloudpubsub
22 | GAPICs:
23 | - proto_path: google/cloud/pubsublite/v1
24 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/ProjectIdOrNumber.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite;
18 |
19 | import com.google.auto.value.AutoOneOf;
20 | import java.io.Serializable;
21 |
22 | @AutoOneOf(ProjectIdOrNumber.Kind.class)
23 | public abstract class ProjectIdOrNumber implements Serializable {
24 | enum Kind {
25 | NAME,
26 | NUMBER
27 | }
28 |
29 | public abstract Kind getKind();
30 |
31 | public abstract ProjectId name();
32 |
33 | public abstract ProjectNumber number();
34 |
35 | public static ProjectIdOrNumber of(ProjectId name) {
36 | return AutoOneOf_ProjectIdOrNumber.name(name);
37 | }
38 |
39 | public static ProjectIdOrNumber of(ProjectNumber number) {
40 | return AutoOneOf_ProjectIdOrNumber.number(number);
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | switch (getKind()) {
46 | case NAME:
47 | return name().toString();
48 | case NUMBER:
49 | return number().toString();
50 | default:
51 | throw new RuntimeException("Unknown case for ProjectIdOrNumber.");
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/proto-google-cloud-pubsublite-v1/src/main/java/com/google/cloud/pubsublite/proto/FlowControlRequestOrBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | // Generated by the protocol buffer compiler. DO NOT EDIT!
17 | // source: google/cloud/pubsublite/v1/subscriber.proto
18 |
19 | // Protobuf Java Version: 3.25.8
20 | package com.google.cloud.pubsublite.proto;
21 |
22 | public interface FlowControlRequestOrBuilder
23 | extends
24 | // @@protoc_insertion_point(interface_extends:google.cloud.pubsublite.v1.FlowControlRequest)
25 | com.google.protobuf.MessageOrBuilder {
26 |
27 | /**
28 | *
29 | *
30 | *
31 | * The number of message tokens to grant. Must be greater than or equal to 0.
32 | *
33 | *
34 | * int64 allowed_messages = 1;
35 | *
36 | * @return The allowedMessages.
37 | */
38 | long getAllowedMessages();
39 |
40 | /**
41 | *
42 | *
43 | *
44 | * The number of byte tokens to grant. Must be greater than or equal to 0.
45 | *
46 | *
47 | * int64 allowed_bytes = 2;
48 | *
49 | * @return The allowedBytes.
50 | */
51 | long getAllowedBytes();
52 | }
53 |
--------------------------------------------------------------------------------
/.kokoro/common.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Copyright 2020 Google LLC
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | function retry_with_backoff {
17 | attempts_left=$1
18 | sleep_seconds=$2
19 | shift 2
20 | command=$@
21 |
22 |
23 | # store current flag state
24 | flags=$-
25 |
26 | # allow a failures to continue
27 | set +e
28 | ${command}
29 | exit_code=$?
30 |
31 | # restore "e" flag
32 | if [[ ${flags} =~ e ]]
33 | then set -e
34 | else set +e
35 | fi
36 |
37 | if [[ $exit_code == 0 ]]
38 | then
39 | return 0
40 | fi
41 |
42 | # failure
43 | if [[ ${attempts_left} > 0 ]]
44 | then
45 | echo "failure (${exit_code}), sleeping ${sleep_seconds}..."
46 | sleep ${sleep_seconds}
47 | new_attempts=$((${attempts_left} - 1))
48 | new_sleep=$((${sleep_seconds} * 2))
49 | retry_with_backoff ${new_attempts} ${new_sleep} ${command}
50 | fi
51 |
52 | return $exit_code
53 | }
54 |
55 | ## Helper functionss
56 | function now() { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n'; }
57 | function msg() { println "$*" >&2; }
58 | function println() { printf '%s\n' "$(now) $*"; }
59 |
60 | ## Helper comment to trigger updated repo dependency release
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/UncheckedApiPreconditions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal;
18 |
19 | import com.google.api.gax.rpc.ApiException;
20 |
21 | // Reduce the boilerplate of precondition checking by throwing an ApiException.
22 | public class UncheckedApiPreconditions {
23 | private UncheckedApiPreconditions() {}
24 |
25 | public static void checkArgument(boolean test) throws ApiException {
26 | checkArgument(test, "");
27 | }
28 |
29 | public static void checkArgument(boolean test, String description) throws ApiException {
30 | try {
31 | CheckedApiPreconditions.checkArgument(test, description);
32 | } catch (CheckedApiException e) {
33 | throw e.underlying;
34 | }
35 | }
36 |
37 | public static void checkState(boolean test) throws ApiException {
38 | checkState(test, "");
39 | }
40 |
41 | public static void checkState(boolean test, String description) throws ApiException {
42 | try {
43 | CheckedApiPreconditions.checkState(test, description);
44 | } catch (CheckedApiException e) {
45 | throw e.underlying;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/CloudRegion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite;
18 |
19 | import com.google.api.gax.rpc.ApiException;
20 | import com.google.api.gax.rpc.StatusCode.Code;
21 | import com.google.auto.value.AutoValue;
22 | import com.google.cloud.pubsublite.internal.CheckedApiException;
23 | import java.io.Serializable;
24 |
25 | /** A wrapped string representing a Google Cloud region. */
26 | @AutoValue
27 | public abstract class CloudRegion implements Serializable {
28 | private static final long serialVersionUID = 6814654654L;
29 |
30 | /** Construct a CloudRegion from a string. */
31 | public static CloudRegion of(String value) throws ApiException {
32 | String[] splits = value.split("-", -1);
33 | if (splits.length != 2) {
34 | throw new CheckedApiException("Invalid region name: " + value, Code.INVALID_ARGUMENT)
35 | .underlying;
36 | }
37 | return new AutoValue_CloudRegion(value);
38 | }
39 |
40 | /** The string representing this region. */
41 | public abstract String value();
42 |
43 | /** {@inheritDoc} */
44 | @Override
45 | public String toString() {
46 | return value();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/SequencedPublisher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal;
18 |
19 | import com.google.api.core.ApiFuture;
20 | import com.google.api.core.ApiService;
21 | import com.google.cloud.pubsublite.proto.PubSubMessage;
22 | import java.io.Flushable;
23 |
24 | /**
25 | * A PubSub Lite publisher that requires a sequence number assigned to every message, for publish
26 | * idempotency. Errors are handled out of band. Thread safe.
27 | */
28 | public interface SequencedPublisher extends ApiService, Flushable {
29 | /**
30 | * Publish a new message with an assigned sequence number.
31 | *
32 | * Behavior is undefined if a call to flush() is outstanding or close() has already been
33 | * called. This method never blocks.
34 | *
35 | *
Guarantees that if a single publish future has an exception set, all publish calls made
36 | * after that will also have an exception set.
37 | */
38 | ApiFuture publish(PubSubMessage message, PublishSequenceNumber sequenceNumber);
39 |
40 | /** Attempts to cancel all outstanding publishes. */
41 | void cancelOutstandingPublishes();
42 | }
43 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/test/java/com/google/cloud/pubsublite/MessageMetadataTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite;
18 |
19 | import static com.google.common.truth.Truth.assertThat;
20 | import static org.junit.Assert.assertThrows;
21 |
22 | import com.google.api.gax.rpc.ApiException;
23 | import org.junit.Test;
24 | import org.junit.runner.RunWith;
25 | import org.junit.runners.JUnit4;
26 |
27 | @RunWith(JUnit4.class)
28 | public final class MessageMetadataTest {
29 | @Test
30 | public void roundTripThroughString() {
31 | MessageMetadata metadata = MessageMetadata.of(Partition.of(10), Offset.of(20));
32 | MessageMetadata metadata2 = MessageMetadata.decode(metadata.encode());
33 | assertThat(metadata2).isEqualTo(metadata);
34 | }
35 |
36 | @Test
37 | public void invalidString() {
38 | assertThrows(ApiException.class, () -> MessageMetadata.decode("999"));
39 | }
40 |
41 | @Test
42 | public void invalidPartition() {
43 | assertThrows(ApiException.class, () -> MessageMetadata.decode("abc:999"));
44 | }
45 |
46 | @Test
47 | public void invalidOffset() {
48 | assertThrows(ApiException.class, () -> MessageMetadata.decode("999:abc"));
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/BlockingPullSubscriber.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal;
18 |
19 | import com.google.api.core.ApiFuture;
20 | import com.google.cloud.pubsublite.proto.SequencedMessage;
21 | import java.util.Optional;
22 | import javax.annotation.concurrent.ThreadSafe;
23 |
24 | @ThreadSafe
25 | public interface BlockingPullSubscriber extends AutoCloseable {
26 |
27 | /**
28 | * Returns a {@link ApiFuture} that will be completed when there are messages available.
29 | * Unfinished existing {@link ApiFuture} returned by onData() will be abandoned and superseded by
30 | * new onData() call.
31 | *
32 | * {@link CheckedApiException} will be set to the Future if there is underlying permanent
33 | * error.
34 | */
35 | ApiFuture onData();
36 |
37 | /**
38 | * Pull messages if there is any ready to deliver. Any message will only be delivered to one call
39 | * if there are multiple concurrent calls.
40 | *
41 | * @throws CheckedApiException if there is underlying permanent error.
42 | */
43 | Optional messageIfAvailable() throws CheckedApiException;
44 |
45 | void close();
46 | }
47 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/wire/ApiExceptionPublisher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal.wire;
18 |
19 | import static com.google.cloud.pubsublite.internal.ExtractStatus.toClientFuture;
20 |
21 | import com.google.api.core.ApiFuture;
22 | import com.google.api.gax.rpc.ApiException;
23 | import com.google.cloud.pubsublite.internal.ProxyService;
24 | import com.google.cloud.pubsublite.internal.Publisher;
25 | import com.google.cloud.pubsublite.proto.PubSubMessage;
26 | import java.io.IOException;
27 |
28 | public class ApiExceptionPublisher extends ProxyService implements Publisher {
29 | private final Publisher publisher;
30 |
31 | ApiExceptionPublisher(Publisher publisher) throws ApiException {
32 | super(publisher);
33 | this.publisher = publisher;
34 | }
35 |
36 | @Override
37 | public ApiFuture publish(PubSubMessage message) {
38 | return toClientFuture(publisher.publish(message));
39 | }
40 |
41 | @Override
42 | public void cancelOutstandingPublishes() {
43 | publisher.cancelOutstandingPublishes();
44 | }
45 |
46 | @Override
47 | public void flush() throws IOException {
48 | publisher.flush();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/.github/workflows/update_generation_config.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2024 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # GitHub action job to test core java library features on
15 | # downstream client libraries before they are released.
16 | name: Update generation configuration
17 | on:
18 | schedule:
19 | - cron: '0 2 * * *'
20 | workflow_dispatch:
21 |
22 | jobs:
23 | update-generation-config:
24 | runs-on: ubuntu-24.04
25 | env:
26 | # the branch into which the pull request is merged
27 | base_branch: main
28 | steps:
29 | - uses: actions/checkout@v4
30 | with:
31 | fetch-depth: 0
32 | token: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
33 | - name: Install Dependencies
34 | shell: bash
35 | run: sudo apt-get update && sudo apt-get install -y libxml2-utils
36 | - name: Update params in generation config to latest
37 | shell: bash
38 | run: |
39 | set -x
40 | [ -z "$(git config user.email)" ] && git config --global user.email "cloud-java-bot@google.com"
41 | [ -z "$(git config user.name)" ] && git config --global user.name "cloud-java-bot"
42 | bash .github/scripts/update_generation_config.sh \
43 | --base_branch "${base_branch}" \
44 | --repo ${{ github.repository }}
45 | env:
46 | GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
47 |
48 |
--------------------------------------------------------------------------------
/proto-google-cloud-pubsublite-v1/src/main/java/com/google/cloud/pubsublite/proto/DeleteTopicRequestOrBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | // Generated by the protocol buffer compiler. DO NOT EDIT!
17 | // source: google/cloud/pubsublite/v1/admin.proto
18 |
19 | // Protobuf Java Version: 3.25.8
20 | package com.google.cloud.pubsublite.proto;
21 |
22 | public interface DeleteTopicRequestOrBuilder
23 | extends
24 | // @@protoc_insertion_point(interface_extends:google.cloud.pubsublite.v1.DeleteTopicRequest)
25 | com.google.protobuf.MessageOrBuilder {
26 |
27 | /**
28 | *
29 | *
30 | *
31 | * Required. The name of the topic to delete.
32 | *
33 | *
34 | *
35 | * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... }
36 | *
37 | *
38 | * @return The name.
39 | */
40 | java.lang.String getName();
41 |
42 | /**
43 | *
44 | *
45 | *
46 | * Required. The name of the topic to delete.
47 | *
48 | *
49 | *
50 | * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... }
51 | *
52 | *
53 | * @return The bytes for name.
54 | */
55 | com.google.protobuf.ByteString getNameBytes();
56 | }
57 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/SeekTarget.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite;
18 |
19 | import com.google.auto.value.AutoOneOf;
20 | import com.google.protobuf.Timestamp;
21 | import java.io.Serializable;
22 |
23 | /** The target location to seek a subscription to. */
24 | @AutoOneOf(SeekTarget.Kind.class)
25 | public abstract class SeekTarget implements Serializable {
26 | public enum Kind {
27 | BACKLOG_LOCATION,
28 | PUBLISH_TIME,
29 | EVENT_TIME,
30 | }
31 |
32 | public abstract SeekTarget.Kind getKind();
33 |
34 | public abstract BacklogLocation backlogLocation();
35 |
36 | public abstract Timestamp publishTime();
37 |
38 | public abstract Timestamp eventTime();
39 |
40 | /** Seek to a named backlog location. */
41 | public static SeekTarget of(BacklogLocation location) {
42 | return AutoOneOf_SeekTarget.backlogLocation(location);
43 | }
44 |
45 | /** Seek to a message publish timestamp. */
46 | public static SeekTarget ofPublishTime(Timestamp time) {
47 | return AutoOneOf_SeekTarget.publishTime(time);
48 | }
49 |
50 | /** Seek to a message event timestamp. */
51 | public static SeekTarget ofEventTime(Timestamp time) {
52 | return AutoOneOf_SeekTarget.eventTime(time);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/.github/workflows/hermetic_library_generation.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2024 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # GitHub action job to test core java library features on
15 | # downstream client libraries before they are released.
16 | name: Hermetic library generation upon generation config change through pull requests
17 | on:
18 | pull_request:
19 |
20 | env:
21 | REPO_FULL_NAME: ${{ github.event.pull_request.head.repo.full_name }}
22 | GITHUB_REPOSITORY: ${{ github.repository }}
23 | jobs:
24 | library_generation:
25 | runs-on: ubuntu-latest
26 | steps:
27 | - name: Determine whether the pull request comes from a fork
28 | run: |
29 | if [[ "${GITHUB_REPOSITORY}" != "${REPO_FULL_NAME}" ]]; then
30 | echo "This PR comes from a fork. Skip library generation."
31 | echo "SHOULD_RUN=false" >> $GITHUB_ENV
32 | else
33 | echo "SHOULD_RUN=true" >> $GITHUB_ENV
34 | fi
35 | - uses: actions/checkout@v4
36 | if: env.SHOULD_RUN == 'true'
37 | with:
38 | fetch-depth: 0
39 | token: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
40 | - uses: googleapis/sdk-platform-java/.github/scripts@v2.64.2
41 | if: env.SHOULD_RUN == 'true'
42 | with:
43 | base_ref: ${{ github.base_ref }}
44 | head_ref: ${{ github.head_ref }}
45 | token: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
46 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/test/java/com/google/cloud/pubsublite/v1/MockAdminService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.v1;
18 |
19 | import com.google.api.core.BetaApi;
20 | import com.google.api.gax.grpc.testing.MockGrpcService;
21 | import com.google.protobuf.AbstractMessage;
22 | import io.grpc.ServerServiceDefinition;
23 | import java.util.List;
24 | import javax.annotation.Generated;
25 |
26 | @BetaApi
27 | @Generated("by gapic-generator-java")
28 | public class MockAdminService implements MockGrpcService {
29 | private final MockAdminServiceImpl serviceImpl;
30 |
31 | public MockAdminService() {
32 | serviceImpl = new MockAdminServiceImpl();
33 | }
34 |
35 | @Override
36 | public List getRequests() {
37 | return serviceImpl.getRequests();
38 | }
39 |
40 | @Override
41 | public void addResponse(AbstractMessage response) {
42 | serviceImpl.addResponse(response);
43 | }
44 |
45 | @Override
46 | public void addException(Exception exception) {
47 | serviceImpl.addException(exception);
48 | }
49 |
50 | @Override
51 | public ServerServiceDefinition getServiceDefinition() {
52 | return serviceImpl.bindService();
53 | }
54 |
55 | @Override
56 | public void reset() {
57 | serviceImpl.reset();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/test/java/com/google/cloud/pubsublite/v1/MockCursorService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.v1;
18 |
19 | import com.google.api.core.BetaApi;
20 | import com.google.api.gax.grpc.testing.MockGrpcService;
21 | import com.google.protobuf.AbstractMessage;
22 | import io.grpc.ServerServiceDefinition;
23 | import java.util.List;
24 | import javax.annotation.Generated;
25 |
26 | @BetaApi
27 | @Generated("by gapic-generator-java")
28 | public class MockCursorService implements MockGrpcService {
29 | private final MockCursorServiceImpl serviceImpl;
30 |
31 | public MockCursorService() {
32 | serviceImpl = new MockCursorServiceImpl();
33 | }
34 |
35 | @Override
36 | public List getRequests() {
37 | return serviceImpl.getRequests();
38 | }
39 |
40 | @Override
41 | public void addResponse(AbstractMessage response) {
42 | serviceImpl.addResponse(response);
43 | }
44 |
45 | @Override
46 | public void addException(Exception exception) {
47 | serviceImpl.addException(exception);
48 | }
49 |
50 | @Override
51 | public ServerServiceDefinition getServiceDefinition() {
52 | return serviceImpl.bindService();
53 | }
54 |
55 | @Override
56 | public void reset() {
57 | serviceImpl.reset();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/cloudpubsub/NackHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.cloudpubsub;
18 |
19 | import com.google.api.core.ApiFuture;
20 | import com.google.api.core.ApiFutures;
21 | import com.google.api.gax.rpc.StatusCode.Code;
22 | import com.google.cloud.pubsublite.internal.CheckedApiException;
23 | import com.google.pubsub.v1.PubsubMessage;
24 |
25 | /**
26 | * A NackHandler handles when nack() is called in a user's AckReplyConsumer. Pub/Sub Lite does not
27 | * have a concept of 'nack'. When nack() is called in an AckReplyConsumerr, nack(message) is called
28 | * with the nacked message.
29 | *
30 | * If the returned future is successful, the message is acknowledged. If the future fails, the
31 | * subscriber client will be failed. The default behavior is to immediately fail the client.
32 | */
33 | public interface NackHandler {
34 | default ApiFuture nack(PubsubMessage message) {
35 | return ApiFutures.immediateFailedFuture(
36 | new CheckedApiException(
37 | "You may not nack messages by default when using a PubSub Lite client. See"
38 | + " NackHandler for how to customize this.",
39 | Code.UNIMPLEMENTED)
40 | .underlying);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/proto-google-cloud-pubsublite-v1/src/main/java/com/google/cloud/pubsublite/proto/GetTopicRequestOrBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | // Generated by the protocol buffer compiler. DO NOT EDIT!
17 | // source: google/cloud/pubsublite/v1/admin.proto
18 |
19 | // Protobuf Java Version: 3.25.8
20 | package com.google.cloud.pubsublite.proto;
21 |
22 | public interface GetTopicRequestOrBuilder
23 | extends
24 | // @@protoc_insertion_point(interface_extends:google.cloud.pubsublite.v1.GetTopicRequest)
25 | com.google.protobuf.MessageOrBuilder {
26 |
27 | /**
28 | *
29 | *
30 | *
31 | * Required. The name of the topic whose configuration to return.
32 | *
33 | *
34 | *
35 | * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... }
36 | *
37 | *
38 | * @return The name.
39 | */
40 | java.lang.String getName();
41 |
42 | /**
43 | *
44 | *
45 | *
46 | * Required. The name of the topic whose configuration to return.
47 | *
48 | *
49 | *
50 | * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... }
51 | *
52 | *
53 | * @return The bytes for name.
54 | */
55 | com.google.protobuf.ByteString getNameBytes();
56 | }
57 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/test/java/com/google/cloud/pubsublite/v1/MockPublisherService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.v1;
18 |
19 | import com.google.api.core.BetaApi;
20 | import com.google.api.gax.grpc.testing.MockGrpcService;
21 | import com.google.protobuf.AbstractMessage;
22 | import io.grpc.ServerServiceDefinition;
23 | import java.util.List;
24 | import javax.annotation.Generated;
25 |
26 | @BetaApi
27 | @Generated("by gapic-generator-java")
28 | public class MockPublisherService implements MockGrpcService {
29 | private final MockPublisherServiceImpl serviceImpl;
30 |
31 | public MockPublisherService() {
32 | serviceImpl = new MockPublisherServiceImpl();
33 | }
34 |
35 | @Override
36 | public List getRequests() {
37 | return serviceImpl.getRequests();
38 | }
39 |
40 | @Override
41 | public void addResponse(AbstractMessage response) {
42 | serviceImpl.addResponse(response);
43 | }
44 |
45 | @Override
46 | public void addException(Exception exception) {
47 | serviceImpl.addException(exception);
48 | }
49 |
50 | @Override
51 | public ServerServiceDefinition getServiceDefinition() {
52 | return serviceImpl.bindService();
53 | }
54 |
55 | @Override
56 | public void reset() {
57 | serviceImpl.reset();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/proto-google-cloud-pubsublite-v1/src/main/java/com/google/cloud/pubsublite/proto/DeleteSubscriptionRequestOrBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | // Generated by the protocol buffer compiler. DO NOT EDIT!
17 | // source: google/cloud/pubsublite/v1/admin.proto
18 |
19 | // Protobuf Java Version: 3.25.8
20 | package com.google.cloud.pubsublite.proto;
21 |
22 | public interface DeleteSubscriptionRequestOrBuilder
23 | extends
24 | // @@protoc_insertion_point(interface_extends:google.cloud.pubsublite.v1.DeleteSubscriptionRequest)
25 | com.google.protobuf.MessageOrBuilder {
26 |
27 | /**
28 | *
29 | *
30 | *
31 | * Required. The name of the subscription to delete.
32 | *
33 | *
34 | *
35 | * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... }
36 | *
37 | *
38 | * @return The name.
39 | */
40 | java.lang.String getName();
41 |
42 | /**
43 | *
44 | *
45 | *
46 | * Required. The name of the subscription to delete.
47 | *
48 | *
49 | *
50 | * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... }
51 | *
52 | *
53 | * @return The bytes for name.
54 | */
55 | com.google.protobuf.ByteString getNameBytes();
56 | }
57 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/test/java/com/google/cloud/pubsublite/v1/MockSubscriberService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.v1;
18 |
19 | import com.google.api.core.BetaApi;
20 | import com.google.api.gax.grpc.testing.MockGrpcService;
21 | import com.google.protobuf.AbstractMessage;
22 | import io.grpc.ServerServiceDefinition;
23 | import java.util.List;
24 | import javax.annotation.Generated;
25 |
26 | @BetaApi
27 | @Generated("by gapic-generator-java")
28 | public class MockSubscriberService implements MockGrpcService {
29 | private final MockSubscriberServiceImpl serviceImpl;
30 |
31 | public MockSubscriberService() {
32 | serviceImpl = new MockSubscriberServiceImpl();
33 | }
34 |
35 | @Override
36 | public List getRequests() {
37 | return serviceImpl.getRequests();
38 | }
39 |
40 | @Override
41 | public void addResponse(AbstractMessage response) {
42 | serviceImpl.addResponse(response);
43 | }
44 |
45 | @Override
46 | public void addException(Exception exception) {
47 | serviceImpl.addException(exception);
48 | }
49 |
50 | @Override
51 | public ServerServiceDefinition getServiceDefinition() {
52 | return serviceImpl.bindService();
53 | }
54 |
55 | @Override
56 | public void reset() {
57 | serviceImpl.reset();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/test/java/com/google/cloud/pubsublite/v1/MockTopicStatsService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.v1;
18 |
19 | import com.google.api.core.BetaApi;
20 | import com.google.api.gax.grpc.testing.MockGrpcService;
21 | import com.google.protobuf.AbstractMessage;
22 | import io.grpc.ServerServiceDefinition;
23 | import java.util.List;
24 | import javax.annotation.Generated;
25 |
26 | @BetaApi
27 | @Generated("by gapic-generator-java")
28 | public class MockTopicStatsService implements MockGrpcService {
29 | private final MockTopicStatsServiceImpl serviceImpl;
30 |
31 | public MockTopicStatsService() {
32 | serviceImpl = new MockTopicStatsServiceImpl();
33 | }
34 |
35 | @Override
36 | public List getRequests() {
37 | return serviceImpl.getRequests();
38 | }
39 |
40 | @Override
41 | public void addResponse(AbstractMessage response) {
42 | serviceImpl.addResponse(response);
43 | }
44 |
45 | @Override
46 | public void addException(Exception exception) {
47 | serviceImpl.addException(exception);
48 | }
49 |
50 | @Override
51 | public ServerServiceDefinition getServiceDefinition() {
52 | return serviceImpl.bindService();
53 | }
54 |
55 | @Override
56 | public void reset() {
57 | serviceImpl.reset();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/.kokoro/dependencies.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Copyright 2019 Google LLC
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | set -eo pipefail
17 | shopt -s nullglob
18 |
19 | ## Get the directory of the build script
20 | scriptDir=$(realpath $(dirname "${BASH_SOURCE[0]}"))
21 | ## cd to the parent directory, i.e. the root of the git repo
22 | cd ${scriptDir}/..
23 |
24 | # include common functions
25 | source ${scriptDir}/common.sh
26 |
27 | # Print out Java
28 | java -version
29 | echo $JOB_TYPE
30 |
31 | function determineMavenOpts() {
32 | local javaVersion=$(
33 | # filter down to the version line, then pull out the version between quotes,
34 | # then trim the version number down to its minimal number (removing any
35 | # update or suffix number).
36 | java -version 2>&1 | grep "version" \
37 | | sed -E 's/^.*"(.*?)".*$/\1/g' \
38 | | sed -E 's/^(1\.[0-9]\.0).*$/\1/g'
39 | )
40 |
41 | if [[ $javaVersion == 17* ]]
42 | then
43 | # MaxPermSize is no longer supported as of jdk 17
44 | echo -n "-Xmx1024m"
45 | else
46 | echo -n "-Xmx1024m -XX:MaxPermSize=128m"
47 | fi
48 | }
49 |
50 | export MAVEN_OPTS=$(determineMavenOpts)
51 |
52 | # this should run maven enforcer
53 | retry_with_backoff 3 10 \
54 | mvn install -B -V -ntp \
55 | -DskipTests=true \
56 | -Dmaven.javadoc.skip=true \
57 | -Dclirr.skip=true
58 |
59 | mvn -B dependency:analyze -DfailOnWarning=true
60 |
--------------------------------------------------------------------------------
/proto-google-cloud-pubsublite-v1/src/main/java/com/google/cloud/pubsublite/proto/GetTopicPartitionsRequestOrBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | // Generated by the protocol buffer compiler. DO NOT EDIT!
17 | // source: google/cloud/pubsublite/v1/admin.proto
18 |
19 | // Protobuf Java Version: 3.25.8
20 | package com.google.cloud.pubsublite.proto;
21 |
22 | public interface GetTopicPartitionsRequestOrBuilder
23 | extends
24 | // @@protoc_insertion_point(interface_extends:google.cloud.pubsublite.v1.GetTopicPartitionsRequest)
25 | com.google.protobuf.MessageOrBuilder {
26 |
27 | /**
28 | *
29 | *
30 | *
31 | * Required. The topic whose partition information to return.
32 | *
33 | *
34 | *
35 | * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... }
36 | *
37 | *
38 | * @return The name.
39 | */
40 | java.lang.String getName();
41 |
42 | /**
43 | *
44 | *
45 | *
46 | * Required. The topic whose partition information to return.
47 | *
48 | *
49 | *
50 | * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... }
51 | *
52 | *
53 | * @return The bytes for name.
54 | */
55 | com.google.protobuf.ByteString getNameBytes();
56 | }
57 |
--------------------------------------------------------------------------------
/proto-google-cloud-pubsublite-v1/src/main/java/com/google/cloud/pubsublite/proto/GetSubscriptionRequestOrBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | // Generated by the protocol buffer compiler. DO NOT EDIT!
17 | // source: google/cloud/pubsublite/v1/admin.proto
18 |
19 | // Protobuf Java Version: 3.25.8
20 | package com.google.cloud.pubsublite.proto;
21 |
22 | public interface GetSubscriptionRequestOrBuilder
23 | extends
24 | // @@protoc_insertion_point(interface_extends:google.cloud.pubsublite.v1.GetSubscriptionRequest)
25 | com.google.protobuf.MessageOrBuilder {
26 |
27 | /**
28 | *
29 | *
30 | *
31 | * Required. The name of the subscription whose configuration to return.
32 | *
33 | *
34 | *
35 | * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... }
36 | *
37 | *
38 | * @return The name.
39 | */
40 | java.lang.String getName();
41 |
42 | /**
43 | *
44 | *
45 | *
46 | * Required. The name of the subscription whose configuration to return.
47 | *
48 | *
49 | *
50 | * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... }
51 | *
52 | *
53 | * @return The bytes for name.
54 | */
55 | com.google.protobuf.ByteString getNameBytes();
56 | }
57 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/test/java/com/google/cloud/pubsublite/v1/MockPartitionAssignmentService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.v1;
18 |
19 | import com.google.api.core.BetaApi;
20 | import com.google.api.gax.grpc.testing.MockGrpcService;
21 | import com.google.protobuf.AbstractMessage;
22 | import io.grpc.ServerServiceDefinition;
23 | import java.util.List;
24 | import javax.annotation.Generated;
25 |
26 | @BetaApi
27 | @Generated("by gapic-generator-java")
28 | public class MockPartitionAssignmentService implements MockGrpcService {
29 | private final MockPartitionAssignmentServiceImpl serviceImpl;
30 |
31 | public MockPartitionAssignmentService() {
32 | serviceImpl = new MockPartitionAssignmentServiceImpl();
33 | }
34 |
35 | @Override
36 | public List getRequests() {
37 | return serviceImpl.getRequests();
38 | }
39 |
40 | @Override
41 | public void addResponse(AbstractMessage response) {
42 | serviceImpl.addResponse(response);
43 | }
44 |
45 | @Override
46 | public void addException(Exception exception) {
47 | serviceImpl.addException(exception);
48 | }
49 |
50 | @Override
51 | public ServerServiceDefinition getServiceDefinition() {
52 | return serviceImpl.bindService();
53 | }
54 |
55 | @Override
56 | public void reset() {
57 | serviceImpl.reset();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/samples/snippets/generated/com/google/cloud/pubsublite/v1/adminservice/deletetopic/SyncDeleteTopicString.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.v1.samples;
18 |
19 | // [START pubsublite_v1_generated_AdminService_DeleteTopic_String_sync]
20 | import com.google.cloud.pubsublite.proto.TopicName;
21 | import com.google.cloud.pubsublite.v1.AdminServiceClient;
22 | import com.google.protobuf.Empty;
23 |
24 | public class SyncDeleteTopicString {
25 |
26 | public static void main(String[] args) throws Exception {
27 | syncDeleteTopicString();
28 | }
29 |
30 | public static void syncDeleteTopicString() throws Exception {
31 | // This snippet has been automatically generated and should be regarded as a code template only.
32 | // It will require modifications to work:
33 | // - It may require correct/in-range values for request initialization.
34 | // - It may require specifying regional endpoints when creating the service client as shown in
35 | // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
36 | try (AdminServiceClient adminServiceClient = AdminServiceClient.create()) {
37 | String name = TopicName.of("[PROJECT]", "[LOCATION]", "[TOPIC]").toString();
38 | adminServiceClient.deleteTopic(name);
39 | }
40 | }
41 | }
42 | // [END pubsublite_v1_generated_AdminService_DeleteTopic_String_sync]
43 |
--------------------------------------------------------------------------------
/samples/snippets/generated/com/google/cloud/pubsublite/v1/adminservice/gettopic/SyncGetTopicString.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.v1.samples;
18 |
19 | // [START pubsublite_v1_generated_AdminService_GetTopic_String_sync]
20 | import com.google.cloud.pubsublite.proto.Topic;
21 | import com.google.cloud.pubsublite.proto.TopicName;
22 | import com.google.cloud.pubsublite.v1.AdminServiceClient;
23 |
24 | public class SyncGetTopicString {
25 |
26 | public static void main(String[] args) throws Exception {
27 | syncGetTopicString();
28 | }
29 |
30 | public static void syncGetTopicString() throws Exception {
31 | // This snippet has been automatically generated and should be regarded as a code template only.
32 | // It will require modifications to work:
33 | // - It may require correct/in-range values for request initialization.
34 | // - It may require specifying regional endpoints when creating the service client as shown in
35 | // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
36 | try (AdminServiceClient adminServiceClient = AdminServiceClient.create()) {
37 | String name = TopicName.of("[PROJECT]", "[LOCATION]", "[TOPIC]").toString();
38 | Topic response = adminServiceClient.getTopic(name);
39 | }
40 | }
41 | }
42 | // [END pubsublite_v1_generated_AdminService_GetTopic_String_sync]
43 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/test/java/com/google/cloud/pubsublite/internal/wire/AssignerSettingsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.internal.wire;
18 |
19 | import static org.mockito.Mockito.mock;
20 |
21 | import com.google.cloud.pubsublite.CloudRegion;
22 | import com.google.cloud.pubsublite.CloudZone;
23 | import com.google.cloud.pubsublite.ProjectNumber;
24 | import com.google.cloud.pubsublite.SubscriptionName;
25 | import com.google.cloud.pubsublite.SubscriptionPath;
26 | import com.google.cloud.pubsublite.v1.PartitionAssignmentServiceClient;
27 | import org.junit.Test;
28 | import org.junit.runner.RunWith;
29 | import org.junit.runners.JUnit4;
30 |
31 | @RunWith(JUnit4.class)
32 | public class AssignerSettingsTest {
33 | @Test
34 | public void testBuilder() {
35 | AssignerSettings unusedSettings =
36 | AssignerSettings.newBuilder()
37 | .setSubscriptionPath(
38 | SubscriptionPath.newBuilder()
39 | .setLocation(CloudZone.of(CloudRegion.of("us-central1"), 'a'))
40 | .setProject(ProjectNumber.of(3))
41 | .setName(SubscriptionName.of("abc"))
42 | .build())
43 | .setReceiver(mock(PartitionAssignmentReceiver.class))
44 | .setServiceClient(mock(PartitionAssignmentServiceClient.class))
45 | .build();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/samples/snippets/generated/com/google/cloud/pubsublite/v1/adminservice/deletetopic/SyncDeleteTopicTopicname.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.v1.samples;
18 |
19 | // [START pubsublite_v1_generated_AdminService_DeleteTopic_Topicname_sync]
20 | import com.google.cloud.pubsublite.proto.TopicName;
21 | import com.google.cloud.pubsublite.v1.AdminServiceClient;
22 | import com.google.protobuf.Empty;
23 |
24 | public class SyncDeleteTopicTopicname {
25 |
26 | public static void main(String[] args) throws Exception {
27 | syncDeleteTopicTopicname();
28 | }
29 |
30 | public static void syncDeleteTopicTopicname() throws Exception {
31 | // This snippet has been automatically generated and should be regarded as a code template only.
32 | // It will require modifications to work:
33 | // - It may require correct/in-range values for request initialization.
34 | // - It may require specifying regional endpoints when creating the service client as shown in
35 | // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
36 | try (AdminServiceClient adminServiceClient = AdminServiceClient.create()) {
37 | TopicName name = TopicName.of("[PROJECT]", "[LOCATION]", "[TOPIC]");
38 | adminServiceClient.deleteTopic(name);
39 | }
40 | }
41 | }
42 | // [END pubsublite_v1_generated_AdminService_DeleteTopic_Topicname_sync]
43 |
--------------------------------------------------------------------------------
/samples/snippets/generated/com/google/cloud/pubsublite/v1/adminservice/create/SyncCreateSetEndpoint.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.v1.samples;
18 |
19 | // [START pubsublite_v1_generated_AdminService_Create_SetEndpoint_sync]
20 | import com.google.cloud.pubsublite.v1.AdminServiceClient;
21 | import com.google.cloud.pubsublite.v1.AdminServiceSettings;
22 | import com.google.cloud.pubsublite.v1.myEndpoint;
23 |
24 | public class SyncCreateSetEndpoint {
25 |
26 | public static void main(String[] args) throws Exception {
27 | syncCreateSetEndpoint();
28 | }
29 |
30 | public static void syncCreateSetEndpoint() throws Exception {
31 | // This snippet has been automatically generated and should be regarded as a code template only.
32 | // It will require modifications to work:
33 | // - It may require correct/in-range values for request initialization.
34 | // - It may require specifying regional endpoints when creating the service client as shown in
35 | // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
36 | AdminServiceSettings adminServiceSettings =
37 | AdminServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
38 | AdminServiceClient adminServiceClient = AdminServiceClient.create(adminServiceSettings);
39 | }
40 | }
41 | // [END pubsublite_v1_generated_AdminService_Create_SetEndpoint_sync]
42 |
--------------------------------------------------------------------------------
/samples/snippets/generated/com/google/cloud/pubsublite/v1/adminservice/gettopic/SyncGetTopicTopicname.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2025 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.cloud.pubsublite.v1.samples;
18 |
19 | // [START pubsublite_v1_generated_AdminService_GetTopic_Topicname_sync]
20 | import com.google.cloud.pubsublite.proto.Topic;
21 | import com.google.cloud.pubsublite.proto.TopicName;
22 | import com.google.cloud.pubsublite.v1.AdminServiceClient;
23 |
24 | public class SyncGetTopicTopicname {
25 |
26 | public static void main(String[] args) throws Exception {
27 | syncGetTopicTopicname();
28 | }
29 |
30 | public static void syncGetTopicTopicname() throws Exception {
31 | // This snippet has been automatically generated and should be regarded as a code template only.
32 | // It will require modifications to work:
33 | // - It may require correct/in-range values for request initialization.
34 | // - It may require specifying regional endpoints when creating the service client as shown in
35 | // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
36 | try (AdminServiceClient adminServiceClient = AdminServiceClient.create()) {
37 | TopicName name = TopicName.of("[PROJECT]", "[LOCATION]", "[TOPIC]");
38 | Topic response = adminServiceClient.getTopic(name);
39 | }
40 | }
41 | }
42 | // [END pubsublite_v1_generated_AdminService_GetTopic_Topicname_sync]
43 |
--------------------------------------------------------------------------------
/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/AlarmFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.google.cloud.pubsublite.internal;
17 |
18 | import static java.util.concurrent.TimeUnit.NANOSECONDS;
19 |
20 | import com.google.cloud.pubsublite.internal.wire.SystemExecutors;
21 | import com.google.common.flogger.GoogleLogger;
22 | import java.time.Duration;
23 | import java.util.concurrent.Future;
24 |
25 | // An alarm factory comes with a builtin delay and constructs a future which runs that delay after
26 | // it finishes.
27 | public interface AlarmFactory {
28 | Future> newAlarm(Runnable runnable);
29 |
30 | // Get around lack of interface support for private static members in java 8
31 | final class Internal {
32 | private static final GoogleLogger LOGGER = GoogleLogger.forEnclosingClass();
33 | }
34 | ;
35 |
36 | static AlarmFactory create(Duration duration) {
37 | return runnable ->
38 | SystemExecutors.getAlarmExecutor()
39 | .scheduleWithFixedDelay(
40 | () -> {
41 | try {
42 | runnable.run();
43 | } catch (Throwable t) {
44 | Internal.LOGGER.atSevere().withCause(t).log("Alarm leaked exception.");
45 | }
46 | },
47 | 0,
48 | duration.toNanos(),
49 | NANOSECONDS);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------