GithubHelp home page GithubHelp logo

Comments (4)

stearnsc avatar stearnsc commented on August 16, 2024

Is that the entire text of the error? That implies to me that either the consumer or the connection is going out of scope before the ack is being sent, which should be impossible. Do you have a (relatively) minimal reproduction I could take a look at?

from pulsar-rs.

chrislearn avatar chrislearn commented on August 16, 2024

use pulsar::{Pulsar, Consumer, SubType, DeserializeMessage, SerializeMessage, producer};
use serde::{Serialize, Deserialize};
use std::time::Duration;
use pulsar::Error as PulsarError;
use pulsar::message::Payload;
use futures::executor::ThreadPool;
use futures::task::SpawnExt;
use futures::compat::Stream01CompatExt;
use futures::stream::StreamExt;
use futures::compat::Future01CompatExt;

#[derive(Debug)]
enum Error {
    Pulsar(PulsarError),
    Message(String),
    Timeout(std::io::Error),
    Serde(serde_json::Error),
    Utf8(std::string::FromUtf8Error),
}

impl From<std::io::Error> for Error {
    fn from(e: std::io::Error) -> Self {
        Error::Timeout(e)
    }
}

impl From<PulsarError> for Error {
    fn from(e: PulsarError) -> Self {
        Error::Pulsar(e)
    }
}

impl From<serde_json::Error> for Error {
    fn from(e: serde_json::Error) -> Self {
        Error::Serde(e)
    }
}

impl From<std::string::FromUtf8Error> for Error {
    fn from(err: std::string::FromUtf8Error) -> Self {
        Error::Utf8(err)
    }
}

impl std::fmt::Display for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            Error::Pulsar(e) => write!(f, "{}", e),
            Error::Message(e) => write!(f, "{}", e),
            Error::Timeout(e) => write!(f, "{}", e),
            Error::Serde(e) => write!(f, "{}", e),
            Error::Utf8(e) => write!(f, "{}", e),
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
struct TestData {
    pub data: String,
}

impl SerializeMessage for TestData {
    fn serialize_message(input: &Self) -> Result<producer::Message, PulsarError> {
        let payload =
            serde_json::to_vec(input).map_err(|e| PulsarError::Custom(e.to_string()))?;
        Ok(producer::Message {
            payload,
            ..Default::default()
        })
    }
}
impl DeserializeMessage for TestData {
    type Output = Result<TestData, serde_json::Error>;

    fn deserialize_message(payload: Payload) -> Self::Output {
        serde_json::from_slice(&payload.data)
    }
}

async fn run() {
    let addr = "127.0.0.1:6650".parse().unwrap();
	let executor = ThreadPool::new().unwrap().compat();

    let pulsar: Pulsar = Pulsar::new(addr, None, executor).compat().await.unwrap();

    let consumer: Consumer<TestData> = pulsar
        .consumer()
        .with_topic("test")
        .with_consumer_name("test_consumer")
        .with_subscription_type(SubType::Shared)
        .with_subscription("test_subscription")
        .build().compat().await.unwrap();

    consumer.compat().for_each(move|msg| {
        let msg = msg.unwrap();
        msg.ack.ack();
        futures::future::ready(())
    }).await;

    
    tokio::time::delay_for(Duration::from_millis(5000)).await;
    /* this will panic
    let producer = pulsar.producer(None);
    producer.send(
        "test",
        &TestData {
            data: "data".to_string(),
        },
    ).compat().await.unwrap();
    */
    pulsar.send("test", &TestData {
        data: "data".to_string(),
    },  Default::default()).compat().await;
}

#[tokio::main]
async fn main() {
    run().await;
}


from pulsar-rs.

chrislearn avatar chrislearn commented on August 16, 2024

and I changed the ack function for print the error message:

    pub fn ack(mut self) {
        for (consumer_id, message_ids) in self.take_message_ids() {
            let result = self.sender.unbounded_send(AckMessage::Ack {
                consumer_id,
                message_ids,
                cumulative: false,
            });
            if let Err(e) = result {
                println!("===============ack error: {}", e.to_string());
            } else {
                println!("===============ack ok");
            }
        }
    }

from pulsar-rs.

Geal avatar Geal commented on August 16, 2024

this should be fixed by the 1.0 release

from pulsar-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.