`GET /v1/streams/{stream}/poll`
(
identity: ResolvedIdentity,
Path(stream_name): Path<String>,
Query(params): Query<PollParams>,
State(state): State<AppState>,
)
| 56 | |
| 57 | /// `GET /v1/streams/{stream}/poll` |
| 58 | pub 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 | ) |
nothing calls this directly
no test coverage detected