Bulk subscriptions in one request using NotificationHandler

Greetings,

I am using the Platform Api's Java sdk and subscribing to more than 100 users' aggregate topics in one go. Here is the code snippet

NotificationHandler handler = NotificationHandler.Builder.standard()
					.withNotificationListeners(topicHandlers)
					.withApiClient(papiClient)
					.build();

topicHandlers, here can contain upto 1000 notificationlisteners. This is where i get the following exception

{"status":429,"code":"too.many.requests","entityName":"notification","message":"Rate limit exceeded the maximum [60] requests within [60] seconds","details":[{"errorCode":"inin-ratelimit-count","fieldName":"61"},{"errorCode":"inin-ratelimit-allowed","fieldName":"60"},{"errorCode":"inin-ratelimit-reset","fieldName":"44"}]}

I reckon each topic is getting sent as a new request for subscription, which should not ideally be the case since I am providing it in one go. I also have a method to add a subscription on the fly by using

handler.addSubscription(notificationHandler);

but a similar addSubscriptions method is missing that should post all the provided subscriptions as part of one request.

Please point out if I am missing on something obvious. Thanks.

Rate limits are in place to protect the system's integrity. You can read more about them here. When your app gets rate limited, it should wait the prescribed amount of time before making more requests. In the case of the example, that's 44 seconds.

Hi tim, i think i did not make myself clear, to be more clear

I want to send multiple topic subscriptions as part of one request using the notification handler for java sdk. I cant seem to find it.

You would use PUT /api/v2/notifications/channels/{channelId}/subscriptions (putNotificationsChannelSubscriptions) without using NotificationHelper in the SDK.

The helper in the SDK doesn't support subscribing to more than one topic at a time currently, so you'll have to manage this without the SDK's helper at this time. I've opened API-3484 to enhance the SDK to allow multiple topic subscriptions at once. This should be a fairly easy change, so I'll see if I can pull this in soon.

Hi tim, Thanks for the reply and for considering the request. Considering the size of the project that I am working on, I have just limited the number of topics that i subscribe to as of now in conformance with the rate limit, as changing the whole approach to handling websocket subscription would cost me a lot more than just developement hours. And I look forward to the enhancement releasing soon enough. Also, is there any way that i can track the status of the API-3484 that you have opened

I'll post back here when it's released.

1 Like

much thanks tim, and looking forward to it

I've added a withNotificationListeners(...) method to NotificationHandler's builder and addSubscriptions(...) to the NotificationHandler class in 40.2.0.

thanks tim for the fix, I have tested the version 40.2.0 for the desired functionality and it works.

I've added a withNotificationListeners(...) method to NotificationHandler's builder

Just a correction, this method was already present in the earlier version of the api but was not sending the provided handlers in one body. Again, thanks for the swift action.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.