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,56 @@ public PersistentTopics(InnerHttpClient httpClient) {
1119 public String getDomainBaseUrl () {
1220 return BASE_URL_PERSISTENT_DOMAIN ;
1321 }
22+
23+
24+ public void createSubscription (String tenant , String namespace , String encodedTopic , String subscriptionName ,
25+ boolean replicated , boolean authoritative , SubscriptionMessageId messageId ) throws PulsarAdminException {
26+ String url = String .format ("%s/%s/%s/%s/subscription/%s" , getDomainBaseUrl (), tenant , namespace , encodedTopic , subscriptionName );
27+ try {
28+ HttpResponse response = httpClient .put (url , messageId ,
29+ "replicated" , String .valueOf (replicated ),
30+ "authoritative" , String .valueOf (authoritative ));
31+ if (response .statusCode () != 204 ) {
32+ throw new PulsarAdminException (
33+ String .format ("failed to create subscription %s for topic %s/%s/%s, status code %s, body : %s" ,
34+ subscriptionName , tenant , namespace , encodedTopic , response .statusCode (), response .bodyAsString ()));
35+ }
36+ } catch (IOException | InterruptedException | ExecutionException e ) {
37+ throw new PulsarAdminException (e );
38+ }
39+ }
40+
41+ public void deleteSubscription (String tenant , String namespace , String encodedTopic , String subName ,
42+ boolean force , boolean authoritative ) throws PulsarAdminException {
43+ String url = String .format ("%s/%s/%s/%s/subscription/%s" , getDomainBaseUrl (), tenant , namespace , encodedTopic , subName );
44+ try {
45+ HttpResponse response = httpClient .delete (url ,
46+ "force" , String .valueOf (force ),
47+ "authoritative" , String .valueOf (authoritative ));
48+ if (response .statusCode () != 204 ) {
49+ throw new PulsarAdminException (
50+ String .format ("failed to delete subscription %s of topic %s/%s/%s, status code %s, body : %s" ,
51+ subName , tenant , namespace , encodedTopic , response .statusCode (), response .bodyAsString ()));
52+ }
53+ } catch (IOException | InterruptedException | ExecutionException e ) {
54+ throw new PulsarAdminException (e );
55+ }
56+ }
57+
58+ public List <String > getSubscriptions (String tenant , String namespace , String encodedTopic , boolean authoritative )
59+ throws PulsarAdminException {
60+ String url = String .format ("%s/%s/%s/%s/subscriptions" , getDomainBaseUrl (), tenant , namespace , encodedTopic );
61+ try {
62+ HttpResponse response = httpClient .get (url , "authoritative" , String .valueOf (authoritative ));
63+ if (response .statusCode () != 200 ) {
64+ throw new PulsarAdminException (
65+ String .format ("failed to get subscriptions of topic %s/%s/%s, status code %s, body : %s" ,
66+ tenant , namespace , encodedTopic , response .statusCode (), response .bodyAsString ()));
67+ }
68+ return JacksonService .toRefer (response .body (), new TypeReference <List <String >>() {
69+ });
70+ } catch (IOException | InterruptedException | ExecutionException e ) {
71+ throw new PulsarAdminException (e );
72+ }
73+ }
1474}
0 commit comments