Skip to content

Commit 08e77d4

Browse files
feat: add randomly generated UUID to outgoing initial streaming pull requests (#77)
* google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/FakePublisherServiceImpl.java * Ensure that if a batch is started and the timeout completes before the currently outstanding message has finished publishing with an ordering key that the last batch does in fact get published. * add back in unit test * feat: add randomly generated UUID to outgoing initial streaming pull requests for better ordering keys affinity
1 parent d0ab525 commit 08e77d4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/StreamingSubscriberConnection.java

+9
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.google.pubsub.v1.StreamingPullResponse;
4646
import io.grpc.Status;
4747
import java.util.List;
48+
import java.util.UUID;
4849
import java.util.concurrent.ScheduledExecutorService;
4950
import java.util.concurrent.TimeUnit;
5051
import java.util.concurrent.atomic.AtomicLong;
@@ -77,6 +78,13 @@ final class StreamingSubscriberConnection extends AbstractApiService implements
7778
private final Lock lock = new ReentrantLock();
7879
private ClientStream<StreamingPullRequest> clientStream;
7980

81+
/**
82+
* The same clientId is used across all streaming pull connections that are created. This is
83+
* intentional, as it indicates to the server that any guarantees made for a stream that
84+
* disconnected will be made for the stream that is created to replace it.
85+
*/
86+
private final String clientId = UUID.randomUUID().toString();
87+
8088
public StreamingSubscriberConnection(
8189
String subscription,
8290
MessageReceiver receiver,
@@ -200,6 +208,7 @@ private void initialize() {
200208
StreamingPullRequest.newBuilder()
201209
.setSubscription(subscription)
202210
.setStreamAckDeadlineSeconds(60)
211+
.setClientId(clientId)
203212
.build());
204213

205214
/**

0 commit comments

Comments
 (0)