Crate azeventhubs

Source
Expand description

An unofficial and experimental Azure Event Hubs client library for Rust.

This crate follows a similar structure to that of the Azure SDK for .Net, and thus it should be familiar to anyone who has used the dotnet SDK. This crate is still in development, and not all features are implemented yet.

§Examples

§Event Hub Producer Example

use azeventhubs::producer::{
EventHubProducerClient, EventHubProducerClientOptions, SendEventOptions,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut producer_client =
        EventHubProducerClient::new_from_connection_string(
            "<CONNECTION_STRING>", // Replace with your connection string
            "<EVENT_HUB_NAME>".to_string(), // Replace with your hub name
            EventHubProducerClientOptions::default()
       ).await?;

    let partition_ids = producer_client.get_partition_ids().await?;

    let event = "Hello, world to first partition!";
    let options = SendEventOptions::new().with_partition_id(&partition_ids[0]);
    producer_client.send_event(event, options).await?;

    producer_client.close().await?;

    Ok(())
}

§Event Hub Consumer Example

use futures_util::StreamExt;
use azeventhubs::consumer::{EventHubConsumerClient, EventHubConsumerClientOptions, EventPosition, ReadEventOptions};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a consumer client
    let mut consumer_client =
        EventHubConsumerClient::new_from_connection_string(
            EventHubConsumerClient::DEFAULT_CONSUMER_GROUP_NAME,
            "<CONNECTION_STRING>", // Replace with your connection string
            "<EVENT_HUB_NAME>".to_string(), // Replace with your hub name
            EventHubConsumerClientOptions::default(),
        ).await?;

    let partition_ids = consumer_client.get_partition_ids().await?;
    let starting_position = EventPosition::earliest();
    let options = ReadEventOptions::default();

    // Get a stream of events from the first partition
    let mut stream = consumer_client
        .read_events_from_partition(&partition_ids[0], starting_position, options)
        .await?;

    // Receive 30 events
    let mut counter = 0;
    while let Some(event) = stream.next().await {
        let event = event?;
        let body = event.body()?;
        let value = std::str::from_utf8(body)?;
        log::info!("{:?}", value);

        log::info!("counter: {}", counter);
        counter += 1;
        if counter > 30 {
            break;
        }
    }
    // Close the stream
    stream.close().await?;

    // Close the consumer client
    consumer_client.close().await?;

    Ok(())
}

§What is implemented and what is not?

FeatureSupported
Event Hub ConnectionYes
Event Hub ProducerYes
Event Hub ConsumerYes
Partition ReceiverYes
Event Hub Buffered ProducerNot yet
Event Hub ProcessorNot yet
Checkpoint StoreNot yet

§TLS Support

Communication between a client application and an Azure Service Event Hub namespace is encrypted using Transport Layer Security (TLS). The TLS implementation is exposed to the user through the corresponding feature flags (please see the feature flag section below). The user should ensure either the rustls or native-tls feature is enabled, and one and only one TLS implementation must be enabled. Enabling both features is not supported and will result in an error.

The native-tls feature is enabled by default, and it will use the native-tls crate to provide TLS support. The rustls feature will use the rustls crate and webpki-roots crate to provide TLS support.

§Feature Flags

This crate supports the following feature flags:

FeatureDescription
defaultEnables “native-tls” feature
rustlsEnables the use of the rustls crate for TLS support
native-tlsEnables the use of the native-tls crate for TLS support

§WebAssembly Support

WebAssembly is NOT supported yet.

§MSRV

1.75.0

Modules§

authorization
Types related to auth.
consumer
Azure Event Hubs Consumer
primitives
Primitives for the Azure Event Hubs client.
producer
Producer client

Structs§

BasicRetryPolicy
Default retry policy used by the client.
EventData
An Event Hubs event, encapsulating a set of data and its associated metadata.
EventHubConnection
A connection to the Azure Event Hubs service, enabling client communications with a specific Event Hub instance within an Event Hubs namespace. A single connection may be shared among multiple Event Hub producers and/or consumers, or may be used as a dedicated connection for a single producer or consumer client.
EventHubConnectionOptions
The set of options that can be specified when creating crate::EventHubConnection
EventHubProperties
A set of information for an Event Hub.
EventHubsConnectionStringProperties
The set of properties that comprise a Event Hubs connection string.
EventHubsRetryOptions
The set of options that can be specified to influence how retry attempts are made, and a failure is eligible to be retried.
MaxRetries
The maximum number of retry attempts before considering the associated operation to have failed
PartitionProperties
A set of information for a single partition of an Event Hub.
ReceivedEventData
A received event.

Enums§

EventHubConnectionError
Error with the EventHubConnection.
EventHubsRetryMode
The type of approach to apply when calculating the delay between retry attempts.
EventHubsTransportType
Specifies the type of protocol and transport that will be used for communicating with Azure Event Hubs.
FormatError
Error with parsing the connection string.
ToConnectionStringError
Error with outputting the connection string.

Traits§

EventHubsRetryPolicy
A policy governinng retrying of operations.