How to subscribe to interactive map layer changes
How to subscribe to interactive map layer changes
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.
Note
- Currently, this feature is only enabled for interactive map layers.
- This feature is not to be mixed up with catalog notifications.
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 typeperTransaction- Per transaction interactive map subscription typecontentChange- Content change interactive map subscription type
The result is an HRN which you can use for the other subscription management functions then.
val subscriptionName = "someSubscription"
val adminApi = DataClient().adminApi()
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).awaitString 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.
adminApi.unsubscribe(subscriptionHrn).awaitadminApi.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.
val exists = adminApi.checkIfSubscriptionExists(subscriptionHrn).await
println(
s"The subscription ${subscriptionHrn.toString} does ${if (exists) "" else "not "} exist")boolean exists =
adminApi.checkIfSubscriptionExists(subscriptionHrn).toCompletableFuture().get();
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.
adminApi.getSubscriptionConfiguration(subscriptionHrn).map(s => println(s.subscriptionHrn))System.out.println(
adminApi
.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.
adminApi
.listSubscriptions()
.map(_.foreach(s => println(s.subscriptionHrn)))
// --- OR ---
adminApi
.listSubscriptionsAsSource()
.map(_.runWith(Sink.seq).map(_.foreach(s => println(s.subscriptionHrn))))for (Iterator<SubscriptionConfiguration> iter =
adminApi.listSubscriptions().toCompletableFuture().get();
iter.hasNext(); ) {
System.out.println(iter.next().getSubscriptionHrn());
}Updated 21 days ago