Now, it's time to go ahead and create a new service bus.
We will use the service bus to create a
queue that we can use in our cloud service.
Let's go down to the command bar; hit New, App Service, Service Bus and then Queue.
We can do a Quick Create or a Custom Create.
I'm going to select Custom Create.
And then we're going to call this the university service bus queue.
Now it's important to put this in the same region that you have your cloud service.
So we've already created the cloud service in the west US
region, so we're going to create our service bus there as well.
It looks like our namespace is ready.
We're going to go ahead and hit next.
And then we have the ability to set the size of the queue
up to 5 gigabytes as well as the default message time to live.
You can also put this in minutes, seconds, or hours.
Later on I'm going to show you how to set
all of this in code, so we're just going to take
the defaults, including the lock duration, and we're going to on
check move expired messages, enable duplicate detection, and enable session.
So while it's activating, we can click on details, and you can see that
it's created the namespace, and it's now
activating the namespace, and everything has been activated.
If
I go ahead and click on it, we get
our blue thunder cloud with information about where to get
the tools, management tests, as well as other links to
other useful information on how to connect to our queue.
If I click on the all tab, you'll see
this is where our queues, topics and relays are listed.
And we currently have one active queue.
Its current size is 0 and its max size is 1 gigabyte.
If I click on
queue, I can also click the name of the queue, come in here
and change the settings that we did when we did a custom set up.
If we move back up, you see we
also have the ability to create notification hubs and
configure Configure is also the area where we
can regenerate our access key if we need to.
Now that we have our service bus queue created, let's
drop back over to Visual Studio, and we're going to want
to open the web role.
So we are going to write to the queue first through the web role, so
we need to make sure that we have a reference to the service bus namespace.
So right-click on references underneath the univ webroll, say
add references, and then look for Microsoft service bus.
You should select version 2.0, as it's
possible your PC may have a different version.
Next, click OK. And now in code, we'll need to add the
references to the proper libraries. So, underneath controllers, open up home
controller dot CS and then at the top we're going to say using microsoft
dot service bus using microsoft service bus messaging
and then we also need to make a reference to Microsoft Windows Azure.
Let's save this.
And now that we have references to the name
space to work with service bus queues, we also
need to tell the cloud service the proper security
access to reference our queue currently in the cloud.
We can do this a couple different ways.
We can edit the cloud service configuration
file manually And you'll see in here, we
have our existing settings for our web
role, with a connection string, and our worker
role with a connection string, as well as
our local configuration files, both pointing to local storage.
And you can see our existing instance counts of 5, with 1 being
dedicated to the web role, and 4 being dedicated to the worker role.
Another way we can do this is actually by clicking on any of the
roles hitting settings and underneath surface configuration
making sure that we have all configurations selected.
We could manually select both cloud or local and you'll see here
those same settings reflected that we saw in the csconfig file text.
Lets select all configurations and say add setting and we going to create a new
string that we going to call the Microsoft
Service Bus Connection String, and lets save that.
Now the connection String itself we going to get from the portal,
so if we go back to our portal and we hit connection information Down under here,
you'll see ACS connection string. This is your access connection string.
You're going to want to copy this complete
string, and in visual studio, we're going paste it.
You also have another option if you'd like, let
me delete this first, and you can hit the ....
If we hit ...
I can
paste it in here and make sure I see the full string.
Let's hit OK>Save>Close and you'll notice now we
have a connection string, Microsoft service bus connection
string with its values set up properly to access our service bus queue in the cloud.
We also need to set that up for the worker role.
So if we come back in here, on the
worker role hit settings, make sure we have all configurations
set, hit add settings, and then we're going to type the same thing.
Microsoft service bus connection string.
And then paste in our ACS.
Make sure that you save everything Double check that your
Cloud configuration and your local configuration now have the settings,
as well as your service definition file, which you can
see under Configurations it has the new setting for Microsoft
Service Bus Connection string, and then go ahead and run you service.
This will run locally to make sure
that everything is set up correctly, and working.
It looks like everything is working correctly.
So next, I'll show you how to use code to
go ahead and write to the Service Bus Message Queue.