Managed Service for Apache Kafka lets you view the operational status,
resource allocation, and configuration details for all of your Connect clusters.
This consolidated view helps you to manage your Connect clusters in one place.

To list your Connect clusters, you can use the Google Cloud console,
the gcloud CLI, the client library, or the
Managed Kafka API. You can't use the open source Apache Kafka API to
list Connect clusters.

## Required roles and permissions to list your Connect clusters


To get the permissions that
you need to list your Connect clusters,

ask your administrator to grant you the
[Managed Kafka Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/managedkafka.md.txt#managedkafka.viewer) (`roles/managedkafka.viewer`) IAM role on your project.


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


This predefined role contains

the permissions required to list your Connect clusters. To see the exact permissions that are
required, expand the **Required permissions** section:


#### Required permissions

The following permissions are required to list your Connect clusters:

- Grant the list clusters permission on the specified location: `managedkafka.connectClusters.list`
- Grant the get cluster details permission on the specified location: `managedkafka.connectClusters.get`


You might also be able to get
these permissions
with [custom roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles.md.txt) or
other [predefined roles](https://docs.cloud.google.com/iam/docs/roles-overview.md.txt#predefined).

## View your Connect clusters

### Console

1. In the Google Cloud console, go to the **Connect Clusters** page.


   [Go to Connect Clusters](https://console.cloud.google.com/managedkafka/connectClusters)

   <br />

2. The clusters you created in a project are listed. The page lets you view
   the following cluster properties:

   - **Name**: The unique identifier for your Connect cluster. You can use it to reference the Connect cluster in various operations.
   - **State** : Indicates the current operational status of the Connect cluster, such as **Active**.
   - **Location**: The geographical location where your Connect cluster is hosted.
   - **Update time**: The time the Connect cluster was last updated.
   - **vCPUs**: The number of vCPUs assigned to the Connect cluster.
   - **Memory**: The total amount of memory allocated to the Connect cluster.
   - **Primary Kafka cluster**: The Managed Service for Apache Kafka cluster associated with the Connect cluster.
   - **Labels**: Key-value pairs that you can attach to the Connect cluster for organization, filtering, and automation purposes.

### gcloud


1. In the Google Cloud console, activate Cloud Shell.

   [Activate Cloud Shell](https://console.cloud.google.com/?cloudshell=true)


   At the bottom of the Google Cloud console, a
   [Cloud Shell](https://docs.cloud.google.com/shell/docs/how-cloud-shell-works.md.txt)
   session starts and displays a command-line prompt. Cloud Shell is a shell environment
   with the Google Cloud CLI
   already installed and with values already set for
   your current project. It can take a few seconds for the session to initialize.
2. Use the [`gcloud managed-kafka connect-clusters list`](https://docs.cloud.google.com/sdk/gcloud/reference/managed-kafka/connect-clusters/list)
   command to list Connect clusters:

   ```bash
   gcloud managed-kafka connect-clusters list \
       --location=LOCATION
   ```
3. To further refine the list of Connect clusters, you can use additional
   flags:

   ```bash
   gcloud managed-kafka connect-clusters list \
       --location=LOCATION \
       [--filter=EXPRESSION] \
       [--limit=LIMIT] \
       [--page-size=PAGE_SIZE] \
       [--sort-by=SORT_BY]
   ```

   Replace the following:
   - <var translate="no">LOCATION</var>: Required. The location of the Connect
     clusters you want to list.

   - <var translate="no">EXPRESSION</var>: (Optional) A boolean filter
     expression to apply to the list. If the expression evaluates to `True`,
     the item is included in the list. For more details and examples, run
     `gcloud topic filters`.

   - <var translate="no">LIMIT</var>: (Optional) The maximum number of Connect
     clusters to display. If not specified, all Connect clusters are listed.

   - <var translate="no">PAGE_SIZE</var>: (Optional) The number of results to
     display per page. If not specified, the service determines a suitable
     page size.

   - <var translate="no">SORT_BY</var>: (Optional) A comma-separated list of
     fields to sort by. The default sort order is ascending. To sort in
     descending order, prefix the field with `~`.

Example output:

    NAME                   VCPU  MEMORY_BYTES  STATE   NETWORK
    connect-cluster-alpha  3     3221225472    ACTIVE
    connect-cluster-beta   3     3221225472    ACTIVE

<br />

### Go


Before trying this sample, follow the Go setup instructions in
[Install the client libraries](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/reference/libraries.md.txt#install). For more information,
see the [Managed Service for Apache Kafka Go API reference documentation](https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/managedkafka/latest/apiv1.md.txt).

To authenticate to Managed Service for Apache Kafka, set up Application Default Credentials(ADC).
For more information,
see [Set up ADC for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment.md.txt).

```go
import (
	"context"
	"fmt"
	"io"

	"cloud.google.com/go/managedkafka/apiv1/managedkafkapb"
	"google.golang.org/api/iterator"
	"google.golang.org/api/option"

	managedkafka "cloud.google.com/go/managedkafka/apiv1"
)

func listConnectClusters(w io.Writer, projectID, region string, opts ...option.ClientOption) error {
	// projectID := "my-project-id"
	// region := "us-central1"
	ctx := context.Background()
	client, err := managedkafka.NewManagedKafkaConnectClient(ctx, opts...)
	if err != nil {
		return fmt.Errorf("managedkafka.NewManagedKafkaConnectClient got err: %w", err)
	}
	defer client.Close()

	locationPath := fmt.Sprintf("projects/%s/locations/%s", projectID, region)
	req := &managedkafkapb.ListConnectClustersRequest{
		Parent: locationPath,
	}
	clusterIter := client.ListConnectClusters(ctx, req)
	for {
		res, err := clusterIter.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("clusterIter.Next() got err: %w", err)
		}
		fmt.Fprintf(w, "Got connect cluster: %v", res)
	}
	return nil
}
```

<br />

### Java


Before trying this sample, follow the Java setup instructions in
[Install the client libraries](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/reference/libraries.md.txt#install). For more information,
see the [Managed Service for Apache Kafka Java API reference documentation](https://docs.cloud.google.com/java/docs/reference/google-cloud-managedkafka/latest/overview.md.txt).

To authenticate to Managed Service for Apache Kafka, set up Application Default Credentials.
For more information, see [Set up ADC for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment.md.txt).

```java
import com.google.api.gax.rpc.ApiException;
import com.google.cloud.managedkafka.v1.ConnectCluster;
import com.google.cloud.managedkafka.v1.LocationName;
import com.google.cloud.managedkafka.v1.ManagedKafkaConnectClient;
import java.io.IOException;

public class ListConnectClusters {

  public static void main(String[] args) throws Exception {
    // TODO(developer): Replace these variables before running the example.
    String projectId = "my-project-id";
    String region = "my-region"; // e.g. us-east1
    listConnectClusters(projectId, region);
  }

  public static void listConnectClusters(String projectId, String region) throws Exception {
    try (ManagedKafkaConnectClient managedKafkaConnectClient = 
        ManagedKafkaConnectClient.create()) {
      LocationName locationName = LocationName.of(projectId, region);
      // This operation is being handled synchronously.
      for (ConnectCluster connectCluster : managedKafkaConnectClient
          .listConnectClusters(locationName).iterateAll()) {
        System.out.println(connectCluster.getAllFields());
      }
    } catch (IOException | ApiException e) {
      System.err.printf("managedKafkaConnectClient.listConnectClusters got err: %s\n", 
          e.getMessage());
    }
  }
}
```

<br />

### Python


Before trying this sample, follow the Python setup instructions in
[Install the client libraries](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/reference/libraries.md.txt#install). For more information,
see the [Managed Service for Apache Kafka Python API reference documentation](https://docs.cloud.google.com/python/docs/reference/google-cloud-managedkafka/latest.md.txt).

To authenticate to Managed Service for Apache Kafka, set up Application Default Credentials.
For more information,
see [Set up ADC for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment.md.txt).

```python
from google.cloud import managedkafka_v1
from google.cloud.managedkafka_v1.services.managed_kafka_connect import (
    ManagedKafkaConnectClient,
)
from google.api_core.exceptions import GoogleAPICallError

# TODO(developer)
# project_id = "my-project-id"
# region = "us-central1"

connect_client = ManagedKafkaConnectClient()

request = managedkafka_v1.ListConnectClustersRequest(
    parent=connect_client.common_location_path(project_id, region),
)

response = connect_client.list_connect_clusters(request=request)
for cluster in response:
    try:
        print("Got Connect cluster:", cluster)
    except GoogleAPICallError as e:
        print(f"Failed to list Connect clusters with error: {e}")
```

<br />

## What's next?

- [View a Connect clusters](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/connect-cluster/view-connect-cluster.md.txt)

- [Update a Connect cluster](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/connect-cluster/update-connect-cluster.md.txt)

- [Delete a Connect cluster](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/connect-cluster/delete-connect-cluster.md.txt)

- [An overview of connectors](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/connect-cluster/connectors-overview.md.txt)

*Apache Kafka® is a registered
trademark of The Apache Software Foundation or its affiliates in the United
States and/or other countries.*