Ana içeriğe geç

6.2.2. İstemci API (Client)#

Yoklama(polling) tabanlı bildirim uygulamasının rest api uçlarını kullanmayı sağlayan yapıdır.

Bağımlılıklar#

Gradle Bağımlılıkları

dependencyManagement {
    imports {
        mavenBom "tr.com.havelsan.framework.notification.cloud:hvl-notification-parent"
    }
}

compile (
    [group: 'tr.com.havelsan.framework.notification.cloud' , name: 'hvl-notification-polling-cloud-client']
)

Rest Servis Tanımı#

Feign client uçlarını kullanabilmek için configurasyon bean'ine asağıdaki annotasyonlar eklenmelidir.

Rest Client Kullanımı

Service metodlarının detaylarına swagger dokümanından ulaşabilirsiniz.

Hvl-polling Servis Başlatılması#

Uyarı

Öncelikli olarak notification-polling-service başlatılmış olmalıdır.

Docker bilgisine buradan ulaşabilirsiniz.

Bildirim Şablonu Oluşturma#

İşlem Yetkisi Verilmesi

Bildirim Şablonu oluşturmak işin "Bildirim Yönetim Yetkisi-notification_manager" servisi kullanan asycn token kullanıcısına verilmiş olmalıdır.

private static final String CODE = "POLLING_SAMPLE";

final HvlNotificationPollingTemplateRestService pollingTemplateRestService = configurableApplicationContext.getBean(HvlNotificationPollingTemplateRestService.class);

final HvlNotificationTemplateModelBuilder templateModelBuilder = HvlNotificationTemplateModelBuilder.create()
        .withCode(CODE)
        .withName("Sample template name")
        .withType(HvlNotificationType.POLLING);

final HvlNotificationTemplateContentModel templateContentModelTr = HvlNotificationTemplateContentModelBuilder
        .create()
        .withSender("EKSEN APP")
        .withSubject("Örnek Bildirim Başlığı:${dynamicSubject}")
        .withContentType(HvlNotificationTemplateContentType.STRING)
        .withContent("Örnek bildirim: ${nameSurname}")
        .build();

final HvlNotificationTemplateContentModel templateContentModelEn = HvlNotificationTemplateContentModelBuilder
        .create()
        .withSender("sender@bulut.ai")
        .withSubject("Sample Polling Subject:${dynamicSubject}")
        .withContentType(HvlNotificationTemplateContentType.STRING)
        .withContent("Sample Polling: ${nameSurname}")
        .build();

final Map<String, HvlNotificationTemplateContentModel> contentMap = new HashMap<>();
        contentMap.put(Locale.of("tr").toString(), templateContentModelTr);
        contentMap.put(Locale.of("en").toString(), templateContentModelEn);
        templateModelBuilder.withContentMap(contentMap);

final HvlNotificationTemplateModel templateModel = templateModelBuilder.build();

pollingTemplateRestService.save(templateModel);

Rest İle Bildirim Gönderimi#

Basit Bildirim Gönderimi#

final HvlNotificationPollingUserRestService notificationPollingUserRestService = configurableApplicationContext.getBean(HvlNotificationPollingUserRestService.class);

final HvlNotificationPollingUserModel pollingUserModel = HvlNotificationPollingUserModelBuilder.create()
        .withAssigneeUser("hvltest1")
        .withType("Sample")
        .withTitle("EKSEN Framework Dökümanları")
        .withShortDescription("EKSEN framework dökümantasyonunu incelemek için tıklayınız.")
        .withRedirectUrl("https://eksen.bulut.ai/")
        .withReferenceUuid(UUID.randomUUID().toString())
        .withSource("KEYSİS")
        .withPriority(HvlNotificationPollingPriority.IMPORTANT)
        .build();

notificationPollingUserRestService.send(pollingUserModel);

Şablon Kodu Kullanarak Bildirim Gönderimi#

Uyarı

"SAMPLE_TEMPLATE_CODE" bu kod ile uygun bir template oluşturulduğu varsayılmaktadır.(Bkz.Mail Şablonu Oluşturma)

final HvlNotificationPollingUserRestService notificationPollingUserRestService = configurableApplicationContext.getBean(HvlNotificationPollingUserRestService.class);

private static final String CODE = "POLLING_SAMPLE;

final HvlNotificationPollingUserModelWithCode pollingUserModelWithCode = HvlNotificationPollingUserModelWithCodeBuilder.create()
        .withAssigneeUser("hvltest1")
        .withType(HvlNotificationPollingType.POLLING)
        .withCode(CODE)
        .withLocale(Locale.of("tr"))
        .withRedirectUrl("https://eksen.bulut.ai/")
        .withNecessity(true)
        .withSource("SAMPLE_APP_WITH_CODE")
        .withPriority(HvlNotificationPollingPriority.IMPORTANT)
        .withNecessity(true)
        .withReferenceUuid(UUID.randomUUID().toString())
        .withAttribute("nameSurname", "John DOE")
        .withAttribute("dynamicSubject", "Dinamil Başlık")
        .build();

notificationPollingUserRestService.sendWithCode(pollingUserModelWithCode);

Rest İle Duyuru Gönderimi#

final HvlNotificationPollingUserRestService notificationPollingUserRestService = configurableApplicationContext.getBean(HvlNotificationPollingUserRestService.class);

final HvlNotificationPollingUserModel pollingUserAnnouncementModel = HvlNotificationPollingUserModelBuilder.create()
        .withAssigneeUser("hvltest1")
        .withType(HvlNotificationPollingType.ANNOUNCEMENT)//Duyuru 
        .withTitle("Announcemen title")
        .withShortDescription("EKSEN framework dökümantasyonunu incelemek için tıklayınız.")
        .withRedirectUrl("https://eksen.bulut.ai/")
        .withReferenceUuid(UUID.randomUUID().toString())
        .withSource("KOVAN")
        .withPriority(HvlNotificationPollingPriority.IMPORTANT)
        .build();

notificationPollingUserRestService.send(pollingUserAnnouncementModel);

Şablon Kodu İle Duyuru Göndermek İçin

İlgili şablon kodu ile bir template oluşturulmuş olmalıdır

.withType(HvlNotificationPollingType.ANNOUNCEMENT)//Duyuru için type

Kafka İle Bildirim Gönderimi#

Kafka ile bildirim gönderimi için Kafka'nın çalıştırılması gerekmektedir.

Kafka docker bilgisine buradan ve cluster docker bilgisine buradan ulaşabilirsiniz.

Bilgilendirme

Kafka ile ilgili bilgilendirme dökümanına buradan ulaşabilirsiniz.

Bilgilendirme

EKSEN framework kafka altyapısı ile ilgili bilgilere buradan ulaşabilirsiniz.

Uyarı

POLLING_EVENT_TOPIC bildirim gönderimi için kullanılacak kafka topic adıdır. (Bkz.Hvl polling service başlatılması) Polling docker instance'ına environment değişken olarak verilen POLLING_EVENT_TOPIC ile eşleşmelidir.

İlgili docker compose dosyasına buradan ulaşabilirsiniz.

Gradle Bağımlılıkları

 api(
   [group: 'tr.com.havelsan.framework.mq', name: 'hvl-kafka'],
   [group: 'tr.com.havelsan.framework.notification', name: 'hvl-notification-polling-common']
   )

Kafka topic'e mesaj yazarak bildirim gönderimi#

final String  POLLING_EVENT_TOPIC="javalt-oauth-polling-notification";

final HvlEventNotifier eventNotifier = configurableApplicationContext.getBean(HvlEventNotifier.class);

final HvlNotificationPollingUserModel pollingUserModel = HvlNotificationPollingUserModelBuilder.create()
        .withAssigneeUser("hvltest1")
        .withType(HvlNotificationPollingType.POLLING)
        .withTitle("Bildirim Başlığı")
        .withShortDescription("Bildirim içeriği bu kısımda yer alacaktır.")
        .withRedirectUrl("https://eksen.bulut.ai/")
        .withReferenceUuid(UUID.randomUUID().toString())
        .withSource("SAMPLE_APP")
        .withPriority(HvlNotificationPollingPriority.IMPORTANT)
        .build();

eventNotifier.notifySync(POLLING_EVENT_TOPIC, pollingUserModel);

}

Kafka topic'e mesaj kodu yazarak bildirim gönderimi#

Uyarı

"SAMPLE_TEMPLATE_CODE" bu kod ile uygun bir template oluşturulduğu varsayılmaktadır.[(Bkz.Mail Şablonu Oluşturma)]
final String  POLLING_EVENT_TOPIC="javalt-oauth-polling-notification";
final HvlEventNotifier eventNotifier = configurableApplicationContext.getBean(HvlEventNotifier.class);

final HvlNotificationPollingUserModelWithCode message = HvlNotificationPollingUserModelWithCodeBuilder.create()
        .withAssigneeUser("hvltest1")
        .withType(HvlNotificationPollingType.POLLING)
        .withCode("SAMPLE_TEMPLATE_CODE")
        .withLocale(Locale.of("tr"))
        .withNecessity(true)
        .withSource("SAMPLE_APP_WITH_CODE")
        .withReferenceUuid(UUID.randomUUID().toString())
        .withPriority(HvlNotificationPollingPriority.CRITICAL)
        .withAttribute("expirationDatetime", "19.07.2026")
        .build();

eventNotifier.notifySync(POLLING_EVENT_TOPIC, message);