Skip to content

Commit

Permalink
[TH2-2212] mq subscriptions recovery (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
lumber1000 authored Sep 13, 2024
1 parent e7fad5e commit aa991da
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 102 deletions.
14 changes: 0 additions & 14 deletions .github/dependabot.yml

This file was deleted.

15 changes: 15 additions & 0 deletions .github/workflows/build-dev-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Build and publish dev release Docker image to Github Container Registry ghcr.io

on: workflow_dispatch

jobs:
build:
uses: th2-net/.github/.github/workflows/compound-java.yml@main
with:
build-target: 'Docker'
devRelease: true
createTag: true
docker-username: ${{ github.actor }}
secrets:
docker-password: ${{ secrets.GITHUB_TOKEN }}
nvd-api-key: ${{ secrets.NVD_APIKEY }}
15 changes: 15 additions & 0 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Build and publish release Docker image to Github Container Registry ghcr.io

on: workflow_dispatch

jobs:
build:
uses: th2-net/.github/.github/workflows/compound-java.yml@main
with:
build-target: 'Docker'
devRelease: false
createTag: true
docker-username: ${{ github.actor }}
secrets:
docker-password: ${{ secrets.GITHUB_TOKEN }}
nvd-api-key: ${{ secrets.NVD_APIKEY }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Dev build and publish Docker distributions to Github Container Registry ghcr.io
name: Build and publish Docker image to Github Container Registry ghcr.io

on:
push:
Expand All @@ -17,5 +17,4 @@ jobs:
docker-username: ${{ github.actor }}
secrets:
docker-password: ${{ secrets.GITHUB_TOKEN }}
owasp-scan:
uses: th2-net/.github/.github/workflows/owasp-gradle-scan.yml@main
nvd-api-key: ${{ secrets.NVD_APIKEY }}
8 changes: 4 additions & 4 deletions .github/workflows/ci-unwelcome-words.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ on:

jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- name: Checkout tool
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
repository: exactpro-th2/ci-github-action
ref: master
Expand All @@ -20,4 +20,4 @@ jobs:
- name: Run CI action
uses: ./ci-github-action
with:
ref: ${{ github.sha }}
ref: ${{ github.sha }}
20 changes: 0 additions & 20 deletions .github/workflows/dependabot-java-build.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .github/workflows/docker-publish.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM gradle:7.6-jdk11 AS build
FROM gradle:8.7-jdk11 AS build
ARG release_version
COPY ./ .
RUN gradle --no-daemon clean build dockerPrepare -Prelease_version=${release_version}
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# KafkaConnect (0.3.0)
# KafkaConnect (0.4.0)
The "KafkaConnect" component is responsible for the communication with Kafka;

## Configuration
Expand Down Expand Up @@ -97,7 +97,7 @@ protobuf
```yaml
spec:
imageName: ghcr.io/th2-net/th2-conn-kafka
imageVersion: 0.3.0
imageVersion: 0.4.0
type: th2-conn
customConfig:
useTransport: false
Expand Down Expand Up @@ -139,6 +139,12 @@ spec:

## Release notes

### 0.4.0
+ Migrated to th2 gradle plugin `0.1.2` (bom: `4.7.0`)
+ Updated common: `5.14.0-dev`
+ Updated common-utils `2.3.0-dev`
+ Updated workflows

### 0.3.0
+ TH2 transport protocol support
Updated bom: `4.5.0`
Expand Down
57 changes: 35 additions & 22 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,34 +1,47 @@
buildscript {
repositories {
gradlePluginPortal()
maven {
url = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
}
plugins {
id "org.jetbrains.kotlin.jvm" version "$kotlin_version"
id "application"
id "com.exactpro.th2.gradle.component" version "0.1.2"
}

group = 'com.exactpro.th2'
version = release_version

kotlin.jvmToolchain(11)

repositories {
maven {
name 'Sonatype_snapshots'
url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
}
dependencies {
classpath "com.exactpro.th2:th2-gradle-plugin:0.0.1-dev-5915772757-13a28ae-SNAPSHOT"

maven {
name 'Sonatype_releases'
url 'https://s01.oss.sonatype.org/content/repositories/releases/'
}
}

apply plugin: "com.exactpro.th2.common-conventions"
apply plugin: "com.exactpro.th2.docker-conventions"
mavenCentral()

configurations.configureEach {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
resolutionStrategy.cacheDynamicVersionsFor 0, 'seconds'
}
}

dependencies {
api platform("com.exactpro.th2:bom:4.5.0")
implementation "com.exactpro.th2:common:5.4.0-dev"
implementation "com.exactpro.th2:common-utils:2.2.0-dev"
implementation "com.exactpro.th2:common:5.14.0-dev"
implementation "com.exactpro.th2:common-utils:2.3.0-dev"

implementation "org.apache.kafka:kafka-clients:3.5.1"
implementation "io.github.oshai:kotlin-logging:5.1.4"

implementation "org.apache.kafka:kafka-clients:3.8.0"
implementation 'com.fasterxml.jackson.core:jackson-databind'

testImplementation "org.jetbrains.kotlin:kotlin-test-junit5"
testImplementation "org.mockito.kotlin:mockito-kotlin:5.0.0"
testImplementation "org.mockito.kotlin:mockito-kotlin:5.4.0"
testImplementation "org.mockito:mockito-inline:5.2.0"
testImplementation "org.assertj:assertj-core:3.24.2"
testImplementation "org.assertj:assertj-core:3.26.3"
}

configurations {
compileClasspath {
resolutionStrategy.activateDependencyLocking()
}
}
test.useJUnitPlatform()
application.mainClass = "com.exactpro.th2.kafka.client.Main"
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kotlin.code.style=official
release_version = 0.3.0
release_version = 0.4.0
kotlin_version=1.8.22
description='Kafka Client'
vcs_url=https://github.com/th2-net/th2-conn-kafka
app_main_class=com.exactpro.th2.kafka.client.Main
vcs_url=https://github.com/th2-net/th2-conn-kafka
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021-2023 Exactpro (Exactpro Systems Limited)
# Copyright 2021-2024 Exactpro (Exactpro Systems Limited)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
# limitations under the License.
#

distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Expand Down
14 changes: 7 additions & 7 deletions src/main/kotlin/com/exactpro/th2/kafka/client/KafkaConnection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.exactpro.th2.common.utils.message.logId
import com.exactpro.th2.common.utils.message.transport.logId
import com.exactpro.th2.common.utils.message.transport.toProto
import com.google.protobuf.UnsafeByteOperations
import mu.KotlinLogging
import io.github.oshai.kotlinlogging.KotlinLogging
import org.apache.kafka.clients.admin.AdminClient
import org.apache.kafka.clients.admin.AdminClientConfig
import org.apache.kafka.clients.admin.NewTopic
Expand Down Expand Up @@ -85,7 +85,7 @@ abstract class KafkaConnection<MESSAGE, MESSAGE_BUILDER>(
val (outMessage, sessionGroup) = messageFuture.get()
if (exception == null) {
val msgText = "Message '${outMessage.logId}' sent to Kafka"
LOGGER.info(msgText)
LOGGER.info { msgText }
if (config.messagePublishingEvents) {
eventSender.onEvent(msgText, "Send message", outMessage.toProtoMessageId(sessionGroup))
}
Expand Down Expand Up @@ -147,7 +147,7 @@ abstract class KafkaConnection<MESSAGE, MESSAGE_BUILDER>(
if (records.isEmpty) {
if (config.kafkaConnectionEvents && !isKafkaAvailable()) {
val failedToConnectMessage = "Failed to connect Kafka"
LOGGER.error(failedToConnectMessage)
LOGGER.error { failedToConnectMessage }
eventSender.onEvent(failedToConnectMessage, CONNECTIVITY_EVENT_TYPE, status = Event.Status.FAILED)

while (!Thread.currentThread().isInterrupted && !isKafkaAvailable()) {
Expand All @@ -156,7 +156,7 @@ abstract class KafkaConnection<MESSAGE, MESSAGE_BUILDER>(

if (!Thread.currentThread().isInterrupted) {
val connectionRestoredMessage = "Kafka connection restored"
LOGGER.info(connectionRestoredMessage)
LOGGER.info { connectionRestoredMessage }
eventSender.onEvent(connectionRestoredMessage, CONNECTIVITY_EVENT_TYPE)
}
}
Expand Down Expand Up @@ -219,12 +219,12 @@ abstract class KafkaConnection<MESSAGE, MESSAGE_BUILDER>(
}
}
} catch (e: InterruptedException) {
LOGGER.info("Polling thread interrupted")
LOGGER.info { "Polling thread interrupted" }
} catch (e: InterruptException) {
LOGGER.info("Polling thread interrupted")
LOGGER.info { "Polling thread interrupted" }
} catch (e: Exception) {
val errorMessage = "Failed to read messages from Kafka"
LOGGER.error(errorMessage, e)
LOGGER.error(e) { errorMessage }
eventSender.onEvent(errorMessage, "Error", exception = e)
} finally {
Thread.interrupted()
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/exactpro/th2/kafka/client/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import com.exactpro.th2.common.utils.message.logId
import com.exactpro.th2.common.utils.message.transport.logId
import com.exactpro.th2.common.utils.message.transport.toProto
import com.exactpro.th2.common.utils.shutdownGracefully
import mu.KotlinLogging
import io.github.oshai.kotlinlogging.KotlinLogging
import java.util.Deque
import java.util.concurrent.ConcurrentLinkedDeque
import java.util.concurrent.CountDownLatch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.exactpro.th2.common.utils.message.id
import com.exactpro.th2.common.utils.message.logId
import com.exactpro.th2.common.utils.message.toTimestamp
import com.exactpro.th2.common.utils.message.transport.logId
import mu.KotlinLogging
import io.github.oshai.kotlinlogging.KotlinLogging
import java.time.Instant
import java.util.concurrent.Executors
import java.util.concurrent.Future
Expand Down

0 comments on commit aa991da

Please sign in to comment.