List shared resource subscriptions (v1)

List all shared resource subscriptions for a data exchange.

Code sample

Java

Before trying this sample, follow the Java setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Java API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

import com.google.cloud.bigquery.analyticshub.v1.AnalyticsHubServiceClient;
import com.google.cloud.bigquery.analyticshub.v1.DataExchangeName;
import com.google.cloud.bigquery.analyticshub.v1.ListSharedResourceSubscriptionsRequest;
import com.google.cloud.bigquery.analyticshub.v1.Subscription;
import java.io.IOException;

public class ListSharedResourceSubscriptions {

  public static void main(String[] args) throws IOException {
    String projectId = "example-project-id";
    String locationId = "example-location-id";
    String dataExchangeId = "example-data-exchange-id";
    listSharedResourceSubscriptions(projectId, locationId, dataExchangeId);
  }

  public static void listSharedResourceSubscriptions(
      String projectId, String locationId, String dataExchangeId) throws IOException {
    // Initialize the client. Create once and reuse across requests.
    try (AnalyticsHubServiceClient client = AnalyticsHubServiceClient.create()) {
      String resource = DataExchangeName.of(projectId, locationId, dataExchangeId).toString();

      ListSharedResourceSubscriptionsRequest request =
          ListSharedResourceSubscriptionsRequest.newBuilder()
              .setResource(resource)
              .build();

      for (Subscription subscription : client.listSharedResourceSubscriptions(request).iterateAll()) {
        System.out.println("Shared resource subscription: " + subscription.getName());
      }
    }
  }
}

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.