Skip to content

Commit 1eb19f1

Browse files
authored
chore: export health check API (#92)
1 parent 6c651d8 commit 1eb19f1

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/hstreamdb/src/client.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use common::{Stream, Subscription};
22
use hstreamdb_pb::h_stream_api_client::HStreamApiClient;
33
use hstreamdb_pb::{
4-
CompressionType, DeleteStreamRequest, DeleteSubscriptionRequest, GetStreamRequest,
4+
CompressionType, DeleteStreamRequest, DeleteSubscriptionRequest, EchoRequest, GetStreamRequest,
55
GetSubscriptionRequest, ListConsumersRequest, ListStreamsRequest, ListSubscriptionsRequest,
66
LookupSubscriptionRequest, NodeState,
77
};
@@ -111,6 +111,20 @@ pub(crate) async fn get_available_node_addrs(
111111
Ok(cluster_addrs)
112112
}
113113

114+
impl Client {
115+
pub async fn echo<T: Into<String>>(&self, msg: T) -> common::Result<String> {
116+
let msg = self
117+
.channels
118+
.channel()
119+
.await
120+
.echo(EchoRequest { msg: msg.into() })
121+
.await?
122+
.into_inner()
123+
.msg;
124+
Ok(msg)
125+
}
126+
}
127+
114128
impl Client {
115129
pub async fn create_stream(&self, stream: Stream) -> common::Result<Stream> {
116130
let stream = self.channels.channel().await.create_stream(stream).await?;

src/x/hstreamdb-erl-nifs/src/lib.rs

+17
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ rustler::atoms! {
3030
max_batch_len, max_batch_size, batch_deadline,
3131
on_flush,
3232
start_client_reply,
33+
echo_reply,
3334
create_stream_reply,
3435
create_subscription_reply,
3536
earliest, latest,
@@ -48,6 +49,7 @@ rustler::init!(
4849
"hstreamdb",
4950
[
5051
async_start_client,
52+
async_echo,
5153
async_create_stream,
5254
async_create_subscription,
5355
async_start_producer,
@@ -206,6 +208,21 @@ fn from_start_client_options(proplists: Term) -> hstreamdb::Result<ChannelProvid
206208
Ok(channel_provider_settings.build())
207209
}
208210

211+
#[rustler::nif]
212+
fn async_echo(pid: LocalPid, client: ResourceArc<NifClient>, msg: String) {
213+
let future = async move {
214+
let client = &client.0;
215+
let mut env = OwnedEnv::new();
216+
match client.echo(msg).await {
217+
Ok(msg) => env.send_and_clear(&pid, |env| (echo_reply(), ok(), msg).encode(env)),
218+
Err(err) => env.send_and_clear(&pid, |env| {
219+
(echo_reply(), error(), err.to_string()).encode(env)
220+
}),
221+
}
222+
};
223+
runtime::spawn(future);
224+
}
225+
209226
#[rustler::nif]
210227
fn async_create_stream(
211228
pid: LocalPid,

0 commit comments

Comments
 (0)