Skip to content

Commit

Permalink
Add Healthcheck (#6)
Browse files Browse the repository at this point in the history
* add healthcheck and basic docs

* fix linting
  • Loading branch information
jabberwoc authored May 14, 2024
1 parent cfd314c commit dd54a52
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ WORKDIR /opt/hl7-to-kafka
COPY --from=build /home/gradle/src/dependencies/ ./
COPY --from=build /home/gradle/src/spring-boot-loader/ ./
COPY --from=build /home/gradle/src/application/ ./
COPY HealthCheck.java .

ARG GIT_REF=""
ARG GIT_URL=""
Expand All @@ -27,8 +28,7 @@ EXPOSE 8080 2575

ENTRYPOINT ["java", "-XX:MaxRAMPercentage=90", "org.springframework.boot.loader.launch.JarLauncher"]

HEALTHCHECK --interval=25s --timeout=3s --retries=2 \
CMD curl --fail --silent localhost:8080/actuator/health | grep UP || exit 1
HEALTHCHECK --interval=25s --timeout=3s --retries=2 CMD ["java", "HealthCheck.java", "||", "exit", "1"]

LABEL org.opencontainers.image.created=${BUILD_TIME} \
org.opencontainers.image.authors="Sebastian Stöcker" \
Expand Down
27 changes: 27 additions & 0 deletions HealthCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse.BodyHandlers;

public class HealthCheck {

private static final int STATUS_OK = 200;

public static void main(String[] args)
throws InterruptedException, IOException {

var client = HttpClient.newHttpClient();
var request = HttpRequest
.newBuilder()
.uri(URI.create("http://localhost:8080/actuator/health"))
.header("accept", "application/json")
.build();
var response = client.send(request, BodyHandlers.ofString());
if (response.statusCode() != STATUS_OK || !response
.body()
.contains("UP")) {
throw new RuntimeException("Healthcheck failed");
}
}
}
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# hl7-to-kafka
[![MegaLinter](https://github.com/diz-unimr/hl7-to-kafka/actions/workflows/mega-linter.yml/badge.svg?branch=main)](https://github.com/diz-unimr/hl7-to-kafka/actions/workflows/mega-linter.yml?query=branch%3Amain) ![java](https://github.com/diz-unimr/hl7-to-kafka/actions/workflows/build.yml/badge.svg) ![docker](https://github.com/diz-unimr/hl7-to-kafka/actions/workflows/release.yml/badge.svg) [![codecov](https://codecov.io/gh/diz-unimr/hl7-to-kafka/graph/badge.svg?token=6vQBSuFCH3)](https://codecov.io/gh/diz-unimr/hl7-to-kafka)

> HL7 v2 to Kafka producer
This project consist of a HL7v2 MLLP listener, which transfers received
messages to a Kafka topic.

Messages are passed to a Kafka producer and send to a configured topic
without any mapping. The sender receives an acknowledgement message (ACK) of
each message sent.

## <a name="deploy_config"></a> Configuration

The following environment variables can be set:

endpoint:
kafka.topic: hl7-topic
hl7:
port: 2575
encoding: iso-8859-1

| Variable | Default | Description |
|--------------------------|----------------|----------------------------------------------------------------|
| BOOTSTRAP_SERVERS | localhost:9092 | Kafka brokers |
| SECURITY_PROTOCOL | PLAINTEXT | Kafka communication protocol |
| SSL_TRUST_STORE_PASSWORD | | Truststore password (if using `SECURITY_PROTOCOL=SSL`) |
| SSL_KEY_STORE_PASSWORD | | Keystore password (if using `SECURITY_PROTOCOL=SSL`) |
| SSL_TRUST_STORE_PASSWORD | | Truststore password (if using `SECURITY_PROTOCOL=SSL`) |
| ENDPOINT_KAFKA_TOPIC | hl7-topic | Kafka output topic to send HL7 messages to |
| ENDPOINT_HL7_PORT | 2575 | HL7 MLLP listener port |
| ENDPOINT_HL7_ENCODING | iso-8859-1 | Default encoding to use if not specified in the message header |
| LOG_LEVEL | info | Log level (error, warn, info, debug) |

Additional application properties can be set by overriding values form the [application.yaml](src/main/resources/application.yaml) by using environment variables.

## Error handling

> TODO

## Development

A [test setup](dev/compose.yaml) and a [script](dev/send-hl7.sh) to send an example
message is available for development purposes.

### Builds

Available image tags can be found at the [Container Registry](https://github.com/orgs/diz-unimr/packages?repo_name=hl7-to-kafka) or under
[Releases](https://github.com/diz-unimr/hl7-to-kafka/releases).

## License

[AGPL-3.0](https://www.gnu.org/licenses/agpl-3.0.en.html)
10 changes: 5 additions & 5 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# the name of Camel
camel:
main.name: HL7 to Kafka
springboot.name: hl7-to-kafka
component:
kafka:
brokers: localhost:9092
ssl-endpoint-algorithm: PLAINTEXT
ssl-truststore-password:
ssl-keystore-password:
brokers: ${BOOTSTRAP_SERVERS:localhost:9092}
ssl-endpoint-algorithm: ${SECURITY_PROTOCOL:PLAINTEXT}
ssl-truststore-password: ${SSL_TRUST_STORE_PASSWORD}
ssl-keystore-password: ${SSL_KEY_STORE_PASSWORD}

endpoint:
kafka.topic: hl7-topic
Expand Down

0 comments on commit dd54a52

Please sign in to comment.