|
1 | 1 | use anyhow::{anyhow, Error}; |
2 | 2 | use futures::{ |
| 3 | + executor::block_on, |
3 | 4 | future::{self}, |
4 | 5 | pin_mut, Stream, StreamExt, |
5 | 6 | }; |
@@ -30,7 +31,7 @@ use tokio::{ |
30 | 31 | mpsc::{self, unbounded_channel, UnboundedReceiver, UnboundedSender}, |
31 | 32 | oneshot, |
32 | 33 | }, |
33 | | - task::JoinSet, |
| 34 | + task::{spawn_blocking, JoinSet}, |
34 | 35 | time::{self, sleep, MissedTickBehavior}, |
35 | 36 | }; |
36 | 37 | use tokio_stream::wrappers::UnboundedReceiverStream; |
@@ -84,18 +85,20 @@ pub fn handle_consumer_client( |
84 | 85 | consumer: Arc<StreamConsumer<KafkaContext>>, |
85 | 86 | shutdown: oneshot::Receiver<()>, |
86 | 87 | ) { |
87 | | - tokio::spawn(async move { |
88 | | - select! { |
89 | | - biased; |
90 | | - _ = shutdown => { |
91 | | - debug!("Received shutdown signal, commiting state in sync mode..."); |
92 | | - let _ = consumer.commit_consumer_state(rdkafka::consumer::CommitMode::Sync); |
93 | | - } |
94 | | - msg = consumer.recv() => { |
95 | | - error!("Got unexpected message from consumer client: {:?}", msg); |
| 88 | + spawn_blocking(|| { |
| 89 | + block_on(async move { |
| 90 | + select! { |
| 91 | + biased; |
| 92 | + _ = shutdown => { |
| 93 | + debug!("Received shutdown signal, commiting state in sync mode..."); |
| 94 | + let _ = consumer.commit_consumer_state(rdkafka::consumer::CommitMode::Sync); |
| 95 | + } |
| 96 | + msg = consumer.recv() => { |
| 97 | + error!("Got unexpected message from consumer client: {:?}", msg); |
| 98 | + } |
96 | 99 | } |
97 | | - } |
98 | | - debug!("Shutdown complete"); |
| 100 | + debug!("Shutdown complete"); |
| 101 | + }) |
99 | 102 | }); |
100 | 103 | } |
101 | 104 |
|
|
0 commit comments