Jacob Vame
Jacob Vame

Reputation: 11

Is it possible to configure an Azure Relay listener that responds to the local addresses also?

I'm new in the Azure Relay use and configuration.

I've developed an API that responds with the Relay mechanism ... now my need is to leave the service bus listeners configured by default in Program (or even in startup) like this:

webBuilder.UseAzureRelay(options =>
            {
               options.UrlPrefixes.Add(Configuration.GetSection("AzureRelay")
                       .GetValue<string>("SB_HC_CONNECTIONSTRING"));
            }) 

Now I need to add other local addresses so that the API can respond via requests from the on-prem environment in which it is released (like a front-end application).

I've searched in documentations, but unfortunately, there's no evidence of how to gain this behavior, and there is no example of how to use the Relay like a middleware.

Have you any ideas or examples to achieve this?

Upvotes: 1

Views: 969

Answers (2)

Kaptein Babbalas
Kaptein Babbalas

Reputation: 1108

I dont know of any middleware that does this, but this sample might help you. I managed to send a message from a console app to the relay and forward that request to another endpoint and relay the response back to the client. This works exactly as NGROK.

To send the message do something like this:

var tokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(
                KeyName, Key);

            var hbConnectionName = "testing";
            var remotePath = "api/weather";

            var uri = new Uri($"https://xxx.servicebus.windows.net/{hbConnectionName}/{remotePath}");
            var token = (await tokenProvider.GetTokenAsync(uri.AbsoluteUri, TimeSpan.FromHours(1))).TokenString;
            var client = new HttpClient();
            var request = new HttpRequestMessage()
            {
                RequestUri = uri,
                Method = HttpMethod.Get,
            };
            request.Headers.Add("ServiceBusAuthorization", token);
            var response = await client.SendAsync(request);
            Console.WriteLine(await response.Content.ReadAsStringAsync());

Upvotes: 0

SauravDas-MT
SauravDas-MT

Reputation: 1440

Azure Relay service facilitates your hybrid applications by enabling you to securely expose services within corporate enterprise network to the public cloud, without having to open a firewall connection or making any changes to corporate network.

Azure Relay addresses the technical challenge of communication between on-premise service and the external application which does not reside on the same premise or firewall. It allows on-premise service to expose a public endpoint. It provides High Availability for On-Premise Services. Azure Relay allows for registering multiple listeners to a single public relay endpoint. This provides a framework for both performance and availability without complex application logic or a costly networking appliance.

There are two Relay offerings from Azure Relay known as WCF Relay and Hybrid Connection.

  • Using WCF Relay you can initiate the connection between your on-premises service and the relay service using the WCF relay bindings.

  • Hybrid Connections provide an easy and convenient way to connect the Web Apps feature in Azure App Service and the Mobile Apps feature in Azure App Service to on-premises resources behind your firewall.

Check this Expose an on-premises WCF REST service to external client by using Azure WCF Relay tutorial from Microsoft for more information.

Alternatively we can develop middleware by simply using Azure Service Bus and Functions check this Developing Middleware With Microsoft Azure Service Bus And Functions document for more information.

Upvotes: 0

Related Questions