kotlingraphqlquarkussubscriptionunsubscribe

Quarkus GraphQL Subscription cancelled


I am running subscription on my server (then processed to redis), but I need to invoke action if client disconnect (whether the connection failed or he leaves the page. Is it even possible? I cannot find any documentation or example after few days of searching.

Example of the subscription endpoint

@Subscription("Notification")
fun notification(id: UUID): Multi<NotificationDto>? {
    
    return dataSource.pubsub(NotificationDto::class.java)
        .subscribe(id.toString())
        .broadcast()
        .toAllSubscribers() 

}

Solution

  • Simply add an onTermination callback to the Multi that your subscription method returns.

    return ...
      .onTermination(() -> // your code here)