Comments (3)
Interesting, so if i break it up as:
loop {
let cp = consumer.poll().unwrap();
for ms in cp.iter() {
...
it gets rather unhappy with me, staying
error[E0597]: `cp` does not live long enough
--> src/main.rs:176:19
|
176 | for ms in cp.iter() {
| ^^-------
| |
| borrowed value does not live long enough
| argument requires that `cp` is borrowed for `'static`
...
203 | }
| - `cp` dropped here while still borrowed
whereas borrowing cp
gives me:
error[E0277]: `&MessageSetsIter<'_>` is not an iterator
--> src/main.rs:176:19
|
176 | for ms in &cp.iter() {
| -^^^^^^^^^
| |
| `&MessageSetsIter<'_>` is not an iterator
| help: consider removing the leading `&`-reference
|
= help: the trait `Iterator` is not implemented for `&MessageSetsIter<'_>`
= note: `Iterator` is implemented for `&mut kafka::consumer::MessageSetsIter<'_>`, but not for `&kafka::consumer::MessageSetsIter<'_>`
= note: required because of the requirements on the impl of `IntoIterator` for `&MessageSetsIter<'_>`
= note: required by `into_iter`
i may have angered the Rust gods at this point, but we wouldn't have fire or skyscrapers if we let that stop us.
Next i commented out the async tokio call and sure enough, it compiled without error. However, the idea here is to kick actual data and back-end ops async to their own co-routines, so i think i need to do something with what is represented as cp
in my current code (MessageSets
type) to make it live long enough to make the compiler happy.
What's the tokio-proper approach to doing this?
from kafka-rust.
Victory. In case anyone runs into this down the line - turns out that a copy of the message bytes needs to be made prior to the move
a la:
loop {
for ms in consumer.poll().unwrap().iter() {
for m in ms.messages() {
// Get MySQL client connection, moved into async block
let mut mysqlconn = mysqlpool.get_conn()?;
// Clone and own the message bytes
let bytes = m.value[..].to_vec().to_owned();
// Handle the message processing async
tokio::spawn(async move {
// Convert copy of dequeued bytes to Message structure
let raw = String::from_utf8_lossy(&bytes);
// ...
let sent_sql = send_sql(&somevar, mysqlconn);
// ...
});
}
consumer.consume_messageset(ms);
}
...
from kafka-rust.
Great stuff! Thank you.
from kafka-rust.
Related Issues (20)
- windows-gnu target compilation [Question] HOT 1
- v0.8.0 is pointing to error-chain = "0.10" that is creating an error HOT 3
- [Feature request] Support for rebalancing and heartbeat HOT 8
- [Feature] Versions handling HOT 8
- How to get message timestamp HOT 2
- Consumers of the same group consuming same partitions and getting same messages HOT 1
- Sending message with headers HOT 2
- Version 0.9 HOT 2
- TLS max record size
- How to get the offset of the last message in a partition?
- is this repo being maintained? HOT 6
- Failed to debug from VSCode after added kafka client references. ("Unknown error (Open 'launch.json'" when F5)
- commit_consumed RequestTimedOut
- Consume from Latest
- UnknowTopicOrPartitiion Error
- See message headers
- how to create and delete topic with kafka-rust
- Two consumers both can receive the same message with same group and topic
- How to connect using credentials, like username and password?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kafka-rust.