use of com.google.pubsub.v1.PullRequest in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method pullTest.
@Test
@SuppressWarnings("all")
public void pullTest() {
PullResponse expectedResponse = PullResponse.newBuilder().build();
mockSubscriber.addResponse(expectedResponse);
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
boolean returnImmediately = false;
int maxMessages = 496131527;
PullResponse actualResponse = client.pull(subscription, returnImmediately, maxMessages);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
PullRequest actualRequest = (PullRequest) actualRequests.get(0);
Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
Assert.assertEquals(returnImmediately, actualRequest.getReturnImmediately());
Assert.assertEquals(maxMessages, actualRequest.getMaxMessages());
}
use of com.google.pubsub.v1.PullRequest in project spring-cloud-gcp by spring-cloud.
the class PubSubTemplate method pull.
/**
* Pulls messages synchronously, on demand, using the pull request in argument.
*
* <p>This method acknowledges all received messages.
* @param pullRequest pull request containing the subscription name
* @return the list of {@link PubsubMessage} containing the headers and payload
*/
private List<PubsubMessage> pull(PullRequest pullRequest, RetrySettings retrySettings) {
Assert.notNull(pullRequest, "The pull request cannot be null.");
try {
SubscriberStub subscriber = this.subscriberFactory.createSubscriberStub(retrySettings);
Assert.notNull(subscriber, "A SubscriberStub is needed to execute the pull request.");
PullResponse pullResponse = subscriber.pullCallable().call(pullRequest);
// Ack received messages.
if (pullResponse.getReceivedMessagesCount() > 0) {
List<String> ackIds = pullResponse.getReceivedMessagesList().stream().map(ReceivedMessage::getAckId).collect(Collectors.toList());
AcknowledgeRequest acknowledgeRequest = AcknowledgeRequest.newBuilder().setSubscription(pullRequest.getSubscription()).addAllAckIds(ackIds).build();
subscriber.acknowledgeCallable().call(acknowledgeRequest);
}
return pullResponse.getReceivedMessagesList().stream().map(ReceivedMessage::getMessage).collect(Collectors.toList());
} catch (Exception ioe) {
throw new PubSubException("Error pulling messages from subscription " + pullRequest.getSubscription() + ".", ioe);
}
}
use of com.google.pubsub.v1.PullRequest in project connectors-workspace-one by vmware.
the class GithubPrController method makeCard.
private Card makeCard(String routingPrefix, Pair<PullRequestId, PullRequest> info, Locale locale, HttpServletRequest request) {
logger.trace("makeCard called: routingPrefix={}, info={}", routingPrefix, info);
PullRequestId pullRequestId = info.getLeft();
PullRequest pullRequest = info.getRight();
boolean isOpen = OPEN_STATE.equalsIgnoreCase(pullRequest.getState());
Card.Builder card = new Card.Builder().setName(// TODO - remove this in APF-536
"GithubPr").setTemplate(routingPrefix + "templates/generic.hbs").setHeader(cardTextAccessor.getHeader(locale), cardTextAccessor.getMessage("subtitle", locale, pullRequestId.getOwner(), pullRequestId.getRepo(), pullRequestId.getNumber())).setBody(createBody(pullRequestId, pullRequest, locale));
// Set image url.
CommonUtils.buildConnectorImageUrl(card, request);
addCloseAction(card, routingPrefix, pullRequestId, isOpen, locale);
addMergeAction(card, routingPrefix, pullRequestId, pullRequest, isOpen, locale);
addApproveAction(card, routingPrefix, pullRequestId, isOpen, locale);
addCommentAction(card, routingPrefix, pullRequestId, locale);
addRequestChangesAction(card, routingPrefix, pullRequestId, isOpen, locale);
return card.build();
}
use of com.google.pubsub.v1.PullRequest in project flink by apache.
the class DefaultPubSubSubscriberFactory method getSubscriber.
@Override
public PubSubSubscriber getSubscriber(Credentials credentials) throws IOException {
ManagedChannel channel = NettyChannelBuilder.forTarget(SubscriberStubSettings.getDefaultEndpoint()).negotiationType(NegotiationType.TLS).sslContext(GrpcSslContexts.forClient().ciphers(null).build()).build();
PullRequest pullRequest = PullRequest.newBuilder().setMaxMessages(maxMessagesPerPull).setSubscription(projectSubscriptionName).build();
SubscriberGrpc.SubscriberBlockingStub stub = SubscriberGrpc.newBlockingStub(channel).withCallCredentials(MoreCallCredentials.from(credentials));
return new BlockingGrpcPubSubSubscriber(projectSubscriptionName, channel, stub, pullRequest, retries, timeout);
}
use of com.google.pubsub.v1.PullRequest in project flink by apache.
the class PubSubSubscriberFactoryForEmulator method getSubscriber.
@Override
public PubSubSubscriber getSubscriber(Credentials credentials) throws IOException {
ManagedChannel managedChannel = NettyChannelBuilder.forTarget(hostAndPort).usePlaintext().build();
PullRequest pullRequest = PullRequest.newBuilder().setMaxMessages(maxMessagesPerPull).setSubscription(projectSubscriptionName).build();
SubscriberGrpc.SubscriberBlockingStub stub = SubscriberGrpc.newBlockingStub(managedChannel);
return new BlockingGrpcPubSubSubscriber(projectSubscriptionName, managedChannel, stub, pullRequest, retries, timeout);
}
Aggregations