PullRequest request = PullRequest.newBuilder() .setSubscription(subscription.getPath()) .setReturnImmediately(returnImmediately) .setMaxMessages(batchSize)
public static SubscriptionPath subscriptionPathFromName( String projectId, String subscriptionName) { return new SubscriptionPath( String.format("projects/%s/subscriptions/%s", projectId, subscriptionName)); }
requestTimeMsSinceEpoch); checkState( subscription.equals(STATE.expectedSubscription), "Subscription %s does not match expected %s", subscription,
@Test public void pullOneMessage() throws IOException { String expectedSubscription = SUBSCRIPTION.getPath(); final PullRequest expectedRequest = PullRequest.newBuilder()
stepContext.addInput( PropertyNames.PUBSUB_SUBSCRIPTION, overriddenTransform.getSubscription().getV1Beta1Path()); } else { stepContext.addInput(
new PullRequest().setReturnImmediately(returnImmediately).setMaxMessages(batchSize); PullResponse response = pubsub.projects().subscriptions().pull(subscription.getPath(), request).execute(); if (response.getReceivedMessages() == null || response.getReceivedMessages().isEmpty()) { return ImmutableList.of();
checkState(inPullMode(), "Can only modify ack deadline in pull mode"); checkState( subscription.equals(STATE.expectedSubscription), "Subscription %s does not match expected %s", subscription,
assertThat(checkpoint.subscriptionPath, equalTo(createdSubscription.getPath()));
@Test public void pullOneMessage() throws IOException { String expectedSubscription = SUBSCRIPTION.getPath(); PullRequest expectedRequest = new PullRequest().setReturnImmediately(true).setMaxMessages(10); PubsubMessage expectedPubsubMessage =
@Test public void pullOneMessageWithNoData() throws IOException { String expectedSubscription = SUBSCRIPTION.getPath(); PullRequest expectedRequest = new PullRequest().setReturnImmediately(true).setMaxMessages(10); PubsubMessage expectedPubsubMessage = new PubsubMessage() .setMessageId(MESSAGE_ID) .setPublishTime(String.valueOf(PUB_TIME)) .setAttributes( ImmutableMap.of( TIMESTAMP_ATTRIBUTE, String.valueOf(MESSAGE_TIME), ID_ATTRIBUTE, RECORD_ID)); ReceivedMessage expectedReceivedMessage = new ReceivedMessage().setMessage(expectedPubsubMessage).setAckId(ACK_ID); PullResponse expectedResponse = new PullResponse().setReceivedMessages(ImmutableList.of(expectedReceivedMessage)); Mockito.when( (Object) (mockPubsub .projects() .subscriptions() .pull(expectedSubscription, expectedRequest) .execute())) .thenReturn(expectedResponse); List<IncomingMessage> acutalMessages = client.pull(REQ_TIME, SUBSCRIPTION, 10, true); assertEquals(1, acutalMessages.size()); IncomingMessage actualMessage = acutalMessages.get(0); assertArrayEquals(new byte[0], actualMessage.elementBytes); }
@Override public void acknowledge(SubscriptionPath subscription, List<String> ackIds) throws IOException { synchronized (STATE) { checkState(inPullMode(), "Can only acknowledge in pull mode"); checkState( subscription.equals(STATE.expectedSubscription), "Subscription %s does not match expected %s", subscription, STATE.expectedSubscription); for (String ackId : ackIds) { checkState( STATE.ackDeadline.remove(ackId) != null, "No message with ACK id %s is waiting for an ACK", ackId); checkState( STATE.pendingAckIncomingMessages.remove(ackId) != null, "No message with ACK id %s is waiting for an ACK", ackId); } } }
@Override public PubsubCheckpoint getCheckpointMark() { int cur = numInFlightCheckpoints.incrementAndGet(); maxInFlightCheckpoints = Math.max(maxInFlightCheckpoints, cur); // It's possible for a checkpoint to be taken but never finalized. // So we simply copy whatever safeToAckIds we currently have. // It's possible a later checkpoint will be taken before an earlier one is finalized, // in which case we'll double ACK messages to Pubsub. However Pubsub is fine with that. List<String> snapshotSafeToAckIds = Lists.newArrayList(safeToAckIds); List<String> snapshotNotYetReadIds = new ArrayList<>(notYetRead.size()); for (PubsubClient.IncomingMessage incomingMessage : notYetRead) { snapshotNotYetReadIds.add(incomingMessage.ackId); } if (outer.subscriptionPath == null) { // need to include the subscription in case we resume, as it's not stored in the source. return new PubsubCheckpoint( subscription.getPath(), this, snapshotSafeToAckIds, snapshotNotYetReadIds); } return new PubsubCheckpoint(null, this, snapshotSafeToAckIds, snapshotNotYetReadIds); }
public static SubscriptionPath subscriptionPathFromPath(String path) { return new SubscriptionPath(path); }
@Override public void modifyAckDeadline( SubscriptionPath subscription, List<String> ackIds, int deadlineSeconds) throws IOException { ModifyAckDeadlineRequest request = ModifyAckDeadlineRequest.newBuilder() .setSubscription(subscription.getPath()) .addAllAckIds(ackIds) .setAckDeadlineSeconds(deadlineSeconds) .build(); subscriberStub().modifyAckDeadline(request); // ignore Empty result. }
@Override public void deleteSubscription(SubscriptionPath subscription) throws IOException { DeleteSubscriptionRequest request = DeleteSubscriptionRequest.newBuilder().setSubscription(subscription.getPath()).build(); subscriberStub().deleteSubscription(request); // ignore Empty result. }
@Override public void createSubscription( TopicPath topic, SubscriptionPath subscription, int ackDeadlineSeconds) throws IOException { Subscription request = Subscription.newBuilder() .setTopic(topic.getPath()) .setName(subscription.getPath()) .setAckDeadlineSeconds(ackDeadlineSeconds) .build(); subscriberStub().createSubscription(request); // ignore Subscription result. }
@Override public void deleteSubscription(SubscriptionPath subscription) throws IOException { pubsub .projects() .subscriptions() .delete(subscription.getPath()) .execute(); // ignore Empty result. }
@Override public void createSubscription( TopicPath topic, SubscriptionPath subscription, int ackDeadlineSeconds) throws IOException { Subscription request = new Subscription().setTopic(topic.getPath()).setAckDeadlineSeconds(ackDeadlineSeconds); pubsub .projects() .subscriptions() .create(subscription.getPath(), request) .execute(); // ignore Subscription result. }
@Override public void modifyAckDeadline( SubscriptionPath subscription, List<String> ackIds, int deadlineSeconds) throws IOException { ModifyAckDeadlineRequest request = new ModifyAckDeadlineRequest().setAckIds(ackIds).setAckDeadlineSeconds(deadlineSeconds); pubsub .projects() .subscriptions() .modifyAckDeadline(subscription.getPath(), request) .execute(); // ignore Empty result. }
@Override public void acknowledge(SubscriptionPath subscription, List<String> ackIds) throws IOException { AcknowledgeRequest request = new AcknowledgeRequest().setAckIds(ackIds); pubsub .projects() .subscriptions() .acknowledge(subscription.getPath(), request) .execute(); // ignore Empty result. }