11package io .github .protocol .pulsar .admin .jdk ;
22
3+ import com .fasterxml .jackson .core .type .TypeReference ;
4+ import io .github .openfacade .http .HttpResponse ;
5+ import io .github .protocol .pulsar .admin .common .JacksonService ;
6+
7+ import java .io .IOException ;
8+ import java .util .List ;
9+ import java .util .concurrent .ExecutionException ;
10+
311public class PersistentTopics extends BaseTopicsImpl {
412
513 private static final String BASE_URL_PERSISTENT_DOMAIN = "/admin/v2" + "/persistent" ;
@@ -11,4 +19,58 @@ public PersistentTopics(InnerHttpClient httpClient) {
1119 public String getDomainBaseUrl () {
1220 return BASE_URL_PERSISTENT_DOMAIN ;
1321 }
22+
23+ public void createSubscription (String tenant , String namespace , String encodedTopic , String subscriptionName ,
24+ boolean replicated , boolean authoritative , SubscriptionMessageId messageId )
25+ throws PulsarAdminException {
26+ String url = String .format ("%s/%s/%s/%s/subscription/%s" , getDomainBaseUrl (), tenant , namespace , encodedTopic ,
27+ subscriptionName );
28+ try {
29+ HttpResponse response =
30+ httpClient .put (url , messageId , "replicated" , String .valueOf (replicated ), "authoritative" ,
31+ String .valueOf (authoritative ));
32+ if (response .statusCode () != 204 ) {
33+ throw new PulsarAdminException (
34+ String .format ("failed to create subscription %s for topic %s/%s/%s, status code %s, body : %s" ,
35+ subscriptionName , tenant , namespace , encodedTopic , response .statusCode (),
36+ response .bodyAsString ()));
37+ }
38+ } catch (IOException | InterruptedException | ExecutionException e ) {
39+ throw new PulsarAdminException (e );
40+ }
41+ }
42+
43+ public void deleteSubscription (String tenant , String namespace , String encodedTopic , String subName , boolean force ,
44+ boolean authoritative ) throws PulsarAdminException {
45+ String url =
46+ String .format ("%s/%s/%s/%s/subscription/%s" , getDomainBaseUrl (), tenant , namespace , encodedTopic , subName );
47+ try {
48+ HttpResponse response =
49+ httpClient .delete (url , "force" , String .valueOf (force ), "authoritative" , String .valueOf (authoritative ));
50+ if (response .statusCode () != 204 ) {
51+ throw new PulsarAdminException (
52+ String .format ("failed to delete subscription %s of topic %s/%s/%s, status code %s, body : %s" ,
53+ subName , tenant , namespace , encodedTopic , response .statusCode (), response .bodyAsString ()));
54+ }
55+ } catch (IOException | InterruptedException | ExecutionException e ) {
56+ throw new PulsarAdminException (e );
57+ }
58+ }
59+
60+ public List <String > getSubscriptions (String tenant , String namespace , String encodedTopic , boolean authoritative )
61+ throws PulsarAdminException {
62+ String url = String .format ("%s/%s/%s/%s/subscriptions" , getDomainBaseUrl (), tenant , namespace , encodedTopic );
63+ try {
64+ HttpResponse response = httpClient .get (url , "authoritative" , String .valueOf (authoritative ));
65+ if (response .statusCode () != 200 ) {
66+ throw new PulsarAdminException (
67+ String .format ("failed to get subscriptions of topic %s/%s/%s, status code %s, body : %s" , tenant ,
68+ namespace , encodedTopic , response .statusCode (), response .bodyAsString ()));
69+ }
70+ return JacksonService .toRefer (response .body (), new TypeReference <List <String >>() {
71+ });
72+ } catch (IOException | InterruptedException | ExecutionException e ) {
73+ throw new PulsarAdminException (e );
74+ }
75+ }
1476}
0 commit comments