Skip to content

Commit

Permalink
feat: use avro by default and fallback on string on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewinci committed Oct 11, 2022
1 parent 63427b7 commit 9603e2d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
14 changes: 13 additions & 1 deletion src-tauri/src/api/consumer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use log::warn;

use super::{ error::Result, AppState };
use crate::lib::{ ConsumerOffsetConfiguration, ConsumerState, ParserMode, ParsedKafkaRecord };

Expand Down Expand Up @@ -38,7 +40,17 @@ pub async fn get_record(
let cluster = state.get_cluster_by_id(&cluster_id).await;
let consumer = cluster.get_consumer(&topic).await;
match consumer.get_record(index).await {
Some(r) => Ok(Some(cluster.parser.parse_record(r, ParserMode::Avro).await?)),
Some(r) => {
let avro_record = cluster.parser.parse_record(r.clone(), ParserMode::Avro).await;
let parsed = match avro_record {
Ok(res) => res,
Err(_) => {
warn!("Unable to parse record with avro. Topic: {} Index : {}", topic, index);
cluster.parser.parse_record(r, ParserMode::String).await?
}
};
Ok(Some(parsed))
}
None => Ok(None),
}
}
8 changes: 0 additions & 8 deletions src/pages/topics/consumer-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const ModalBody = ({ cluster, topicName }: ConsumerModalProps) => {
const form = useForm<ConsumerForm>({
initialValues: {
from: "End",
useAvro: cluster.schemaRegistry ? true : false,
dateInterval: [nowUTC, nowUTC],
onlyBeginning: false,
timeInterval: [zeroUTC, zeroUTC],
Expand Down Expand Up @@ -76,12 +75,6 @@ const ModalBody = ({ cluster, topicName }: ConsumerModalProps) => {
</Text>
</Stack>
<Divider />
<Checkbox
disabled={cluster.schemaRegistry === undefined}
label="Use Avro (with schema registry)"
{...form.getInputProps("useAvro", { type: "checkbox" })}
/>
<Divider />
<Title size={15}>Start consuming from</Title>
<Chip.Group position="left" multiple={false} {...form.getInputProps("from")}>
<Chip value="End">End</Chip>
Expand Down Expand Up @@ -121,7 +114,6 @@ export const dateTimeToUnixTimeMs = (dateUTC: Date, timeUTC: Date): number => {

type ConsumerForm = {
from: "Beginning" | "End" | "Custom";
useAvro: boolean;
dateInterval: [Date, Date];
timeInterval: [Date, Date];
onlyBeginning: boolean;
Expand Down

0 comments on commit 9603e2d

Please sign in to comment.