# Subscriptions

A subscription enables you to get notified about changes of data in a layer. If there happens a change of data of a supervised layer the backend will generate a message in the defined stream layer. You can then react to these stream layer messages like to any other regular stream layer message, e.g. using HERE platform's Flink environment.

#### Notes:

• Currently, this feature is only enabled for interactive map layers.

## Subscribe

To subscribe to interactive map layer changes, you need to call the subscribe function of AdminApi.

There are currently 3 interactive map layer subscription types:

• perFeature - Per feature interactive map subscription type
• perTransaction - Per transaction interactive map subscription type
• contentChange - Content change interactive map subscription type

The result is an HRN which you can use for the other subscription management functions then.

Scala
Java
val subscriptionName = "someSubscription"
val subscriptionConfig = WritableSubscriptionConfiguration(
subscriptionName = subscriptionName,
description = Some(s"description of $subscriptionName"), sourceCatalog = HRN.fromString("hrn:::::sourceCatalog"), sourceLayer = "someSourceLayer", destinationCatalog = HRN.fromString("hrn:::::destinationCatalog"), destinationLayer = "someDestinationLayer", interactiveMapSubscription = InteractiveMapSubscriptionConfiguration(InteractiveMapSubscriptionType.CONTENT_CHANGE) ) val subscriptionHrn = adminApi.subscribe(subscriptionConfig).await String subscriptionName = "someSubscription"; AdminApi adminApi = DataClient.get(myActorSystem).adminApi(); WritableSubscriptionConfiguration subscriptionConfig = WritableSubscriptionConfiguration.builder() .withSubscriptionName(subscriptionName) .withDescription(String.format("description of %s", subscriptionName)) .withSourceCatalog(HRN.fromString("hrn:::::sourceCatalog")) .withSourceLayer("someSourceLayer") .withDestinationCatalog(HRN.fromString("hrn:::::destinationCatalog")) .withDestinationLayer("someDestinationLayer") .withInteractiveMapSubscription( new InteractiveMapSubscriptionConfiguration.Builder() .withInteractiveMapSubscriptionType( InteractiveMapSubscriptionType.CONTENT_CHANGE()) .build()) .build(); HRN subscriptionHrn = adminApi.subscribe(subscriptionConfig).toCompletableFuture().get(); ## Unsubscribe To unsubscribe from interactive map layer changes, you need to call the unsubscribe function of AdminApi with the subscription HRN which you got from the subscribe call. Scala Java adminApi.unsubscribe(subscriptionHrn).await adminApi.unsubscribe(subscriptionHrn).toCompletableFuture().get(); ## Check if subscription exists You can check if subscription exists by calling the checkIfSubscriptionExists function of AdminApi with a subscription HRN. Scala Java val exists = adminApi.checkIfSubscriptionExists(subscriptionHrn).await println( s"The subscription${subscriptionHrn.toString} does \${if (exists) "" else "not "} exist")
boolean exists =
System.out.println(
String.format(
"The subscription %s does%s exist", subscriptionHrn.toString(), exists ? "" : " not"));

## Get subscription configuration

You can get the configuration of a subscription by calling the getSubscriptionConfiguration function of AdminApi with a subscription HRN.

Scala
Java
adminApi.getSubscriptionConfiguration(subscriptionHrn).map(s => println(s.subscriptionHrn))
System.out.println(
.getSubscriptionConfiguration(subscriptionHrn)
.toCompletableFuture()
.get()
.getSubscriptionHrn()
.toString());

## List subscriptions

You can get a list of all subscriptions which you have access to by calling the listSubscriptions function of AdminApi.

You can give an optional limit parameter which controls the size of the retrieved list pages. Default value is a 100 subscriptions per page. If you see some performance issues with the listSubscriptions call you should put a higher value.

Scala
Java
adminApi
.listSubscriptions()
.map(_.foreach(s => println(s.subscriptionHrn)))
// --- OR ---
.map(_.runWith(Sink.seq).map(_.foreach(s => println(s.subscriptionHrn))))
for (Iterator<SubscriptionConfiguration> iter =
}