Skip to content
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

WIP: poller consumer support in libs and bridge #1765

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 126 additions & 28 deletions bridge/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions bridge/svix-bridge-plugin-kafka/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ use rdkafka::{
Message as _,
};
use svix_bridge_types::{
async_trait, svix::api::Svix, CreateMessageRequest, JsObject, SenderInput, SenderOutputOpts,
TransformationConfig, TransformerInput, TransformerInputFormat, TransformerJob,
TransformerOutput, TransformerTx,
async_trait,
svix::api::{MessageCreateOptions, Svix},
CreateMessageRequest, JsObject, SenderInput, SenderOutputOpts, TransformationConfig,
TransformerInput, TransformerInputFormat, TransformerJob, TransformerOutput, TransformerTx,
};
use tokio::task::spawn_blocking;

Expand Down Expand Up @@ -69,27 +70,26 @@ impl KafkaConsumer {
serde_json::from_slice(payload).map_err(Error::Deserialization)?
};

let CreateMessageRequest {
app_id,
message,
mut post_options,
} = payload;
let CreateMessageRequest { app_id, message } = payload;

let KafkaInputOpts::Inner {
group_id, topic, ..
} = &self.opts;

// If committing the message fails or the process crashes after posting the webhook but
// before committing, this makes sure that the next run of this fn with the same kafka
// message doesn't end up creating a duplicate webhook in svix.
let idempotency_key = format!("svix_bridge_kafka_{group_id}_{topic}_{}", msg.offset());
post_options
.get_or_insert_with(Default::default)
.idempotency_key = Some(idempotency_key);
let options = MessageCreateOptions {
with_content: None,
// If committing the message fails or the process crashes after posting the webhook but
// before committing, this makes sure that the next run of this fn with the same kafka
// message doesn't end up creating a duplicate webhook in svix.
idempotency_key: Some(format!(
"svix_bridge_kafka_{group_id}_{topic}_{}",
msg.offset()
)),
};

self.svix_client
.message()
.create(app_id, message, post_options.map(Into::into))
.create(app_id, message, Some(options))
.await?;

Ok(())
Expand Down
Loading
Loading