From 52c73fca921d169efbcdaee8bb05e9cb0857606a Mon Sep 17 00:00:00 2001 From: nagarjunakuchi Date: Sun, 11 Feb 2024 14:42:26 +0530 Subject: [PATCH] Added config for subscription --- mediator/pom.xml | 4 +- .../opencrvs/config/SubscribeConfig.java | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 mediator/src/main/java/io/mosip/opencrvs/config/SubscribeConfig.java diff --git a/mediator/pom.xml b/mediator/pom.xml index 2df944b..4bdc672 100644 --- a/mediator/pom.xml +++ b/mediator/pom.xml @@ -113,11 +113,11 @@ httpclient ${apache.httpcomponents.version} - + io.micrometer diff --git a/mediator/src/main/java/io/mosip/opencrvs/config/SubscribeConfig.java b/mediator/src/main/java/io/mosip/opencrvs/config/SubscribeConfig.java new file mode 100644 index 0000000..c7b060c --- /dev/null +++ b/mediator/src/main/java/io/mosip/opencrvs/config/SubscribeConfig.java @@ -0,0 +1,46 @@ +package io.mosip.opencrvs.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +import io.mosip.kernel.core.websub.spi.SubscriptionClient; +import io.mosip.kernel.websub.api.model.SubscriptionChangeRequest; +import io.mosip.kernel.websub.api.model.SubscriptionChangeResponse; +import io.mosip.kernel.websub.api.model.UnsubscriptionRequest; + +@Configuration +public class SubscribeConfig { + + @Autowired + protected SubscriptionClient subscriptionClient; + + @Value("${websub.hub.url}") + private String hubUrl; + + @Value("${mosip.opencrvs.partner.client.sha.secret}") + private String callBackSecret; + + @Value("${mosip.opencrvs.partner.client.id}") + private String topic; + + @Value("${mosip.receive.credential.url}") + private String callbackUrl; + + protected void subscribeForPartnerCertEvent() { + try { + System.out.println("Started subscribing......."); + SubscriptionChangeRequest subscriptionRequest = new SubscriptionChangeRequest(); + subscriptionRequest.setCallbackURL(callbackUrl); + subscriptionRequest.setSecret(callBackSecret); + subscriptionRequest.setTopic(topic+ "/CREDENTIAL_ISSUED"); + subscriptionRequest.setHubURL(hubUrl); + subscriptionClient.subscribe(subscriptionRequest); + System.out.println("Subscribing done.......... for event " + topic+ "/CREDENTIAL_ISSUED"); + } catch (Exception e) { + System.out.println("Error while subscribing.........."); + e.printStackTrace(); + throw e; + } + } +}