Commit 8588e33a authored by GuanLuo's avatar GuanLuo Committed by GitHub
Browse files

feat: Add KV publisher and receiver. Add KV aware routing example.


Signed-off-by: default avatarNeelay Shah <neelays@nvidia.com>
Co-authored-by: default avataraflowers <aflowers@nvidia.com>
Co-authored-by: default avatarRyan McCormick <rmccormick@nvidia.com>
Co-authored-by: default avatarhongkuanz <hongkuanz@nvidia.com>
Co-authored-by: default avatarNeelay Shah <neelays@nvidia.com>
parent d8aada0b
......@@ -31,13 +31,16 @@
use crate::Result;
use async_nats::{client, jetstream, Subscriber};
use bytes::Bytes;
use derive_builder::Builder;
use futures::TryStreamExt;
use futures::{StreamExt, TryStreamExt};
use std::path::PathBuf;
use tokio::time;
use validator::{Validate, ValidationError};
mod slug;
pub use slug::Slug;
use tracing as log;
#[derive(Clone)]
pub struct Client {
......@@ -113,6 +116,35 @@ impl Client {
Ok(subscription)
}
// todo - deprecate - move to service subscriber
pub async fn get_endpoints(
&self,
service_name: &str,
timeout: time::Duration,
) -> Result<Vec<Bytes>, anyhow::Error> {
let subject = format!("$SRV.STATS.{}", service_name);
let reply_subject = format!("_INBOX.{}", nuid::next());
let mut subscription = self.client.subscribe(reply_subject.clone()).await?;
let deadline = tokio::time::Instant::now() + timeout;
// Publish the request with the reply-to subject
self.client
.publish_with_reply(subject, reply_subject, "".into())
.await?;
// Set a timeout to gather responses
let mut responses = Vec::new();
// let mut response_stream = subscription.take_while(|_| futures::future::ready(true));
while let Ok(Some(message)) = time::timeout_at(deadline, subscription.next()).await {
// log::debug!("get endpoint received message before timeout: {:?}", message);
responses.push(message.payload);
}
Ok(responses)
}
// /// create a new stream
// async fn get_or_create_work_queue_stream(
// &self,
......
......@@ -56,6 +56,7 @@ pub const DEFAULT_GRACEFUL_SHUTDOWN_TIMEOUT_DEBUG: u64 = 5;
/// Default graceful shutdown timeout in seconds in release mode
pub const DEFAULT_GRACEFUL_SHUTDOWN_TIMEOUT_RELEASE: u64 = 30;
#[derive(Debug, Clone)]
pub struct Worker {
runtime: Runtime,
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment