Listing Topics of a Kafka Instance
Function
This API is used to query details about topics of a Kafka instance.
Calling Method
For details, see Calling APIs.
URI
GET /v2/{project_id}/instances/{instance_id}/topics
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Parameter description: Project ID. For details, see Obtaining a Project ID. Constraints: N/A Value range: N/A Default value: N/A |
instance_id |
Yes |
String |
Parameter description: Instance ID. To obtain it, log in to the Kafka console and find the instance ID on the Kafka instance details page. Constraints: N/A Value range: N/A Default value: N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
offset |
No |
String |
Parameter description: Offset, which is the position where the query starts. Constraints: N/A Value range: ≥ 0 Default value: N/A |
limit |
No |
String |
Parameter description: Maximum number of instances that can be returned in a query. Constraints: N/A Value range: 1–50 Default value: 10 |
Request Parameters
None
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
total |
Integer |
Parameter description: Total number of topics. Value range: N/A |
size |
Integer |
Parameter description: Indicates the maximum number of records to be displayed on a page. Value range: N/A |
remain_partitions |
Integer |
Parameter description: Number of remaining partitions. Value range: N/A |
max_partitions |
Integer |
Parameter description: Total number of partitions. Value range: N/A |
topic_max_partitions |
Integer |
Parameter description: Maximum number of partitions in a single topic. Value range: N/A |
topics |
Array of TopicEntity objects |
Parameter description: Topic list. |
Parameter |
Type |
Description |
---|---|---|
policiesOnly |
Boolean |
Parameter description: Whether this policy is the default policy. Value range:
|
name |
String |
Parameter description: Topic name. Value range: N/A |
replication |
Integer |
Parameter description: Number of replicas, which is configured to ensure data reliability. Value range: N/A |
partition |
Integer |
Parameter description: Number of topic partitions, which is used to set the number of concurrently consumed messages. Value range: N/A |
retention_time |
Integer |
Parameter description: Retention period of a message. Value range: 0–720 |
sync_replication |
Boolean |
Parameter description: Whether to enable synchronous replication. This function is disabled by default. Value range:
|
sync_message_flush |
Boolean |
Parameter description: Whether synchronous flushing is enabled. The default value is false. Synchronous flushing compromises performance. Value range:
|
external_configs |
Object |
Parameter description: Extended configuration. |
topic_type |
Integer |
Parameter description: Topic type. Value range:
|
topic_other_configs |
Array of topic_other_configs objects |
Parameter description: Other topic configurations. |
topic_desc |
String |
Parameter description: Topic description. Value range: N/A |
created_at |
Long |
Parameter description: Topic creation time. Value range: N/A |
Parameter |
Type |
Description |
---|---|---|
name |
String |
Parameter description: Configuration name. Value range: N/A |
valid_values |
String |
Parameter description: Valid value. Value range: N/A |
default_value |
String |
Parameter description: Default value. Value range: N/A |
config_type |
String |
Parameter description: Configuration type. Value range:
|
value |
String |
Parameter description: Configuration value. Value range: N/A |
value_type |
String |
Parameter description: Configuration value type. Value range: N/A |
Example Requests
Querying the topic list
GET https://{endpoint}/v2/{project_id}/instances/{instance_id}/topics?offset=0&limit=10
Example Responses
Status code: 200
The query is successful.
{
"total" : 1,
"size" : 0,
"topics" : [ {
"policiesOnly" : false,
"name" : "Topic-test01",
"replication" : 3,
"partition" : 3,
"retention_time" : 72,
"sync_replication" : "false",
"sync_message_flush" : "false",
"topic_other_configs" : [ {
"name" : "max.message.bytes",
"valid_values" : "[0...10485760]",
"default_value" : "10485760",
"config_type" : "dynamic",
"value" : "10485760",
"value_type" : "int"
}, {
"name" : "message.timestamp.type",
"valid_values" : "[CreateTime, LogAppendTime]",
"default_value" : "LogAppendTime",
"config_type" : "dynamic",
"value" : "LogAppendTime",
"value_type" : "string"
} ],
"external_configs" : { },
"topic_type" : 0,
"topic_desc" : "This is a test topic",
"created_at" : 1688112779916
} ],
"remain_partitions" : 294,
"max_partitions" : 300,
"topic_max_partitions" : 200
}
SDK Sample Code
The SDK sample code is as follows.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
package com.huaweicloud.sdk.test;
import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.kafka.v2.region.KafkaRegion;
import com.huaweicloud.sdk.kafka.v2.*;
import com.huaweicloud.sdk.kafka.v2.model.*;
public class ListInstanceTopicsSolution {
public static void main(String[] args) {
// The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
// In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
String ak = System.getenv("CLOUD_SDK_AK");
String sk = System.getenv("CLOUD_SDK_SK");
String projectId = "{project_id}";
ICredential auth = new BasicCredentials()
.withProjectId(projectId)
.withAk(ak)
.withSk(sk);
KafkaClient client = KafkaClient.newBuilder()
.withCredential(auth)
.withRegion(KafkaRegion.valueOf("<YOUR REGION>"))
.build();
ListInstanceTopicsRequest request = new ListInstanceTopicsRequest();
request.withInstanceId("{instance_id}");
try {
ListInstanceTopicsResponse response = client.listInstanceTopics(request);
System.out.println(response.toString());
} catch (ConnectionException e) {
e.printStackTrace();
} catch (RequestTimeoutException e) {
e.printStackTrace();
} catch (ServiceResponseException e) {
e.printStackTrace();
System.out.println(e.getHttpStatusCode());
System.out.println(e.getRequestId());
System.out.println(e.getErrorCode());
System.out.println(e.getErrorMsg());
}
}
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# coding: utf-8
import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkkafka.v2.region.kafka_region import KafkaRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkkafka.v2 import *
if __name__ == "__main__":
# The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
# In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
ak = os.environ["CLOUD_SDK_AK"]
sk = os.environ["CLOUD_SDK_SK"]
projectId = "{project_id}"
credentials = BasicCredentials(ak, sk, projectId)
client = KafkaClient.new_builder() \
.with_credentials(credentials) \
.with_region(KafkaRegion.value_of("<YOUR REGION>")) \
.build()
try:
request = ListInstanceTopicsRequest()
request.instance_id = "{instance_id}"
response = client.list_instance_topics(request)
print(response)
except exceptions.ClientRequestException as e:
print(e.status_code)
print(e.request_id)
print(e.error_code)
print(e.error_msg)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
package main
import (
"fmt"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
kafka "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/v2"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/v2/model"
region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/v2/region"
)
func main() {
// The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
// In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
ak := os.Getenv("CLOUD_SDK_AK")
sk := os.Getenv("CLOUD_SDK_SK")
projectId := "{project_id}"
auth := basic.NewCredentialsBuilder().
WithAk(ak).
WithSk(sk).
WithProjectId(projectId).
Build()
client := kafka.NewKafkaClient(
kafka.KafkaClientBuilder().
WithRegion(region.ValueOf("<YOUR REGION>")).
WithCredential(auth).
Build())
request := &model.ListInstanceTopicsRequest{}
request.InstanceId = "{instance_id}"
response, err := client.ListInstanceTopics(request)
if err == nil {
fmt.Printf("%+v\n", response)
} else {
fmt.Println(err)
}
}
|
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
package com.huaweicloud.sdk.test;
import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.kafka.v2.region.KafkaRegion;
import com.huaweicloud.sdk.kafka.v2.*;
import com.huaweicloud.sdk.kafka.v2.model.*;
public class ListInstanceTopicsSolution {
public static void main(String[] args) {
// The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
// In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
String ak = System.getenv("CLOUD_SDK_AK");
String sk = System.getenv("CLOUD_SDK_SK");
String projectId = "{project_id}";
ICredential auth = new BasicCredentials()
.withProjectId(projectId)
.withAk(ak)
.withSk(sk);
KafkaClient client = KafkaClient.newBuilder()
.withCredential(auth)
.withRegion(KafkaRegion.valueOf("<YOUR REGION>"))
.build();
ListInstanceTopicsRequest request = new ListInstanceTopicsRequest();
request.withInstanceId("{instance_id}");
try {
ListInstanceTopicsResponse response = client.listInstanceTopics(request);
System.out.println(response.toString());
} catch (ConnectionException e) {
e.printStackTrace();
} catch (RequestTimeoutException e) {
e.printStackTrace();
} catch (ServiceResponseException e) {
e.printStackTrace();
System.out.println(e.getHttpStatusCode());
System.out.println(e.getRequestId());
System.out.println(e.getErrorCode());
System.out.println(e.getErrorMsg());
}
}
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# coding: utf-8
import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkkafka.v2.region.kafka_region import KafkaRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkkafka.v2 import *
if __name__ == "__main__":
# The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
# In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
ak = os.environ["CLOUD_SDK_AK"]
sk = os.environ["CLOUD_SDK_SK"]
projectId = "{project_id}"
credentials = BasicCredentials(ak, sk, projectId)
client = KafkaClient.new_builder() \
.with_credentials(credentials) \
.with_region(KafkaRegion.value_of("<YOUR REGION>")) \
.build()
try:
request = ListInstanceTopicsRequest()
request.instance_id = "{instance_id}"
response = client.list_instance_topics(request)
print(response)
except exceptions.ClientRequestException as e:
print(e.status_code)
print(e.request_id)
print(e.error_code)
print(e.error_msg)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
package main
import (
"fmt"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
kafka "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/v2"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/v2/model"
region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/v2/region"
)
func main() {
// The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
// In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
ak := os.Getenv("CLOUD_SDK_AK")
sk := os.Getenv("CLOUD_SDK_SK")
projectId := "{project_id}"
auth := basic.NewCredentialsBuilder().
WithAk(ak).
WithSk(sk).
WithProjectId(projectId).
Build()
client := kafka.NewKafkaClient(
kafka.KafkaClientBuilder().
WithRegion(region.ValueOf("<YOUR REGION>")).
WithCredential(auth).
Build())
request := &model.ListInstanceTopicsRequest{}
request.InstanceId = "{instance_id}"
response, err := client.ListInstanceTopics(request)
if err == nil {
fmt.Printf("%+v\n", response)
} else {
fmt.Println(err)
}
}
|
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
Status Code |
Description |
---|---|
200 |
The query is successful. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot