Skip to content

Initial Service Bus crate #2863

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@
"path": "../sdk/keyvault/.dict.txt",
"noSuggest": true
},
{
"name": "servicebus",
"path": "../sdk/servicebus/.dict.txt",
"noSuggest": true
},
{
"name": "storage",
"path": "../sdk/storage/.dict.txt",
Expand Down Expand Up @@ -202,6 +207,14 @@
"cosmos"
]
},
{
"filename": "sdk/servicebus/**",
"dictionaries": [
"crates",
"rust-custom",
"servicebus"
]
},
{
"filename": "sdk/storage/**",
"dictionaries": [
Expand All @@ -211,4 +224,4 @@
]
}
]
}
}
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
"sdk/keyvault/azure_security_keyvault_certificates",
"sdk/keyvault/azure_security_keyvault_keys",
"sdk/keyvault/azure_security_keyvault_secrets",
"sdk/servicebus/azure_messaging_servicebus",
"sdk/template/azure_template_core",
"sdk/template/azure_template",
"sdk/storage/azure_storage_common",
Expand Down
13 changes: 13 additions & 0 deletions sdk/servicebus/.dict.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
amqps
azuremessagingservicebus
backoff
mybus
myqueue
myservicebus
retryable
Retryable
SubQueue
subqueues
testqueue
testtopic
testsubscription
17 changes: 17 additions & 0 deletions sdk/servicebus/azure_messaging_servicebus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Release History

## 0.1.0 (Unreleased)

### Features Added

- Initial release of Azure Service Bus client library for Rust
- Support for sending and receiving messages from Service Bus queues and topics
- Support for session-enabled entities
- Support for dead letter queues
- AMQP-based implementation using azure_core_amqp

### Breaking Changes

### Bugs Fixed

### Other Changes
120 changes: 120 additions & 0 deletions sdk/servicebus/azure_messaging_servicebus/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Running Azure Service Bus Live Tests

This guide explains how to set up and run live integration tests for the Azure Service Bus SDK for Rust using the Azure SDK test infrastructure.

## Prerequisites

1. **Azure Subscription**: Access to the targeted subscription
2. **Azure CLI**: Install and configure Azure CLI (`az login`)
3. **Azure PowerShell**: Install PowerShell modules (`Install-Module Az -Force`)
4. **Bicep**: For infrastructure deployment (`az bicep install`)
5. **Permissions**: Contributor access to create resources in your subscription

## Automated Test Infrastructure Setup

The Azure SDK provides a standardized test infrastructure using the `New-TestResources.ps1` script with Bicep templates to automatically create and configure all required Azure Service Bus resources.

### Deploy Test Resources

From the repository root, run:

```powershell
# Set subscription
az account set --subscription "<Your Subscription Name>"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this is the Azure CLi. The script below uses the Azure PowerShell cmdlets. This command makes no different. You can and should avoid the -SubscriptionId parameter below if you replace this with Set-AzContext -Subscription "<Name>".

# Deploy test infrastructure
./eng/common/TestResources/New-TestResources.ps1 servicebus/azure_messaging_servicebus -SubscriptionId <subscription ID>
```

This will automatically create:

- Azure Service Bus namespace with Standard tier
- Test queue named `testqueue`
- Test topic named `testtopic` with subscription `testsubscription`
- RBAC permissions for TokenCredential testing
- All required environment variables

The script will output PowerShell commands to set environment variables.

### Environment Variables

After deployment completes successfully, the script will output commands like:

```powershell
$env:SERVICEBUS_NAMESPACE = "sb-your-deployment-name.servicebus.windows.net"
$env:SERVICEBUS_QUEUE_NAME = "testqueue"
$env:SERVICEBUS_TOPIC_NAME = "testtopic"
$env:SERVICEBUS_SUBSCRIPTION_NAME = "testsubscription"
```

## Run Live Tests

Once the environment variables are set, run the tests:

**All Live Tests:**

```powershell
cd sdk\servicebus\azure_messaging_servicebus
cargo test
```

## Debugging

Enable debug logging for detailed information:

```powershell
$env:RUST_LOG = "debug"
cargo test
```

For detailed AMQP protocol debugging:

```powershell
$env:RUST_LOG = "azure_messaging_servicebus=debug,azure_core_amqp=debug"
cargo test
```

## Expected Test Behavior

- **TokenCredential Tests**: Will skip if not properly configured (not a failure)
- **Test Duration**: Each test typically takes 10-30 seconds due to network operations
- **Resource Cleanup**: Tests automatically complete/delete sent messages

## Troubleshooting

### Deployment Issues

- Ensure you're logged into Azure CLI: `az login`
- Verify you have Contributor permissions on the subscription
- Check that the resource group name doesn't already exist
- Ensure Service Bus is available in your selected region

### Authentication Issues

- For TokenCredential tests, ensure you're logged in via Azure CLI
- RBAC permissions are automatically configured during deployment
- Service principal credentials can be set via environment variables if needed

### Test Execution Issues

- Verify all environment variables are set correctly
- Check that Service Bus resources are in "Active" status
- Ensure network connectivity to Azure Service Bus
- Review test output for specific error messages

## Resource Cleanup

When you're finished testing, clean up the resources:

```powershell
# Clean up test resources
./eng/common/TestResources/Remove-TestResources.ps1 servicebus/azure_messaging_servicebus
```

## Performance Notes

- Live tests create real network connections
- Messages are sent to actual Azure Service Bus queues
- Consider using a dedicated test namespace
- Tests include cleanup operations (complete/delete messages)
- Some tests may have delays for timing validation
45 changes: 45 additions & 0 deletions sdk/servicebus/azure_messaging_servicebus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (c) Microsoft Corp. All Rights Reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

[package]
name = "azure_messaging_servicebus"
version = "0.1.0"
description = "Rust client for Azure Service Bus"
readme = "README.md"
authors.workspace = true
license.workspace = true
repository.workspace = true
homepage = "https://github.com/azure/azure-sdk-for-rust"
documentation = "https://docs.rs/azure_messaging_servicebus"

keywords = ["sdk", "azure", "messaging", "cloud", "servicebus"]
categories = ["api-bindings"]

edition.workspace = true

[dependencies]
async-lock.workspace = true
async-stream.workspace = true
async-trait.workspace = true
azure_core.workspace = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to disable default features here. See EH for an example.

azure_core_amqp.workspace = true
futures.workspace = true
rand.workspace = true
rand_chacha.workspace = true
serde = { workspace = true, features = ["derive"] }
time.workspace = true
tracing.workspace = true
url.workspace = true
uuid.workspace = true

[dev-dependencies]
azure_core_amqp = { workspace = true, features = ["test"] }
azure_core_test = { workspace = true, features = ["tracing"] }
azure_identity.workspace = true
azure_messaging_servicebus = { path = "." }
serde_json.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
tracing-subscriber = { workspace = true, features = ["env-filter", "fmt"] }

[lints]
workspace = true
Loading