-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(engine): implement NoopPubSub backend and refactor CloudPubSub i…
…ntegration (#690)
- Loading branch information
Showing
6 changed files
with
120 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,43 @@ | ||
pub(crate) mod google_pubsub; | ||
use google_cloud_pubsub::client::{Client, ClientConfig}; | ||
|
||
pub(crate) mod google; | ||
pub(crate) mod noop; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub(crate) enum PubSubBackendError { | ||
#[error("Failed to try from : {0}")] | ||
TryFrom(String), | ||
#[error("Failed to create : {0}")] | ||
Create(String), | ||
} | ||
|
||
impl PubSubBackendError { | ||
pub(crate) fn create<T: ToString>(message: T) -> Self { | ||
Self::Create(message.to_string()) | ||
} | ||
} | ||
|
||
pub(crate) enum PubSubBackend { | ||
Google(google::CloudPubSub), | ||
Noop(noop::NoopPubSub), | ||
} | ||
|
||
impl PubSubBackend { | ||
pub(crate) async fn try_from(value: &str) -> Result<Self, PubSubBackendError> { | ||
let value = value.to_lowercase(); | ||
match value.as_str() { | ||
"google" => { | ||
let config = ClientConfig::default() | ||
.with_auth() | ||
.await | ||
.map_err(PubSubBackendError::create)?; | ||
let client = Client::new(config) | ||
.await | ||
.map_err(PubSubBackendError::create)?; | ||
Ok(Self::Google(google::CloudPubSub::new(client))) | ||
} | ||
"noop" => Ok(Self::Noop(noop::NoopPubSub {})), | ||
_ => Err(PubSubBackendError::TryFrom(value)), | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use crate::pubsub::message::EncodableMessage; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum NoopPubSubError {} | ||
|
||
pub struct NoopPubSub {} | ||
|
||
#[async_trait::async_trait] | ||
impl crate::pubsub::publisher::Publisher for NoopPubSub { | ||
type Error = NoopPubSubError; | ||
|
||
async fn publish<M: EncodableMessage>(&self, _message: M) -> Result<(), Self::Error> { | ||
Ok(()) | ||
} | ||
|
||
async fn shutdown(&self) {} | ||
} |