Delete a Google Cloud Managed Service for Apache Kafka consumer group
Stay organized with collections
Save and categorize content based on your preferences.
Deleting a consumer group removes a consumer group from your
Managed Service for Apache Kafka cluster.
To delete a consumer group, you can use the Google Cloud console,
the Google Cloud CLI, the client libraries, the Managed Kafka API, or
the open source Apache Kafka APIs.
Required roles and permissions to delete a consumer group
This predefined role contains
the permissions required to delete your consumer groups. To see the exact permissions that are
required, expand the Required permissions section:
Required permissions
The following permissions are required to delete your consumer groups:
When you delete a consumer group, the consumer offsets it stores are
permanently lost. You are also unable to see the logs and metrics for the
consumer groups in the console. However, the metrics and logs associated with
the consumer group are retained and accessible using
Logs Explorer.
Deleting a consumer group also does not delete
the messages it has consumed. The messages are still available in the topics
with which they were originally associated.
To delete a consumer group, follow these steps:
Console
In the Google Cloud console, go to the Cluster page.
At the bottom of the Google Cloud console, a
Cloud Shell
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.
importcom.google.api.gax.rpc.ApiException;importcom.google.cloud.managedkafka.v1.ConsumerGroupName;importcom.google.cloud.managedkafka.v1.ManagedKafkaClient;importjava.io.IOException;publicclassDeleteConsumerGroup{publicstaticvoidmain(String[]args)throwsException{// TODO(developer): Replace these variables before running the example.StringprojectId="my-project-id";Stringregion="my-region";// e.g. us-east1StringclusterId="my-cluster";StringconsumerGroupId="my-consumer-group";deleteConsumerGroup(projectId,region,clusterId,consumerGroupId);}publicstaticvoiddeleteConsumerGroup(StringprojectId,Stringregion,StringclusterId,StringconsumerGroupId)throwsException{try(ManagedKafkaClientmanagedKafkaClient=ManagedKafkaClient.create()){// This operation is being handled synchronously.managedKafkaClient.deleteConsumerGroup(ConsumerGroupName.of(projectId,region,clusterId,consumerGroupId));System.out.println("Deleted consumer group");}catch(IOException|ApiExceptione){System.err.printf("managedKafkaClient.getConsumerGroup got err: %s",e.getMessage());}}}
Python
fromgoogle.api_core.exceptionsimportNotFoundfromgoogle.cloudimportmanagedkafka_v1# TODO(developer)# project_id = "my-project-id"# region = "us-central1"# cluster_id = "my-cluster"# consumer_group_id = "my-consumer-group"client=managedkafka_v1.ManagedKafkaClient()consumer_group_path=client.consumer_group_path(project_id,region,cluster_id,consumer_group_id)request=managedkafka_v1.DeleteConsumerGroupRequest(name=consumer_group_path,)try:client.delete_consumer_group(request=request)print("Deleted consumer group")exceptNotFoundase:print(f"Failed to delete consumer group {consumer_group_id} with error: {e.message}")
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-26 UTC."],[],[],null,["# Delete a Google Cloud Managed Service for Apache Kafka consumer group\n\nDeleting a consumer group removes a consumer group from your\nManaged Service for Apache Kafka cluster.\n\nTo delete a consumer group, you can use the Google Cloud console,\nthe Google Cloud CLI, the client libraries, the Managed Kafka API, or\nthe open source Apache Kafka APIs.\n\nRequired roles and permissions to delete a consumer group\n---------------------------------------------------------\n\n\nTo get the permissions that\nyou need to delete your consumer groups,\n\nask your administrator to grant you the\n\n\n[Managed Kafka Consumer Group Editor](/iam/docs/roles-permissions/managedkafka#managedkafka.consumerGroupEditor) (`roles/managedkafka.consumerGroupEditor`)\nIAM role on your project.\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nThis predefined role contains\n\nthe permissions required to delete your consumer groups. To see the exact permissions that are\nrequired, expand the **Required permissions** section:\n\n\n#### Required permissions\n\nThe following permissions are required to delete your consumer groups:\n\n- Delete consumer groups: ` ``managedkafka.consumerGroups.delete`\n\n\nYou might also be able to get\nthese permissions\nwith [custom roles](/iam/docs/creating-custom-roles) or\nother [predefined roles](/iam/docs/roles-overview#predefined).\n\nFor more information about the Managed Kafka Consumer Group Editor role, see\n[Managed Service for Apache Kafka predefined roles](/managed-service-for-apache-kafka/docs/access-control#predefined-roles).\n\nDelete a consumer group\n-----------------------\n\nWhen you delete a consumer group, the consumer offsets it stores are\npermanently lost. You are also unable to see the logs and metrics for the\nconsumer groups in the console. However, the metrics and logs associated with\nthe consumer group are retained and accessible using\n[Logs Explorer](/logging/docs/view/logs-explorer-interface).\nDeleting a consumer group also does not delete\nthe messages it has consumed. The messages are still available in the topics\nwith which they were originally associated.\n\nTo delete a consumer group, follow these steps: \n\n### Console\n\n1. In the Google Cloud console, go to the **Cluster** page.\n\n [Go to Clusters](https://console.cloud.google.com/managedkafka/clusters)\n2. From the list of clusters, click the cluster to which the consumer group that you want to delete belongs. The **Cluster details** page opens.\n\n3. Click the consumer group that you want to delete.\n4. In the **Consumer group details** page, click **Delete**.\n5. Confirm the operation.\n\n### gcloud\n\n1. In the Google Cloud console, activate Cloud Shell.\n\n [Activate Cloud Shell](https://console.cloud.google.com/?cloudshell=true)\n\n\n At the bottom of the Google Cloud console, a\n [Cloud Shell](/shell/docs/how-cloud-shell-works)\n session starts and displays a command-line prompt. Cloud Shell is a shell environment\n with the Google Cloud CLI\n already installed and with values already set for\n your current project. It can take a few seconds for the session to initialize.\n2. Run the [`gcloud managed-kafka consumer-groups delete`](/sdk/gcloud/reference/managed-kafka/consumer-groups/delete) command:\n\n \u003cbr /\u003e\n\n ```bash\n gcloud managed-kafka consumer-groups delete CONSUMER_GROUP_ID \\\n --cluster=CLUSTER_ID \\\n --location=LOCATION\n ```\n\n This command permanently removes a consumer group from your\n Managed Service for Apache Kafka cluster.\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eCONSUMER_GROUP_ID\u003c/var\u003e: The ID or name of the consumer group.\n\n - \u003cvar translate=\"no\"\u003eCLUSTER_ID\u003c/var\u003e: The ID or name of the cluster.\n\n - \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: The location of the cluster.\n\n \u003cbr /\u003e\n\n### Go\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \t\"cloud.google.com/go/managedkafka/apiv1/managedkafkapb\"\n \t\"google.golang.org/api/option\"\n\n \tmanagedkafka \"cloud.google.com/go/managedkafka/apiv1\"\n )\n\n func deleteConsumerGroup(w io.Writer, projectID, region, clusterID, consumerGroupID string, opts ...option.ClientOption) error {\n \t// projectID := \"my-project-id\"\n \t// region := \"us-central1\"\n \t// clusterID := \"my-cluster\"\n \t// consumerGroupID := \"my-consumer-group\"\n \tctx := context.Background()\n \tclient, err := managedkafka.https://cloud.google.com/go/docs/reference/cloud.google.com/go/managedkafka/latest/apiv1.html#cloud_google_com_go_managedkafka_apiv1_Client_NewClient(ctx, opts...)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"managedkafka.NewClient got err: %w\", err)\n \t}\n \tdefer client.Close()\n\n \tclusterPath := fmt.Sprintf(\"projects/%s/locations/%s/clusters/%s\", projectID, region, clusterID)\n \tconsumerGroupPath := fmt.Sprintf(\"%s/consumerGroups/%s\", clusterPath, consumerGroupID)\n \treq := &managedkafkapb.DeleteConsumerGroupRequest{\n \t\tName: consumerGroupPath,\n \t}\n \tif err := client.DeleteConsumerGroup(ctx, req); err != nil {\n \t\treturn fmt.Errorf(\"client.DeleteConsumerGroup got err: %w\", err)\n \t}\n \tfmt.Fprint(w, \"Deleted consumer group\\n\")\n \treturn nil\n }\n\n### Java\n\n import com.google.api.gax.rpc.https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.ApiException.html;\n import com.google.cloud.managedkafka.v1.https://cloud.google.com/java/docs/reference/google-cloud-managedkafka/latest/com.google.cloud.managedkafka.v1.ConsumerGroupName.html;\n import com.google.cloud.managedkafka.v1.https://cloud.google.com/java/docs/reference/google-cloud-managedkafka/latest/com.google.cloud.managedkafka.v1.ManagedKafkaClient.html;\n import java.io.IOException;\n\n public class DeleteConsumerGroup {\n\n public static void main(String[] args) throws Exception {\n // TODO(developer): Replace these variables before running the example.\n String projectId = \"my-project-id\";\n String region = \"my-region\"; // e.g. us-east1\n String clusterId = \"my-cluster\";\n String consumerGroupId = \"my-consumer-group\";\n deleteConsumerGroup(projectId, region, clusterId, consumerGroupId);\n }\n\n public static void deleteConsumerGroup(\n String projectId, String region, String clusterId, String consumerGroupId) throws Exception {\n try (https://cloud.google.com/java/docs/reference/google-cloud-managedkafka/latest/com.google.cloud.managedkafka.v1.ManagedKafkaClient.html managedKafkaClient = https://cloud.google.com/java/docs/reference/google-cloud-managedkafka/latest/com.google.cloud.managedkafka.v1.ManagedKafkaClient.html.create()) {\n // This operation is being handled synchronously.\n managedKafkaClient.deleteConsumerGroup(\n https://cloud.google.com/java/docs/reference/google-cloud-managedkafka/latest/com.google.cloud.managedkafka.v1.ConsumerGroupName.html.of(projectId, region, clusterId, consumerGroupId));\n System.out.println(\"Deleted consumer group\");\n } catch (IOException | https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.ApiException.html e) {\n System.err.printf(\"managedKafkaClient.getConsumerGroup got err: %s\", e.https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.ErrorDetails.html#com_google_api_gax_rpc_ErrorDetails__T_getMessage_java_lang_Class_T__());\n }\n }\n }\n\n### Python\n\n from google.api_core.exceptions import NotFound\n from google.cloud import https://cloud.google.com/python/docs/reference/google-cloud-managedkafka/latest/\n\n # TODO(developer)\n # project_id = \"my-project-id\"\n # region = \"us-central1\"\n # cluster_id = \"my-cluster\"\n # consumer_group_id = \"my-consumer-group\"\n\n client = https://cloud.google.com/python/docs/reference/google-cloud-managedkafka/latest/.https://cloud.google.com/python/docs/reference/google-cloud-managedkafka/latest/google.cloud.managedkafka_v1.services.managed_kafka.ManagedKafkaClient.html()\n\n consumer_group_path = client.https://cloud.google.com/python/docs/reference/google-cloud-managedkafka/latest/google.cloud.managedkafka_v1.services.managed_kafka.ManagedKafkaClient.html#google_cloud_managedkafka_v1_services_managed_kafka_ManagedKafkaClient_consumer_group_path(\n project_id, region, cluster_id, consumer_group_id\n )\n request = https://cloud.google.com/python/docs/reference/google-cloud-managedkafka/latest/.https://cloud.google.com/python/docs/reference/google-cloud-managedkafka/latest/google.cloud.managedkafka_v1.types.DeleteConsumerGroupRequest.html(\n name=consumer_group_path,\n )\n\n try:\n client.https://cloud.google.com/python/docs/reference/google-cloud-managedkafka/latest/google.cloud.managedkafka_v1.services.managed_kafka.ManagedKafkaClient.html#google_cloud_managedkafka_v1_services_managed_kafka_ManagedKafkaClient_delete_consumer_group(request=request)\n print(\"Deleted consumer group\")\n except NotFound as e:\n print(f\"Failed to delete consumer group {consumer_group_id} with error: {e.message}\")\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nWhat's next?\n------------\n\n- [View a consumer group](/managed-service-for-apache-kafka/docs/view-consumer-group).\n- [List all consumer groups of a cluster](/managed-service-for-apache-kafka/docs/list-consumer-groups).\n- [Edit a consumer group](/managed-service-for-apache-kafka/docs/edit-consumer-group).\n\n*Apache Kafka® is a registered\ntrademark of The Apache Software Foundation or its affiliates in the United\nStates and/or other countries.*"]]