use of com.google.pubsub.v1.SubscriptionName in project google-cloud-java by GoogleCloudPlatform.
the class PubsubBenchWrapperImpl method recv.
public void recv(PubsubRecv request, StreamObserver<EmptyResponse> responseObserver) {
System.out.println("recv has been called");
ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of("some-project", request.getSubName());
Subscriber subscriber = null;
try {
InstantiatingExecutorProvider executorProvider = InstantiatingExecutorProvider.newBuilder().setExecutorThreadCount(1).build();
subscriber = Subscriber.newBuilder(subscriptionName, new SimpleReceiver()).setExecutorProvider(executorProvider).build();
subscriber.startAsync().awaitRunning();
// Allow the subscriber to run indefinitely unless an unrecoverable error occurs.
subscriber.awaitTerminated();
} catch (IllegalStateException e) {
System.out.println("Subscriber unexpectedly stopped: " + e);
}
EmptyResponse reply = EmptyResponse.newBuilder().build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
}
use of com.google.pubsub.v1.SubscriptionName in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientSnippets method createSubscriptionWithPushEndpoint.
/** Example of creating a subscription with a push endpoint. */
public Subscription createSubscriptionWithPushEndpoint(String topicId, String subscriptionId, String endpoint) throws Exception {
// [START pubsub_create_push_subscription]
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
TopicName topicName = TopicName.create(projectId, topicId);
SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId);
// eg. endpoint = "https://my-test-project.appspot.com/push"
PushConfig pushConfig = PushConfig.newBuilder().setPushEndpoint(endpoint).build();
// acknowledgement deadline in seconds for the message received over the push endpoint
int ackDeadlineInSeconds = 10;
Subscription subscription = subscriptionAdminClient.createSubscription(subscriptionName, topicName, pushConfig, ackDeadlineInSeconds);
return subscription;
}
// [END pubsub_create_push_subscription]
}
use of com.google.pubsub.v1.SubscriptionName in project google-cloud-java by GoogleCloudPlatform.
the class SubscriberSnippets method createSubscriber.
private void createSubscriber() throws Exception {
// [START pubsub_pull]
String projectId = "my-project-id";
String subscriptionId = "my-subscription-id";
SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId);
// Instantiate an asynchronous message receiver
MessageReceiver receiver = new MessageReceiver() {
@Override
public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) {
// handle incoming message, then ack/nack the received message
System.out.println("Id : " + message.getMessageId());
System.out.println("Data : " + message.getData().toStringUtf8());
consumer.ack();
}
};
Subscriber subscriber = null;
try {
// Create a subscriber for "my-subscription-id" bound to the message receiver
subscriber = Subscriber.defaultBuilder(subscriptionName, receiver).build();
subscriber.startAsync();
// ...
} finally {
// stop receiving messages
if (subscriber != null) {
subscriber.stopAsync();
}
}
// [END pubsub_pull]
}
use of com.google.pubsub.v1.SubscriptionName in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientSnippets method getSubscription.
/** Example of getting a subscription. */
public Subscription getSubscription(String subscriptionId) throws Exception {
// [START pubsub_get_subscription]
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId);
Subscription subscription = subscriptionAdminClient.getSubscription(subscriptionName);
return subscription;
}
// [END pubsub_get_subscription]
}
use of com.google.pubsub.v1.SubscriptionName in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientSnippets method deleteSubscription.
/** Example of deleting a subscription. */
public SubscriptionName deleteSubscription(String subscriptionId) throws Exception {
// [START pubsub_delete_subscription]
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId);
subscriptionAdminClient.deleteSubscription(subscriptionName);
return subscriptionName;
}
// [END pubsub_delete_subscription]
}
Aggregations