@@ -11,7 +11,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
11
11
use rabbitmq_stream_client:: Environment ;
12
12
let environment = Environment :: builder ( ) . build ( ) . await ?;
13
13
let stream = "stream-offset-tracking-rust" ;
14
- let received_messages = Arc :: new ( AtomicI64 :: new ( -1 ) ) ;
15
14
let first_offset = Arc :: new ( AtomicI64 :: new ( -1 ) ) ;
16
15
let last_offset = Arc :: new ( AtomicI64 :: new ( -1 ) ) ;
17
16
let notify_on_close = Arc :: new ( Notify :: new ( ) ) ;
@@ -46,7 +45,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
46
45
47
46
let mut stored_offset: u64 = consumer. query_offset ( ) . await . unwrap_or_else ( |_| 0 ) ;
48
47
49
- if stored_offset > 0 {
48
+ if stored_offset > 0 {
50
49
stored_offset += 1 ;
51
50
}
52
51
consumer = environment
@@ -62,6 +61,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
62
61
let notify_on_close_cloned = notify_on_close. clone ( ) ;
63
62
64
63
task:: spawn ( async move {
64
+ let mut received_messages = -1 ;
65
65
while let Some ( delivery) = consumer. next ( ) . await {
66
66
let d = delivery. unwrap ( ) ;
67
67
@@ -74,8 +74,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
74
74
Ordering :: Relaxed ,
75
75
) ;
76
76
}
77
-
78
- if received_messages. fetch_add ( 1 , Ordering :: Relaxed ) % 10 == 0
77
+ received_messages = received_messages + 1 ;
78
+ if received_messages % 10 == 0
79
79
|| String :: from_utf8_lossy ( d. message ( ) . data ( ) . unwrap ( ) ) . contains ( "marker" )
80
80
{
81
81
let _ = consumer
@@ -87,7 +87,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
87
87
let handle = consumer. handle ( ) ;
88
88
_ = handle. close ( ) . await ;
89
89
notify_on_close_cloned. notify_one ( ) ;
90
-
91
90
}
92
91
}
93
92
}
0 commit comments