Java SDK
Kero’s server-side helper libraries (also known as server-side SDKs) reduce the amount of work required to use Kero’s REST APIs, by reducing the boilerplate code you have to write. Below are the installation instructions for these libraries in Java.
Kero’s Java SDK provides full access to the API and consists of two parts:
- The live feed that provides updates on markets and events in real-time.
- The API that allows for interaction with Kero’s markes and events.
Tutorial
Section titled “Tutorial”Here is an example of a Kero SDK implementation using a Java Spring Boot application:
-
Import the Kero-SDK library by adding dependencies:
repositories {// other repositories heremaven {url 'https://sdk-artifactory.rushsports.io/artifactory/java-sdk/'}}dependencies {// other dependencies hereimplementation 'com.kero:kero:1.8.2'}<repositories><!-- other repositories here --><repository><id>kero-sdk-artifactory</id><url>https://sdk-artifactory.rushsports.io/artifactory/java-sdk/</url></repository></repositories><dependencies><!-- other dependencies here --><dependency><groupId>com.kero</groupId><artifactId>kero</artifactId><version>1.8.2</version></dependency></dependencies>resolvers += "Kero SDK Artifactory" at "https://sdk-artifactory.rushsports.io/artifactory/java-sdk/"libraryDependencies += "com.kero" % "kero" % "1.8.2" -
Add environment variables:
KERO_SDK_FEED_TYPE=RABBITMQ;KERO_SDK_ENVIRONMENT=DEMO;KERO_SDK_USERNAME={ask support for credentials};KERO_SDK_PASSWORD={ask support for credentials}; -
Initialize the KeroSDK bean (it’s an entry point and should be singleton):
/*** Partner's configuration class*/@Configurationpublic class MainConfig {/*** This bean is an entry point to the Kero system.* @return*/@Beanpublic KeroSDK sdk() {return KeroSDK.getInstance();}}Initialization with credentials:
@Configurationpublic class MainConfig {/*** Initializes KeroSDK with authentication credentials.* @return KeroSDK instance with credentials*/@Beanpublic KeroSDK sdk() {return KeroSDK.getInstance("username", "password");}} -
Use the KeroSDK bean to interact with the Kero REST API:
/*** Some controller in the partner's application*/@RestController@RequiredArgsConstructorpublic class MainController {private final KeroSDK kero;/*** This route returns a page of filtered events @see com.kero.dto.Event.* @param sport filter by sport enum @see com.kero.dto.Sport* @param source filter by source, provided as a string* @param availableForSubscription filter returns events that partner is not subscribed to* @param live filter returns only currently active events to which the partner is subscribed* @param ended filter returns only closed events to which the partner was subscribed* @param search filter returns events with a search by event.name and event.shortName* @param page page number (begins from 1)* @param size number of events per page* @return a page of filtered events*/@GetMapping(value = "/events", produces = MediaType.APPLICATION_JSON_VALUE)public ResponseEntity<?> events(@RequestParam(required = false) Sport sport,@RequestParam(required = false) String source,@RequestParam(required = false) boolean availableForSubscription,@RequestParam(required = false) boolean live,@RequestParam(required = false) boolean ended,@RequestParam(required = false) String search,@RequestParam int page,@RequestParam int size) {return ResponseEntity.ok().body(kero.listEvents(new EventQuery(sport, source, availableForSubscription, live, ended, search, page, size)));}/*** This method lists all the markets available in the Kero feed.* @param marketState filter by market state enum @see com.kero.dto.MarketState* @param marketKeys filter by market keys* @param page page number (begins from 1)* @param size number of markets per page (no more than 50)* @param eventId Kero uuid of the event* @return a {@link Pageable} of markets*/@GetMapping(value = "/events/{eventId}/markets", produces = MediaType.APPLICATION_JSON_VALUE)public ResponseEntity<?> markets(@RequestParam(required = false) MarketState marketState,@RequestParam(required = false) ArrayList<String> marketKeys,@PathVariable String eventId,@RequestParam int page,@RequestParam int size) {MarketQuery query = new MarketQuery(page, size);if (marketState != null && marketState.describeConstable().isPresent())query.setMarketState(marketState);if (marketKeys != null && !marketKeys.isEmpty())query.setMarketKeys(marketKeys);if (eventId.equals("all"))query.setAll(true);elsequery.setEventId(UUID.fromString(eventId));return ResponseEntity.ok().body(kero.listMarketsWithVariables(query));}/*** This method lists all the markets samples available in the Kero feed.** @return a map of templates where the key is the template id, the value is a map of translations.* In this inner map the key is the language code* (ISO-639 Set 1 or ISO-639 Set 2 for languages that aren't presented in the Set 1 like "cnr")* and the value is the translation.*/@GetMapping(value = "/markets/templates", produces = MediaType.APPLICATION_JSON_VALUE)public ResponseEntity<?> templates() {return ResponseEntity.ok().body(kero.listSamples());}/*** This method lists all the teams available in the Kero feed for mapping purpose.* @return a list of {@link Team}*/@GetMapping(value = "/teams", produces = MediaType.APPLICATION_JSON_VALUE)public ResponseEntity<?> teams() {return ResponseEntity.ok().body(kero.listTeams());}/*** This method lists all the players available in the Kero feed for mapping purpose.* @return a list of {@link Player}*/@GetMapping(value = "/players", produces = MediaType.APPLICATION_JSON_VALUE)public ResponseEntity<?> players() {return ResponseEntity.ok().body(kero.listPlayers());}/*** This method subscribes to the game using its source and source game id.* @param id the Kero event uuid.*/@GetMapping(value = "/{id}/subscribe")public ResponseEntity<?> subscribe(@PathVariable UUID id) {kero.subscribe(id);return ResponseEntity.ok().build();}/*** This method unsubscribes from the particular event.* @param id the Kero event uuid.*/@GetMapping(value = "/{id}/unsubscribe")public ResponseEntity<?> unsubscribe(@PathVariable UUID id) {kero.unsubscribe(id);return ResponseEntity.ok().build();}/*** This method starts the simulation of the events. Only 5 running simulation are available at the moment.* @param catalogueId the id of the catalogue item to simulate* @param startsAt time when the simulation should start (must be in UTC epoch seconds).* In any case, the simulation will start no earlier than now + 20 minutes.* @return the {@link Simulation} that is being simulated* @since 1.7.5*/@PostMapping(value = "/sim/start", consumes = MediaType.APPLICATION_JSON_VALUE)public ResponseEntity<?> sim(@RequestBody SimRequest request) {return ResponseEntity.ok().body(kero.startSim(request.getCatalogueId(), request.getStartsAt()));}/*** This method stops the simulation of the event running.* @param simGameId the Kero game id of the simulation to stop* @since 1.7.5*/@GetMapping(value = "/sim/{id}/stop")public ResponseEntity<?> sim(@RequestParam String id) {kero.stopSim(id);return ResponseEntity.ok().build();}/*** This method lists all the events which can be simulated.* @return a list of {@link Event}*/@GetMapping(value = "/sim/catalogue", produces = MediaType.APPLICATION_JSON_VALUE)public ResponseEntity<?> sim() {return ResponseEntity.ok().body(kero.listSimCatalogue());}} -
To connect to the Kero live feed, implement the Kero Feed listener:
/*** Kero Feed listener implementation*/@Service@Slf4jpublic class KeroFeedImpl implements KeroFeed {/*** This method represents events feed. Partner will receive all the updates regarding the assigned events.* @param event @see com.kero.dto.Event that was updated* @param action action that was performed on the market* @param timestamp time of the message*/@Overridepublic void eventsFeed(Event event, FeedAction action, long timestamp) {log.info("Event feed: {}", event);}} -
Register the listener in the KeroSDK (e.g. on application start):
@Component@RequiredArgsConstructorpublic class AppListener {/*** Kero SDK instance injected*/private final KeroSDK sdk;/*** Kero Feed listener injected*/private final KeroFeed feed;/*** Application start listener. Here the sdk is initialized.*/@EventListener(ApplicationReadyEvent.class)public void handleApplicationStart() {try {sdk.init(feed);} catch (Exception e) {// process the exception as needed// exception here can happen when some settings are incorrect// i.e. wrong password, environment, etc.e.printStackTrace();}}} -
Now, you will receive all market and event updates in the
KeroFeedImplclass methods.