Azure / azure-sdk-for-rust

This repository is for active development of the *unofficial* Azure SDK for Rust. This repository is *not* supported by the Azure SDK team.
MIT License
680 stars 232 forks source link

TopicClient always receive 401 #1637

Closed Gaelik-git closed 2 months ago

Gaelik-git commented 2 months ago

I created a Service Bus Namespace with:

I also have a Sharred access Policies on the Namespace level named common But the topic client always receives a 401, when my QueueClient receives 204

Can you help me with this ? Is my code incorrect ? Can it be linked to the ordering when creating things ? I am using the latest 0.19 version of the sdk with rust 1.77.1

This is the result of this test program

INFO peeked message queue val=204
INFO send message to topic ko=Error { context: Simple(HttpResponse { status: Unauthorized, error_code: None }) }
INFO peeked message from subscription val=401
use azure_messaging_servicebus::service_bus::{QueueClient, TopicClient};
use reqwest::Client;
use std::sync::Arc;
use std::time::Duration;
use tracing::{info, subscriber::set_global_default};

#[tokio::main]
async fn main() {
    // common conf
    let namespace = "REDACTED";
    let policy_name = "common";
    let policy_key = "REDACTED";

    // topic conf
    let topic_name = "test-topic";
    let subscription_name = "test-subscription";

    // queue conf
    let queue_name = "dev";

    set_global_default(tracing_subscriber::fmt::Subscriber::new())
        .expect("set tracing default subscriber");

    let client = QueueClient::new(
        Arc::new(Client::new()),
        namespace,
        queue_name,
        policy_name,
        policy_key,
    )
    .unwrap();
    let val = client
        .peek_lock_message2(Some(Duration::from_micros(1)))
        .await
        .unwrap();

    info!(val = %val.status(), "peeked message queue");
    let client = TopicClient::new(
        Arc::new(Client::new()),
        namespace,
        topic_name,
        policy_name,
        policy_key,
    )
    .unwrap();

    let val = client.topic_sender().send_message("msg").await;

    match val {
        Ok(_) => info!(ok = ?val.is_ok(), "send message to topic"),
        Err(_) => info!(ko = ?val.unwrap_err(), "send message to topic"),
    }

    let val = client
        .subscription_receiver(subscription_name)
        .peek_lock_message2(Some(Duration::from_micros(1)))
        .await
        .unwrap();

    info!(val = %val.status(), "peeked message from subscription");
}
Gaelik-git commented 2 months ago

I think it might a bug introduced in v0.18

When using the v0.17 of this crate I get better result, I am able to send message to the topic but reading from the subscription is still ko

2024-04-12T16:31:31.347529Z  INFO: peeked message queue val=204
2024-04-12T16:31:31.597199Z  INFO: send message to topic ok=true
2024-04-12T16:31:32.730468Z  INFO: peeked message from subscription val=405

This is the body of the 405 reponse

<Error>
   <Code>405</Code>
   <Detail>It is not possible for an entity that requires sessions to create a non-sessionful message receiver. TrackingId:0d889d68-0ab2-4a03-b080-9dbae72678b1_G19_B22, SystemTracker:REDACTED:Topic:test-topic|test-subscription, Timestamp:2024-04-12T17:11:24</Detail>
</Error>
Gaelik-git commented 2 months ago

Looks like the fix on this commit should also be on the TopiClient https://github.com/Azure/azure-sdk-for-rust/commit/c999ef3df4c8c65edf458e7948235e31bd44dc61