-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Resolve Issues in RestKafkaSender and SchemaRetriever #180
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.radarbase.producer.rest | ||
|
||
import java.lang.reflect.ParameterizedType | ||
import java.lang.reflect.Type | ||
|
||
class RadarParameterizedType( | ||
private val raw: Class<*>, | ||
private val args: Array<Type>, | ||
private val owner: Type? = null, | ||
) : ParameterizedType { | ||
override fun getRawType(): Type = raw | ||
override fun getActualTypeArguments(): Array<Type> = args | ||
override fun getOwnerType(): Type? = owner | ||
|
||
override fun toString(): String { | ||
return buildString { | ||
append(raw.typeName) | ||
if (args.isNotEmpty()) { | ||
append('<') | ||
append(args.joinToString(", ") { it.typeName }) | ||
append('>') | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,8 +61,6 @@ import org.radarbase.topic.AvroTopic | |
import org.radarbase.util.RadarProducerDsl | ||
import org.slf4j.LoggerFactory | ||
import java.io.IOException | ||
import kotlin.reflect.javaType | ||
import kotlin.reflect.typeOf | ||
import kotlin.time.Duration | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
|
@@ -143,6 +141,16 @@ class RestKafkaSender(config: Config) : KafkaSender { | |
inner class RestKafkaTopicSender<K : Any, V : Any>( | ||
override val topic: AvroTopic<K, V>, | ||
) : KafkaTopicSender<K, V> { | ||
|
||
val recordDataTypeInfo: TypeInfo = TypeInfo( | ||
type = RecordData::class, | ||
kotlinType = null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not define the ktype as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I attempted to define kotlinType using the following approaches:
Here are the results:
When trying:
I encountered similar errors with:
I am uncertain if this approach is optimal. I would appreciate any suggestions for improvements or more efficient alternatives. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also from the TypeInfo class, kotlinType is null by default, unlike other properties:
|
||
reifiedType = RadarParameterizedType( | ||
raw = RecordData::class.java, | ||
args = arrayOf(topic.keyClass, topic.valueClass), | ||
), | ||
) | ||
|
||
override suspend fun send(records: RecordData<K, V>) = withContext(scope.coroutineContext) { | ||
try { | ||
val response: HttpResponse = restClient.post { | ||
|
@@ -275,22 +283,13 @@ class RestKafkaSender(config: Config) : KafkaSender { | |
|
||
companion object { | ||
private val logger = LoggerFactory.getLogger(RestKafkaSender::class.java) | ||
private val recordDataTypeInfo: TypeInfo | ||
|
||
val DEFAULT_TIMEOUT: Duration = 20.seconds | ||
val KAFKA_REST_BINARY_ENCODING = ContentType("application", "vnd.radarbase.avro.v1+binary") | ||
val KAFKA_REST_JSON_ENCODING = ContentType("application", "vnd.kafka.avro.v2+json") | ||
val KAFKA_REST_ACCEPT = ContentType("application", "vnd.kafka.v2+json") | ||
const val GZIP_CONTENT_ENCODING = "gzip" | ||
|
||
init { | ||
val kType = typeOf<RecordData<Any, Any>>() | ||
|
||
@OptIn(ExperimentalStdlibApi::class) | ||
val reifiedType = kType.javaType | ||
recordDataTypeInfo = TypeInfo(RecordData::class, reifiedType, kType) | ||
} | ||
|
||
fun restKafkaSender(builder: Config.() -> Unit): RestKafkaSender = | ||
RestKafkaSender(Config().apply(builder)) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The POST issue is likely due to a bug here- https://github.com/RADAR-base/radar-commons/blame/4d2044f5a1ec7f7b6b8f4fa1d6433144e7501bac/radar-commons/src/main/java/org/radarbase/producer/schema/SchemaRestClient.kt#L122, this should be calling
schemaGet
, notschemaPost
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we update it to a GET request, we should fetch the schemas by version or ID. We don't have either of these at the moment. Should I proceed with "latest", which will fetch the latest version?