Skip to content

Commit

Permalink
Added additional sample implementations of service handlers and metri…
Browse files Browse the repository at this point in the history
…cs exposure (#10)

Added additional sample implementations of service handlers and metrics exposure
  • Loading branch information
naveenad committed Jul 10, 2023
1 parent b654058 commit 4e61ad0
Show file tree
Hide file tree
Showing 27 changed files with 736 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
To view the readme for a specific example, please go to the specific example's readme file.

See [Gateway framework user's guide](https://download.diffusiondata.com/gateway-framework/latest/user-guide/contents/index.html) to get started with writing a Gateway application using the framework.
See [Gateway framework user's guide](https://download.diffusiondata.com/gateway-framework/latest/user-guide/contents/index.html) to get started with understanding Framework concepts, running a Gateway application and writing a Gateway application using the framework.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Main Gateway Application implementation for Csv sink application.
*
* @author Push Technology Limited
* @author DiffusionData Ltd
*/
final class CsvFileSinkApplication implements GatewayApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* CSV file sink handler to write received string update into a CSV file.
*
* @author Push Technology Limited
* @author DiffusionData Ltd
*/
@Immutable
final class CsvFileSinkHandler implements SinkHandler<String> {
Expand All @@ -34,7 +34,6 @@ final class CsvFileSinkHandler implements SinkHandler<String> {
@Override
public SinkServiceProperties getSinkServiceProperties() throws InvalidConfigurationException {
return newSinkServicePropertiesBuilder()
.topicType(TopicType.JSON)
.payloadConvertorName("$JSON_to_CSV_STRING")
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Main Runner class.
*
* @author Push Technology Limited
* @author DiffusionData Ltd
*/
public class Runner {
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* all the items of array will be looped to extract the headers. Hence, this
* convertor is suggested to be used only for simple and small JSON payload.
*
* @author Push Technology Limited
* @author DiffusionData Ltd
*/
public final class SimpleJSONToCsvStringConvertor
implements OutboundPayloadConvertor<String, JSON> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* Tests for {@link CsvFileSinkApplication}.
*
* @author Push Technology Limited
* @author DiffusionData Ltd
*/
class CsvFileSinkApplicationTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Tests for {@link CsvFileSinkHandler}.
*
* @author Push Technology Limited
* @author DiffusionData Ltd
*/
class CsvFileSinkHandlerTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Main Gateway Application implementation for Csv source application.
*
* @author Push Technology Limited
* @author DiffusionData Ltd
*/
final class CsvFileSourceApplication implements GatewayApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* Polling source handler implementation for CSV source.
*
* @author Push Technology Limited
* @author DiffusionData Ltd
*/
final class CsvPollingSourceHandler implements PollingSourceHandler {
private static final Logger LOG =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* Implementation of {@link StreamingSourceHandler} which listens to csv file
* changes and publishes contents to Diffusion server.
*
* @author Push Technology Limited
* @author DiffusionData Ltd
*/
final class CsvStreamingSourceHandler implements StreamingSourceHandler {
private static final Logger LOG =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Main Runner class.
*
* @author Push Technology Limited
* @author DiffusionData Ltd
*/
public class Runner {
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Sample configuration required for source application.
*
* @author Push Technology Limited
* @author DiffusionData Ltd
*/
public final class SourceConfig {
private String fileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Validator for {@link SourceConfig} instance.
*
* @author Push Technology Limited
* @author DiffusionData Ltd
*/
public final class SourceConfigValidator {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
/**
* Tests for {@link CsvFileSourceApplication}.
*
* @author Push Technology Limited
* @author DiffusionData Ltd
*/
@ExtendWith(MockitoExtension.class)
class CsvFileSourceApplicationTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/**
* Tests for {@link CsvPollingSourceHandler}.
*
* @author Push Technology Limited
* @author DiffusionData Ltd
*/
@ExtendWith({MockitoExtension.class})
class CsvPollingSourceHandlerTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/**
* Tests for {@link CsvStreamingSourceHandler}.
*
* @author Push Technology Limited
* @author DiffusionData Ltd
*/
@ExtendWith(MockitoExtension.class)
class CsvStreamingSourceHandlerTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* Tests for {@link SourceConfigValidator}.
*
* @author Push Technology Limited
* @author DiffusionData Ltd
*/
@ExtendWith(MockitoExtension.class)
class SourceConfigValidatorTest {
Expand Down
119 changes: 119 additions & 0 deletions misc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Example Gateway Application

## Introduction

This example Gateway application is created to demonstrate creating Hybrid
service type (handlers) and Streaming source service types which handles missing
topic notifications. It is also implemented to expose JMX and Prometheus metrics.

This application supports two service types:

1. DATE_APPENDER
2. MISSING_TOPIC_HANDLER

### DATE_APPENDER

This hybrid service supports getting Diffusion JSON topic updates and appends
a timestamp to the JSON data, if the data is of type JSON object. Any other types of JSON data will be ignored. The updated data will then be
published to another Diffusion JSON topic. This target Diffusion topic path will
be created by appending value of `targetTopicPrefix` from service configuration
to the actual path, from where the update is received. Setting `targetTopicPrefix` in configuration is optional. If this configuration parameter is not set then its default value is used which is `enhanced/`.

The schema of configuration for this service type is:

```json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"targetTopicPrefix": {
"type": "string",
"default": "enhanced/",
"description": "The target Diffusion topic prefix to publish updates to. This prefix is appended to the topic path from which the update is received, creating a new topic path. The updated data is then published to the newly created topic path"
}
}
}
```

Below is an example of an overall configuration of a service of
type `DATE_APPENDER`:

```json
{
"serviceName": "dateAppender1",
"serviceType": "DATE_APPENDER",
"config": {
"framework": {
"sink": {
"diffusionTopicSelector": "fx/EUR"
}
},
"application": {
"targetTopicPrefix": "updated/"
}
}
}
```

With this configuration, the service will subscribe to the `fx/EUR` topic path.
Upon receiving an update for this topic, if the update is in the form of a JSON
object, the service will add a timestamp to the update and publish it to a new
JSON topic named `updated/fx/EUR`

### MISSING_TOPIC_HANDLER

This streaming source service registers a Missing topic notification handler for
the `missingTopicSelector` that is passed in the configuration. If there is any
subscription to the configured missing topic branch, the service would create
the missing topic of type JSON and publish a dummy JSON data.

The schema of configuration for this service type is:

```json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"missingTopicSelector": {
"type": "string",
"description": "Missing topic selector to get missing topic notifications"
}
},
"required": [
"missingTopicSelector"
]
}
```

Below is an example of an overall configuration of a service of
type `MISSING_TOPIC_HANDLER`:

```json
{
"serviceName": "missingTopicHandler1",
"serviceType": "MISSING_TOPIC_HANDLER",
"config": {
"application": {
"missingTopicSelector": "fx/EUR"
}
}
}
```

With this configuration, the service will register for missing topic
notifications for the `fx/EUR` topic path. If any other session subscribes to
this path and the topic does not exist in the server, this service will create a
JSON-type topic and publish dummy data to it.

NOTE:
> For the demonstration purposes, the supplied configuration file: `src/main/resources/configuration.json` is created such that, a service of type `MISSING_TOPIC_HANDLER` will be created which will register for missing topic notification for topic path `fx/EUR`. Services of type `DATE_APPENDER` are created such that they subscribe to topic `fx/EUR`. Hence, when these services are added into the application, services `dateAppender1` and `dateAppender2` will subscribe to `fx/EUR` topic and service `missingTopicHandler` will create and update `fx/EUR` topic. As soon as the topic is created, `dateAppender1` and `dateAppender2` will send updates with date appended in them to topics `updated/fx/EUR` and `enhanced/fx/EUR` respectively.
## Metrics
Out of the box metrics provided by Framework are exposed with JMX and Prometheus.

Exposed Prometheus metrics can be accessed using `http://localhost:8085/metrics`.

## Running the application in IDE
To run the application via IDE, run `misc/src/main/java/com/diffusiondata/gateway/example/Runner.java` file. Configuration file can be set as VM arguments in Run configuration as follows:

> -Dgateway.config.file=misc/src/main/resources/configuration.json -Dgateway.config.use-local-services=true
32 changes: 32 additions & 0 deletions misc/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>gateway-examples</artifactId>
<groupId>com.diffusiondata.gateway.adapter</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>misc</artifactId>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-jmx</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit 4e61ad0

Please sign in to comment.