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

Event Hubs: make it possible to set a custom endpoint for use with TCP proxies #2147

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions sdk/core/azure_core_amqp/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct AmqpConnectionOptions {
pub desired_capabilities: Option<Vec<AmqpSymbol>>,
pub properties: Option<AmqpOrderedMap<AmqpSymbol, AmqpValue>>,
pub buffer_size: Option<usize>,
pub custom_endpoint: Option<Url>,
}

impl AmqpConnectionOptions {}
Expand Down Expand Up @@ -206,6 +207,7 @@ mod tests {
incoming_locales: Some(vec!["en-US".to_string()]),
offered_capabilities: Some(vec!["capability".into()]),
desired_capabilities: Some(vec!["capability".into()]),
custom_endpoint: None,
properties: Some(
vec![("key", "value")]
.into_iter()
Expand Down
14 changes: 13 additions & 1 deletion sdk/core/azure_core_amqp/src/fe2o3/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ impl AmqpConnectionApis for Fe2o3AmqpConnection {
.container_id(id)
.max_frame_size(65536);

let mut endpoint = url.clone();

if let Some(options) = options {
if let Some(custom_endpoint) = options.custom_endpoint {
endpoint = custom_endpoint.clone();
builder = builder.hostname(url.host_str().unwrap());
}

if let Some(frame_size) = options.max_frame_size {
builder = builder.max_frame_size(frame_size);
}
Expand Down Expand Up @@ -101,7 +108,12 @@ impl AmqpConnectionApis for Fe2o3AmqpConnection {
}
}
self.connection
.set(Mutex::new(builder.open(url).await.map_err(AmqpOpen::from)?))
.set(Mutex::new(
builder
.open(endpoint.clone())
.await
.map_err(AmqpOpen::from)?,
))
.map_err(|_| {
azure_core::Error::new(
azure_core::error::ErrorKind::Other,
Expand Down
8 changes: 8 additions & 0 deletions sdk/eventhubs/azure_messaging_eventhubs/src/producer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ pub struct ProducerClientOptions {

/// The maximum size of a message that can be sent to the Event Hub.
pub max_message_size: Option<u64>,

/// A custom endpoint to connect to. Use this to connect through a TCP proxy.
pub custom_endpoint: Option<String>,
}

impl ProducerClientOptions {}
Expand Down Expand Up @@ -367,6 +370,7 @@ impl ProducerClient {
async fn ensure_connection(&self, url: &str) -> Result<()> {
if self.connection.get().is_none() {
let connection = AmqpConnection::new();

connection
.open(
self.options
Expand All @@ -386,6 +390,10 @@ impl ProducerClient {
.map(|(k, v)| (AmqpSymbol::from(k), AmqpValue::from(v)))
.collect(),
),
custom_endpoint: Some(Url::parse(
// TODO: yeah...probably not right.
self.options.custom_endpoint.as_ref().unwrap().as_str(),
)?),
..Default::default()
}),
)
Expand Down