 All right, so why don't you tell us now because we've talked about all this great stuff. Who are you dude and what do you do? Joe, I'm just a dude who works out of his basement in Brandon Manitoba. So this is good stuff My name is James Chambers. I'm an ASP net IS MVP I'm I've been a four-time awardee and I'm just really loving the new stuff in Azure and on ASP net vnext ASP net five. I guess we're called now and so yeah a blog in this space I'm working in the space and this opportunity to work with the already crews just awesome like to take our Craft and to apply it to something that's like for the greater good is just really cool As far as the queues go what we what we wanted to do was to basically You know take the workload that was happening in the website itself Okay, and move it off into the cloud We let's let the website keep moving as quickly as possible But the long-running tasks the IO the email sending the calling the rest API is out to send SMS messages We want to make sure that that's not tying up the tasks on the website proper I see because traditionally what's going to happen is if you send the email on the web server There's be some thread on a whatever web server that's sending an email exactly and we're waiting for that to go off and send the email So instead of doing that we knew up this command We put in all of the details that we need to we post it onto a queue And then we've got a job that's already in the back and a web job That's just part of our Azure website got it and it runs in the back end and when it's triggered automatically when a new Entry goes into the queue I see so whenever the queue whenever something goes into this queue It's just some like database kind of thing, right? Why don't you explain a little bit what a queue is sure this so the storage queue is one of the Features of Azure and it allows us just to post a message and in my case all I'm doing is taking that command that I've got I Use jason.net to serialize it as a jason document. We pitch it up just as a string So it's super easy And then on the on the other side of it when that queue is actually when we want to start processing the queue You know and back to what a queue actually is it's it's just a it's just that it's just you know The way that we think about you stand in line for something and then eventually you get to the front of the line So the queue works that way as well and the storage queue There's some cool things about it like it's gonna keep retrying for us if there's failures and everything rather than writing all of that Logic inside of our app. We just install the Azure SDK throw our message onto the bus and then We wait for it to be triggered in our web job, and that's not a completely different process. Awesome Yeah, you're saying you're saying three things like you said line Queue and bus those all represent the same thing. Yeah, effectively. Yeah, and it's just some common terminology that we use or whatever But the the line the bus the queue like I mean lines more human stuff The bus is kind of what we call it internally. There's you know, it's there's service bus There's mediator that we use is one of the patterns that we use in here as well And so it's just that more of a design pattern or conceptual thing the storage queue is actually the name of the thing that lives in Azure so that's if you're looking for it as a service in Azure That's what it's called. And so you're also saying that when you put something into the queue it notifies Something that I have work to be done. Exactly. So we've set up again with using the Azure SDK We set up this web job that gets deployed side-by-side with our site and it is automatically triggered. There's a job host that's run We specify some config so it knows how to connect to the right part of Azure and there's a connection string That's used much like when you're talking to a database and but it's really simple. It's like five lines of code and then The job host keeps running and whenever any of the functions that we export that have that are tied Explicitly to a specific queue when a new message goes in it will just automatically spin up a new process with that running in it And it'll execute whatever code we've got to process the message coming out of the queue So that Jason document that we were talking about story and earlier it's just gonna pop that off We use Jason that net again to deserialize it and then we can work with that like a normal dot net poco Well, let's let's take a look at it Maybe you can show us the message and maybe you can show us some code that pushes into the queue. Do you have that? Yeah, absolutely. Okay, so I'm driving into our applications This is the already application and in the admin area what I was working on was this concept of the activity admin controller So on the front end of the website here if it is running as an administrator I'm logging in and one of the scenarios for notifications that we want to use is when we have an Activity that set up and there's all these tasks that need to be completed. We're gonna sign volunteers these tasks So we want them to be notified, you know, you signed up to help on this project Here's an opportunity for you to help this matches your skill set. We'd like you to try this out So we go in as an administrator. I go into our campaign list We've got this idea of the smoke detectors campaign. So I go into here Maybe I'm you know, I'm actually looking for the fire prevention days and I'm gonna drill into this specific Day and I want to assign some volunteers So I'm gonna assign tasks here and then I can just pick these guys up Assign them to the tasks that we need to and when I say assign users that actually goes off into the back And that's when that queuing happens and all those right The message goes on to the bus and then the application comes back as quickly as possible Oh, that's awesome. Well, let's look at the code of how you do that. Absolutely. So I'm in the code itself here We basically we get a list of all the updates that are coming in we have You know, we just knew up a couple of lists we add anything that was that had been changed from the view model that's posted back into our our Controller action here and then very easily we just set up a view model for this command and we send it off to The bus and that's that's all that's needed to make that happen and right away We return the website gets to keep moving along got it So the bus is what kind of object is that so that's actually a library called mediator created by Active member of the ASP net community Jimmy Bogart's. Oh, of course Yeah, open source project really easy to use and really does a great job of cleaning up any of your dependencies on your Controllers so rather than having to inject all of these different Repositories and services into your controller the concept here with mediator is that you just you just inject the bus and then Whenever you want to send something off to be dispatched You put the command on and it'll find the the correct handler and deal with that message on the other end So now we've sent it to the bus we can look at the handler on the other side interesting So what can I see where you nude up the bus because I'm interested in sure yeah So the the bus is just simply it's using dependency injection So it's up in the constructor of the class and all we're doing is passing it in right you know, okay Right now in over the course of this obviously we're doing some refactoring So these other services are actually going to go away and as we move everything over to commands and queries and and use The bus then those other services disappear and the only thing injected in our controller is the I mediator So maybe you can help educate me. Are you guys using the CQRS type pattern command and query, but we're not doing full-blown event So yeah, okay, so now that's I've got my bus that gets passed in via DI I've got my controller here that does the interesting bits of building up my model I send it off to the bus and then without waiting for any Crazy processing to actually happen. I get to just resume rendering the website Can I look at the can I look at the concrete implementation of the bus that's being passed in um The concrete implementation of the bus like at the wiring for IOC or do you mean the the one that Jimmy Bogart wrote? Well, so you're passing in the one at Jimmy Bogart wrote right right the concrete one The mediator actually provides the bus for us that library provides the bus for us And then all of the rest everything happens internally in that library And then so there's a place and startup where you have to tell it any time it asks for that I Mediator is it called that's correct. You need to pass this one. Where's that code? Right, so actually what we've done is we've set up auto-fac, which is another open source project and rather than newing up each of those or creating a Mapping for each one of those. We're actually just scanning the entire DLL that for anything that's exported with that signature So I see you'll see in our under our features We've got notifications and when I look at a command a command is defined as an I request And so the I request is one of those things in mediator when you scan the assembly You find the I request and then you know, hey, these are these are the kinds of things are going to be coming into Mediator, how does it know to do it use of a singletons or instances? You can actually configure that kind of stuff on your own There's an advance like you can dive in and do that as you need to on the on the other end of it here We've got a request handler and it says hey This is the kind of thing that I know about this Notify volunteers command so now when the command hits the bus the bus looks around and says okay What classes do I know about that's the handler and the way it goes it also? This is direct command and handler, but there's also a pattern that lets you do pub subs You can publish an event and then you can have any number of listeners that are actually going to pick up and queue off of those Whatever you've sent out. Awesome. Well, let's take a look at the one for sending messages. It looks like it's right there Yeah, this is it right here. This is the command and you can see it's it's pretty straightforward What we're doing is we've got a single command that lets any caller Choose to send out The SMS messages the email messages are both so you build up that body of SMS recipients You build up the body of email recipients and when you pass that in if there's anything in that collection It's gonna loop over them and then queue the messages the SMSes have a recipient in a message The email recipients have an email And subject as well and we're actually because we're using send grid We're actually gonna be able to use templates as well So all the emails that go out are gonna look like super like awesome. Yeah, they're gonna look that's cool Yeah, so then all we do is we throw we after we for each through that we Serialize the object and we punch it onto the bus and then it go into the storage service And that is again something that's just pushed in here and that right and that storage service that IQ storage service Is actually built on top of the SDK the Azure SDK right the right exactly. Yeah, so that's cool So whenever you're whenever you're sending a message here, you're not really sending a message You're just saying we're gonna defer this to later Yeah, and we're gonna put it on the queue and let let that take care of it. Exactly. So let's can we see where the event happens when? When you actually get the queue the message in the queue and then it notifies somebody that it gets a message, right? And this is the super simple part. Um, so down here We've got a web job called notification processor and you configure it to deploy side-by-side with your web app Right when you actually the tooling and visual studio 2015 now supports You can like right-click and add a web job to this So much nicer than it used to be way remember you had to put it in this weird folder Yeah, there's like some config stuff and XML and all that kind of stuff and it was it sucked But now it's like really fast super easy to do and it deploys to the same slot as your website So there's no additional costs or anything like that, but it'll all run in separate processes So even though it's in the same slot it somehow manages to be a separate process There's some child process thing that's going on it picks them up because I'm assuming that's the way it works because when I When I send it off and I'll put myself into the queue five times I get five text messages like that. There's and you see the five different There's a DQ thing going on and it happens like one right after the next listen to the job getting the stuff off Right so to start up the job what we do in my case. I'm using user secrets Yeah, so the Azure storage Connection string is stored in my user secrets and this is or in this case an environment variable I apologize and but that's the pattern that you know that pattern that we're doing got it Probably got some refactoring here to make it use the configuration that's built into a SPN stuff like that But we're getting there at this point It just builds up a job host configuration uses that connection string for where we want to there's the storage piece in the dashboard piece The really cool thing about the dashboard is that works like your console. So like what I'm working locally. This is just you know, it's a It's a program. I've got a This is just a command line application so I can run it locally if I want to In the cloud though the logger that is injected and I'll show you that in a second over in the functions The logger that's injected anything that you're Pushing out to the log will show up in your dashboard and then you can yeah, like it makes debugging like so I know Yeah, because these things these things it feels like these things sort of run in this black box And they're like did it work right and you have no idea But you can instrument that very easily and just put push to this log and then everything's there Especially when you're doing like, you know in production when you're under load and something starts going wrong Finding the needle in the haystacks like all my spot impossible So having the log there and understanding what's happening And if you've done a good job of instrumenting and logging out your state Then this becomes a really trivial thing to do and it looks like the job host is the actual thing that's gonna be running That's right So we do we do run and block and then the way the SDK works as it scans for anything that looks like Something that is part of the Azure SDK So I've got this functions that CS and I've got a process SMS Q message It's got a Q trigger property attribute on it And when when this compiles when this builds when this runs it dives in and pulls these functions out and says This is something that we're going to use to participate in that job host Okay, so let's look at the Q trigger attribute that's happening on this function This is saying anytime this SMS dash pending dash deliveries Q. I'm assuming that's a Q That's right exactly anytime something goes into that Q execute this function exactly Yeah, and then so, you know, we've we know that it's that JSON object that we had serialized previously So we do serialize it back out. We've got a shared type with a common core library or whatever So we do serialize that back out We read from our environment variables to pull out things like our Twilio ID and our token the phone number that we're sending from and then all then the rest of it is send the To we got the message that we've got we create an instance of the Twilio rest client This is all like code that you can just pull right off of there Yeah, and then we just send it out if there's an exception if there's something goes wrong with sending it via Twilio They populate this rest exception object So if that's not Nolan, there's a message in there Then we know something went wrong and we just log it out man You're going full Elvis operator and string interpolation. I know I love it. Hey, it's great C sharp six. Yeah, okay Let me get some of your feeling because you've been you've been an IS MVP for a long time What do you think of the new direction of ASP down at five NBC six? So, you know There's a lot of cheese movements like you know the kind of the joke is that hey who moved my cheese or whatever There's a lot of cheese movement and of course and at the same time, you know They they're trying to make the point that a lot of the things are still the same I'm still gonna do a file new project I'm still gonna do a right-click deploy or I'm gonna check it into github and I'm gonna do a Repository based deployment or things like that So those those basic mechanics that we know are the same when you start drilling in yeah There's a lot of changes, but it's enabling a lot of really cool things too And it's it's actually giving us a chance to rethink some of our best practices It's you know, it's the MVC pattern, but there's all this other tools here as well So like the idea of injecting a service into a view or using a view without having to sell it to do that Yeah, and and it's and you've got IOC which is like first-class citizen across the entire board now like this is This is really good So and if it doesn't do enough if that container doesn't do enough for you then you can replace it with your own So if you want to use structure map or auto-fac or whatever you want to use an inject Then you just swap that out and use that instead So I think there's a lot of really good little nuggets in here And I mean you look at things like how fast Kestrel's running now. Yeah, it's really fast like crazy fast I think they were showing now like half a million requests a second on static files or something like that's mind-blowingly fast like Eight times faster than note or something like that. So well, thanks so much for spending time on this bud Absolutely