Glen Mazza's Weblog

https://glenmazza.net/blog/date/20240527 Monday May 27, 2024

Java (well, Kotlin) Client for Splash Events

To my blog-samples project I've added a Splash Events client using Spring Security's OAuth2 client support. Out of the box, it contains APIs for querying events, event extra details, event attendees, and contacts (attendees for one or more events), see its integrated tests for examples on how this client can be used. Although written in Kotlin, it should work fine integrated with any JVM-compatible language, I use it with a Java application.

One peculiarity with Splash Events is the API returning a 200 with a 429 internal error code when too many requests are being made, requiring some delay (usually a second will do) before making another request. I believe the limitation for at least my project is no more than two calls per second allowed, something that can easily occur when querying for many contacts or events. For optimal performance, for areas of the code where you're rapidly querying Splash, it's good to install an adjustable wait-state prior to making the call, to avoid the delays with receiving the 429 and making another call thereafter. Choose the smallest wait state that doesn't result in excessive 429 messages. Further, of course, code calling the client should still handle the case of a 429 getting returned, pausing, and making the same request again. For my calls to get contact data, I use code similar to the following:

private Contact getContact(String contactId) {
    do {
        try {
            insertDelay();   // Thread.sleep(xxx) etc.
            return splashQueryRunner.getContact(contactId).getData();
        } catch (ServiceException exception) {
            int statusCode = exception.getStatusCode();
            if (statusCode == 429) {
                pauseDueToTooManyRequests();  // Thread.sleep(xxx) with different logging
            } else {
                // something else
                logger.error("getContact API Call Service Exception: code = {}, message = {}",
                        statusCode, exception.getMessage());
                throw exception;
            }
        } catch (Exception exception) {
            logger.error("Splash API getContact event call returned error", exception);
            throw exception;
        }
    } while (true);
}

Posted by Glen Mazza in Programming at 07:00AM May 27, 2024 | Comments[0]

Post a Comment:

Calendar
« June 2024
Sun Mon Tue Wed Thu Fri Sat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Today
About Me
Java Software Engineer
TightBlog project maintainer
Arlington, Virginia USA
glen.mazza at pm dot me
GitHub profile for Glen Mazza at Stack Overflow, Q&A for professional and enthusiast programmers
Blog Search


Blog article index
Navigation
About Blog
Blog software: TightBlog 4.0.0
Application Server: Tomcat
Database: MySQL
Hosted on: Linode
SSL Certificate: Let's Encrypt
Installation Instructions