MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / poll_stream

Function poll_stream

nodedb/src/control/server/http/routes/stream_poll.rs:58–155  ·  view source on GitHub ↗

`GET /v1/streams/{stream}/poll`

(
    identity: ResolvedIdentity,
    Path(stream_name): Path<String>,
    Query(params): Query<PollParams>,
    State(state): State<AppState>,
)

Source from the content-addressed store, hash-verified

56
57/// `GET /v1/streams/{stream}/poll`
58pub async fn poll_stream(
59 identity: ResolvedIdentity,
60 Path(stream_name): Path<String>,
61 Query(params): Query<PollParams>,
62 State(state): State<AppState>,
63) -> impl IntoResponse {
64 // Reject any attempt to override the caller's tenant via query string.
65 if params.tenant_id.is_some() {
66 return (
67 StatusCode::FORBIDDEN,
68 Json(serde_json::json!({
69 "error": "tenant_id must not be supplied as a query parameter; \
70 tenant is determined from the bearer token"
71 })),
72 )
73 .into_response();
74 }
75
76 let group = match params.group {
77 Some(g) => g.to_lowercase(),
78 None => {
79 return (
80 StatusCode::BAD_REQUEST,
81 Json(serde_json::json!({"error": "missing 'group' query parameter"})),
82 )
83 .into_response();
84 }
85 };
86
87 let tenant_id = identity.tenant_id().as_u64();
88 let limit = params.limit.unwrap_or(100).min(10_000);
89 let stream_name = stream_name.to_lowercase();
90
91 let consume_params = ConsumeParams {
92 tenant_id,
93 stream_name: &stream_name,
94 group_name: &group,
95 partition: params.partition,
96 limit,
97 };
98
99 let result = match consume_stream(&state.shared, &consume_params) {
100 Ok(r) => r,
101 Err(ConsumeError::RemotePartition { leader_node, .. }) => {
102 // Forward to remote node.
103 match crate::event::cdc::consume::consume_remote(
104 &state.shared,
105 &consume_params,
106 leader_node,
107 )
108 .await
109 {
110 Ok(r) => r,
111 Err(e) => {
112 return (
113 StatusCode::BAD_GATEWAY,
114 Json(serde_json::json!({"error": e.to_string()})),
115 )

Callers

nothing calls this directly

Calls 9

consume_streamFunction · 0.85
consume_remoteFunction · 0.85
into_responseMethod · 0.80
collectMethod · 0.80
to_stringMethod · 0.80
as_u64Method · 0.45
tenant_idMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected