PullConsumer

Struct PullConsumer 

Source
pub struct PullConsumer<T, C: CodecType> { /* private fields */ }
Expand description

A typed pull consumer with configurable codec.

§Type Parameters

  • T - The message type
  • C - The codec type used for deserialization

Implementations§

Source§

impl<T, C: CodecType> PullConsumer<T, C>

Source

pub fn inner(&self) -> &Consumer<Config>

Get the underlying async-nats consumer.

Source

pub fn name(&self) -> &str

Get consumer name.

Source§

impl<T: DeserializeOwned, C: CodecType> PullConsumer<T, C>

Source

pub async fn fetch(&self, batch_size: usize) -> Result<PullBatch<T, C>>

Fetch a batch of messages.

§Example
use intercom::{Client, MsgPackCodec};
use serde::{Deserialize, Serialize};
use futures::StreamExt;

#[derive(Serialize, Deserialize, Debug)]
struct Event { id: u64 }

let client = Client::<MsgPackCodec>::connect("nats://localhost:4222").await?;
let jetstream = client.jetstream();
let stream = jetstream.get_stream("events").await?;
let consumer = stream.get_pull_consumer::<Event>("my-consumer").await?;

let mut messages = consumer.fetch(10).await?;
while let Some(result) = messages.next().await {
    let msg = result?;
    println!("Got: {:?}", msg.payload);
    msg.ack().await?;
}
Source

pub fn fetch_builder(&self) -> FetchBuilder<T, C>

Fetch messages with a builder for advanced options.

Source

pub async fn messages(&self) -> Result<PullMessages<T, C>>

Create a continuous message stream.

Returns a Stream that continuously delivers messages.

§Example
use intercom::{Client, MsgPackCodec};
use serde::{Deserialize, Serialize};
use futures::StreamExt;

#[derive(Serialize, Deserialize, Debug)]
struct Event { id: u64 }

let client = Client::<MsgPackCodec>::connect("nats://localhost:4222").await?;
let jetstream = client.jetstream();
let stream = jetstream.get_stream("events").await?;
let consumer = stream.get_pull_consumer::<Event>("my-consumer").await?;

let mut messages = consumer.messages().await?;
while let Some(result) = messages.next().await {
    let msg = result?;
    println!("Got: {:?}", msg.payload);
    msg.ack().await?;
}

Auto Trait Implementations§

§

impl<T, C> Freeze for PullConsumer<T, C>

§

impl<T, C> !RefUnwindSafe for PullConsumer<T, C>

§

impl<T, C> Send for PullConsumer<T, C>
where T: Send,

§

impl<T, C> Sync for PullConsumer<T, C>
where T: Sync,

§

impl<T, C> Unpin for PullConsumer<T, C>
where T: Unpin, C: Unpin,

§

impl<T, C> !UnwindSafe for PullConsumer<T, C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more