MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / start

Method start

chirpstack-integration/src/lib.rs:160–279  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

158 }
159
160 async fn start(&self) -> Result<()> {
161 info!("Getting Redis connection");
162 let mut redis_conn = self.redis_client.get_async_connection().await?;
163
164 let key = format!("{}device:stream:event", self.key_prefix);
165
166 // Try to create the consumer group. This will fail in case the consumer group already exists.
167 let _: usize = match redis::cmd("XGROUP")
168 .arg("CREATE")
169 .arg(&key)
170 .arg(&self.consumer_group)
171 .arg(0)
172 .arg("MKSTREAM")
173 .query_async(&mut redis_conn)
174 .await
175 {
176 Ok(v) => v,
177 Err(e) => {
178 warn!(error = %e, "Could not create Redis consumer group, ignore this error if the group already exists");
179 0
180 }
181 };
182
183 loop {
184 let srr: redis::streams::StreamReadReply = redis::cmd("XREADGROUP")
185 .arg("GROUP")
186 .arg(&self.consumer_group)
187 .arg(&self.consumer_name)
188 .arg("COUNT")
189 .arg(10)
190 .arg("BLOCK")
191 .arg(1000)
192 .arg("STREAMS")
193 .arg(&key)
194 .arg(">")
195 .query_async(&mut redis_conn)
196 .await?;
197
198 for stream_key in &srr.keys {
199 for stream_id in &stream_key.ids {
200 let _: () = redis::cmd("XACK")
201 .arg(&key)
202 .arg(&self.consumer_group)
203 .arg(&stream_id.id)
204 .query_async(&mut redis_conn)
205 .await?;
206
207 for (k, v) in &stream_id.map {
208 let res = || -> Result<()> {
209 info!(key = %k, "Event received from Redis stream");
210 match k.as_ref() {
211 "up" => {
212 if let redis::Value::BulkString(b) = v {
213 let pl = integration_pb::UplinkEvent::decode(
214 &mut Cursor::new(b),
215 )?;
216 tokio::spawn(uplink_event(pl));
217 }

Callers 1

startFunction · 0.80

Calls 10

get_async_connectionMethod · 0.80
as_refMethod · 0.80
uplink_eventFunction · 0.70
join_eventFunction · 0.70
ack_eventFunction · 0.70
txack_eventFunction · 0.70
status_eventFunction · 0.70
log_eventFunction · 0.70
location_eventFunction · 0.70
decodeFunction · 0.50

Tested by

no test coverage detected