Hello, Cloud Gurus,
and welcome back.
In this lesson, we're going to take a look
at implementing Azure Relay.
Let's take a look at what we're going to cover.
First up, we'll briefly explore what Azure Relay is,
and then we'll take a look at how it works,
and then we'll wrap up with a quick demo
of Azure Relay.
Let's get started.
So, what is Azure Relay?
Often, when you are migrating applications to the cloud,
your applications will be migrated in batches,
and sometimes you will need to migrate applications
before all of their dependencies have been migrated.
And you also might run into issues
getting network connectivity,
between Azure and your on-premises locations,
up and running in a manner that is reliable enough
for your applications.
And all of these problems can lead to delays
in getting your apps up and running in the cloud.
The Azure Relay service allows you
to securely expose services that reside
within your corporate network
to applications running in the cloud.
And you can expose the services
without opening a firewall connection,
and without requiring intrusive changes
to corporate network infrastructure.
For example, let's say,
you work for a finance institution,
and there is financial data that is available
from an on-premises application,
and you want to be able to present
some of that application data
to customers on a new mobile banking app.
If you wait for all of the required approvals
and networking changes,
your competition could easily outpace you.
To speed up deployment,
you could use Azure Relay
to securely make data available
to the cloud-based app.
And Azure Relay has 2 features
to enable this communication.
The first is hybrid connections,
which uses HTTP and WebSockets
to support communication
using almost any programming language.
Hybrid connections is recommended in most scenarios,
including when you're using new .NET Core applications.
And if you're not familiar with WebSockets,
WebSockets is a type of web-based technology
that enables real-time communication.
The second option
is to use Windows Communication Foundation,
or WCF Relays,
to enable remote procedure calls to applications
using older .NET Framework apps that use WCF.
And, as a hybrid administrator,
you don't need to be an application developer,
and you don't need to understand these concepts in detail.
What you need to know is how the relay service
can help your business
when dealing with hybrid workloads,
and the type of connection you need,
and what's involved in setting it up.
Let's take a high-level look
at what components are involved
in setting up Azure Relay,
and how it works.
Firstly, you have a requesting client,
and this will typically be an application
hosted in Azure,
and it may be on a server,
but it could also be something like an Azure Function.
And then you have a listening client,
and this is the on-premises application
that you want to connect to.
And you create a relay by creating a namespace
with a unique servicebus.windows.net address.
And you should place the relay in a region
close to your client's.
Then you create shared access policies
that determine what clients can do
when they connect.
The clients might read or send messages.
Each shared access policy has a pair of keys
that clients can use to connect to the namespace.
And then you create a connection in the namespace,
which will be either a hybrid connection
or a WCF connection.
And then your on-premises client
connects to the relay service
through an outbound connection.
And your requesting client does the same,
making an outbound connection to the relay service.
And this creates a connection
that can be used for traffic in either direction.
The requesting client can send requests
to the relay service,
the relay service will relay that request
to the listening client,
and the listening client can respond to the request
it receives, from the relay,
back through the relay.
All right, let's take a quick look at a demo
of implementing Azure Relay.
In this demo, we want to configure the Azure Relay service
by creating a namespace,
a hybrid connection,
and collecting the authentication details
from the shared access policy.
I've used code, provided by Microsoft
to create an application
that will act as a listening client.
So, we will configure the listening client application
using the authentication details
from our shared access policy,
and then we'll run the client.
And then we'll do the same
for the requesting client.
I have some sample code from Microsoft
running on the requesting client.
We will update that code
with the shared access policy authentication details.
And then we will run the requesting client
and test the relay.
Let's take a look.
All right, and here we are on the Azure portal.
Let's go ahead and get started
by creating our relay namespace.
So, we'll go ahead and click Create,
and we'll search for Relay,
and we can go ahead and hit Create.
We'll go ahead and use our existing Resource group,
and we'll just provide a name for our relay,
I'm just going to use the name, mytestrelay1,
and I'm going to create the namespace
in the Australia East Azure region,
because that's where our application is hosted.
And now we can go ahead
and click Review and Create,
and then we can go ahead and hit Create.
This will just take a moment to create,
so, we'll come back when this is done.
All right, that namespace has been created,
so, let's go ahead and go to the resource.
Now we need to create a hybrid connection,
so, we're going to select Hybrid Connections
under Entities,
and then we'll go and create a hybrid connection.
We're just going to provide a name
for this hybrid connection.
I'm just going to call this MyHybridConnection1,
I'm going to leave the client authorization on,
and then I'll go ahead and hit Create.
Next, we need to collect the credentials,
so, we'll go ahead and navigate
to Shared Access Policies under Settings,
and we have a default shared access key,
so we'll go ahead and select that,
and we could create additional access keys
if we wanted to have keys that would just send,
or listen, and separate out those responsibilities,
but for our testing purposes here,
we're okay to just use the one key
for both the sender and the receiver,
so, we'll go ahead and copy the Primary Connection String,
which includes all the details we'll need
to configure our application.
Now, let's go ahead and update the listener,
so, we'll jump over to our listener virtual machine.
And I just have a bit of code here,
provided by Microsoft,
that will configure a listener for us.
And I just need to go ahead and provide the details
of my Azure Relay service,
and the key, and the connection name.
So, we'll go ahead and paste all this information in,
and we just need to put in our hybrid connection name,
so, we'll paste that in there as well,
and we'll just scroll down to line 40,
and we'll just change what this server replies with
when a request is sent to this server,
we'll just change this to Hello Cloud Gurus.
We can go ahead and save this.
Now we can go ahead and run this,
and if we've done everything correctly,
then our listeners should start listening.
All right, the server is listening,
now we can jump across to our sender.
Here's the sender application,
and this is code also provided by Microsoft,
so, we just need to paste in the relay namespace,
connection name, key name, and key again,
so, I'll go ahead and paste those in.
Now, what this code is doing
is it's simply making a HTTP request,
which is the equivalent of accessing a website,
but this is making the request
using the Azure Relay service.
The listener is waiting for the HTTP request
from the relay,
and responding with the message
that we just configured.
All right, now we can go ahead and run this application
and test our relay service.
But before we do that,
I'm just going to go ahead and throw a breakpoint in here.
And the only reason I'm doing this
is to make sure that this console doesn't exit
once it's received the result back
from the listener.
So, just add a breakpoint there,
then we can go ahead and start debugging,
and then it's minimized our console window,
so, I'll just bring that up,
and then we can see that response being received
from the listener via the Azure Relay.
All right, that concludes this demo.
Now let's go ahead and wrap up with a bit of a summary
of what we've covered in this lesson.
All right, so, what have we covered?
Azure Relay allows you to expose on-premises services
to applications running in the cloud
without requiring changes to network connectivity
and firewall configuration,
and you should use the Windows Communication Foundation,
or WCF Relays,
for legacy .NET Framework
and WCF applications.
And you should use Hybrid Connections
for all other application types.
And it's important to remember
that the relay service contains a namespace,
connections, and controls access
to the namespace and connections,
using shared access policies.
All right, that concludes this lesson.
Thanks for being with me,
I hope you found this useful,
and I look forward to seeing you in the next lesson.