5555
5656 // newClientFn exists so we can stub out newClient for unit tests.
5757 newClientFn func (ctx context.Context , connID uint64 ) (amqpwrap.AMQPClient , error )
58+
59+ customEndpoint string
5860 }
5961
6062 // NamespaceOption provides structure for configuring a new Event Hub namespace
@@ -102,6 +104,17 @@ func NamespaceWithConnectionString(connStr string) NamespaceOption {
102104 }
103105}
104106
107+ // NamespaceWithCustomEndpoint sets a custom endpoint, useful for when you're connecting through a TCP proxy.
108+ // When establishing a TCP connection we connect to this address. The audience is extracted from the
109+ // fullyQualifiedNamespace given to NamespaceWithTokenCredential or the endpoint in the connection string passed
110+ // to NamespaceWithConnectionString.
111+ func NamespaceWithCustomEndpoint (customEndpoint string ) NamespaceOption {
112+ return func (ns * Namespace ) error {
113+ ns .customEndpoint = customEndpoint
114+ return nil
115+ }
116+ }
117+
105118// NamespaceWithTLSConfig appends to the TLS config.
106119func NamespaceWithTLSConfig (tlsConfig * tls.Config ) NamespaceOption {
107120 return func (ns * Namespace ) error {
@@ -170,6 +183,7 @@ func (ns *Namespace) newClientImpl(ctx context.Context, connID uint64) (amqpwrap
170183 "framework" : runtime .Version (),
171184 "user-agent" : ns .getUserAgent (),
172185 },
186+ HostName : ns .FQDN ,
173187 }
174188
175189 if ns .tlsConfig != nil {
@@ -190,7 +204,7 @@ func (ns *Namespace) newClientImpl(ctx context.Context, connID uint64) (amqpwrap
190204 return & amqpwrap.AMQPClientWrapper {Inner : client , ConnID : connID }, err
191205 }
192206
193- client , err := amqp .Dial (ctx , ns .getAMQPHostURI (), & connOptions )
207+ client , err := amqp .Dial (ctx , ns .getAMQPHostURI (true ), & connOptions )
194208 return & amqpwrap.AMQPClientWrapper {Inner : client , ConnID : connID }, err
195209}
196210
@@ -461,11 +475,17 @@ func (ns *Namespace) getWSSHostURI() string {
461475 return fmt .Sprintf ("wss://%s/" , ns .FQDN )
462476}
463477
464- func (ns * Namespace ) getAMQPHostURI () string {
478+ func (ns * Namespace ) getAMQPHostURI (useCustomEndpoint bool ) string {
479+ fqdn := ns .FQDN
480+
481+ if useCustomEndpoint && ns .customEndpoint != "" {
482+ fqdn = ns .customEndpoint
483+ }
484+
465485 if ns .TokenProvider .InsecureDisableTLS {
466- return fmt .Sprintf ("amqp://%s/" , ns . FQDN )
486+ return fmt .Sprintf ("amqp://%s/" , fqdn )
467487 } else {
468- return fmt .Sprintf ("amqps://%s/" , ns . FQDN )
488+ return fmt .Sprintf ("amqps://%s/" , fqdn )
469489 }
470490}
471491
@@ -474,7 +494,7 @@ func (ns *Namespace) GetHTTPSHostURI() string {
474494}
475495
476496func (ns * Namespace ) GetEntityAudience (entityPath string ) string {
477- return ns .getAMQPHostURI () + entityPath
497+ return ns .getAMQPHostURI (false ) + entityPath
478498}
479499
480500func (ns * Namespace ) getUserAgent () string {
0 commit comments