Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Subscription and Subscriber in the SDK #93

Closed
17 tasks
pedronauck opened this issue Jul 24, 2024 · 0 comments · Fixed by #125
Closed
17 tasks

Implement Subscription and Subscriber in the SDK #93

pedronauck opened this issue Jul 24, 2024 · 0 comments · Fixed by #125

Comments

@pedronauck
Copy link
Collaborator

pedronauck commented Jul 24, 2024

Description

Implement the Subscription and Subscriber components in the SDK as per the given specifications. These components will enable users to subscribe to specific NATS subjects and consume the incoming data stream.

use fuel_streams::{
    conn::{Client, ConnectionResult},
    stream::{Subscription},
    types::Response,
};

#[tokio::main]
async fn main() -> ConnectionResult<()> {
    let server = Client::new("stream.fuel.network").await?;
    let subscriber = Subscription::new(Subject::Transactions)
        .subscribe(&server)?;

    while let Some(response) = subscriber.next().await {
        println!("Received transaction: {:?}", response);
    }

    Ok(())
}

Tasks

  • Create a Subscription struct with the following methods:
    • new(subject: Subject) -> Self
    • subscribe(server: &Client) -> Result<Subscriber, SubscriptionError>
  • Create a Subscriber struct with the following methods:
    • next(&mut self) -> Option<Response>
    • try_next(&mut self) -> Result<Option<Response>, SubscriberError>
  • Implement error handling for subscription and message consumption
  • Define SubscriptionError and SubscriberError enums using thiserror
  • Write unit tests for all Subscription and Subscriber methods
  • Create integration tests with Client and mock NATS server
  • Ensure compatibility with the provided usage example

Technical Details

  • Use async streams for message consumption in Subscriber
  • Implement filtering capabilities for subscriptions using the Filter type
  • Ensure Subscription works with different Subject types (e.g., Transactions, Blocks)
  • Make sure the Response type can handle different data types based on the Subject
  • Use thiserror to create proper SubscriptionError and SubscriberError enums

Additional Notes

  • Ensure the API is consistent with Client and other SDK components
  • The implementation should support the usage pattern provided in the example
  • Consider implementing a way to handle durable subscriptions if required

Definition of Done

  • Code implemented
  • Unit tests written and passing
  • Integration tests (if applicable) written and passing
  • Documentation updated
  • Code reviewed
  • Example usage works as expected
@pedronauck pedronauck added this to the v1 - Internal MVP milestone Jul 24, 2024
@pedronauck pedronauck self-assigned this Jul 24, 2024
@pedronauck pedronauck removed this from the v1 - Internal MVP milestone Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant