I wanted to get an opinion on how to properly implement this and if this is the right approach to doing so. So I have created a fully reactive application using reactive-messaging but have come to know that I have an overarching constraint - and that constraint being Oracle. As you know, JDBC is inherently blocking in nature and cannot really be executed asynchronously. I am trying to figure out a way to achieve this so that the event loop thread does not get blocked and so far the only thing that seems to work is something like this:
@Incoming(KAFKA_DATA)
@Blocking
@Acknowledgment(Acknowledgment.Strategy.MANUAL)
fun consume(record: Message<Notification>): CompletionStage<Void> {
val metadata = record.getMetadata(IncomingKafkaRecordMetadata::class.java).orElse(null)
if (metadata != null) {
log.debug(
"Received Kafka Record - " +
"topic: {}, " +
"partition: {}, " +
"offset: {}, " +
"payload: {}",
metadata.topic, metadata.partition, metadata.offset, record.payload
)
}
return Uni.createFrom().voidItem()
.invoke { -> invokeBlockingCall(record.payload) }
.call { -> handleSuccess(record) }
.onFailure().call { failure -> handleFailure(failure, record) }
.runSubscriptionOn(Infrastructure.getDefaultExecutor())
.subscribeAsCompletionStage()
}
I have managed to get that working as-is but I am unsure if it is the correct/efficient way of doing so. Does anyone have any suggestions on how to achieve such a task? Any suggestions are greatly appreciated and taken into account, thanks!