Phone: (865) 257-9679     Mail: info@yosttechnologies.com

Blog

/ WebAPI, NServiceBus, and SignalR, Oh My!!
22 Aug 2013

WebAPI, NServiceBus, and SignalR, Oh My!!

  • By Unknown
  • 4  Tags
  • 6  Comments
I just recently got done helping prove out a very interesting concept that I thought I would share. This may not be anything new for some of you but for many this may be a very eye opening concept. It has to do with how you can combine three technologies to give you a very resilient and “push event” driven RESTful API for your applications and/or customers to use.

A technology many of us already know and love is Microsoft’s WebAPI framework that comes built into their ASP.NET MVC framework. It enables developers to very quickly build truly RESTful APIs that by default use JSON for the data messages. I have been using this platform ever since it was in pre-release and if you are in the process of evaluating your options for building an API – this is the one to look at. More information about it can be found at http://www.asp.net/web-api.

Now, this is only part of the picture and I have said nothing earth shattering so let's get on to the good stuff.

So lets say you or your organization/team has spent the time to build your API on the WebAPI platform and everything is going great but now you have come to the point where you need your services to talk to each other. Do the services call each other? Well that doesn't feel right. Plus, how do I  know when one of the services does something that another service needs to respond to as well? Do I use SQL data triggers? Ick!! Enter NServiceBus by Particular Software (http://particular.net/NServiceBus).
As it’s name implies, it is at its core a service bus that can be used to distribute events and messages between various listeners. It enables you to decouple your services to achieve a true SOA (service oriented architecture) but maintains a transactional consistency, reliability, and scalability you will need. This means your services can subscribe to events other services publish. Ok, a bit tough to follow so lets look at an example.

Say for simplicity sake you have two WebAPI services; a Inventory API and and a Products API. Now, lets say your Products API needs to know when the Inventory API changes available inventory so it can update the “availability” information on its products. This can be easily achieved by the Inventory API publishing a “InventoryUpdate” event to NServiceBus which then puts it in its queue and broadcasts the event to all subscribers of that event. For the ProductsAPI to get this event it simply subscribes to the “InventoryUpdate” event. Bam! You have “connected” your services together with NServiceBus.

So, thanks to NServiceBus your services are “talking” to each other via events but that is really only part of the picture. Wouldn’t it be nice if you could take those events and pass them on to the consumers of your APIs? But wait, we are talking about a WEB API so how can this be done? Enter SignalR.

Only until recently it was just wishful thinking of API builders to be able to push notifications to consumers of their APIs. Now, thanks to a new framework put out by Microsoft called ASP.NET SignalR these dreams have coming true. Essentially ASP.NET SignalR is a library that makes it incredibly simple to “push” events over the HTTP protocol. Without going into too much detail, SignalR uses HTTP web sockets to push in real time data to a website. More information about the framework and how to use it can be found at http://signalr.net/.

So how does this apply to WebAPI you ask?

Well, since your WebAPI is really just a website it can use SignalR to push events to your API consumers so they get real time notifications. In the past your API consumers would need some kind of “heartbeat” that constantly called your API for status updates to determine if an event occurred but with SignalR they will be notified immediately via “events” your API pushes out. Whether the consumer of your API is another website or application it can attach event handlers to these push notifications – essentially closing the loop on service events.

While all of this may seem very confusing and complicated, for what is being achieved it is actually very simple and elegant. This approach allows you to develop a very distributed API while maintaining interconnectivity between each of your services and their consumers. I can almost guarantee you we are going to see more and more need for this type workflow and with WebAPI, NServiceBus, and SignalR, there is no reason you can’t do it now.

Feel free to leave me comments or feedback. If you have specific questions about this post please contact me at matt@yosttechnologies.com or go to our website at http://www.yosttechnologies.com and submit your comments.
COMMENTS
  • Kiquenet
  • | Mar 07 2014
  • | Reply
Any full source code sample real application about it ?
  • Mark Roberts
  • | Nov 04 2017
  • | Reply
As the brain becomes overwhelmed with changing stimuli, it stops attending to any one thing and starts zoning out. Too much exposure to these frenetic programs gives the brain more practice passively accepting information without deeply processing it. <a href="http://www2.newsy.com/videos/u-k-elections-nicola-sturgeon-s-big-week/" rel="nofollow">guarantor loans</a><br />
  • Rian
  • | Oct 15 2021
  • | Reply
<a href="https://www.virtualedge.org/" rel="nofollow">event management</a> Most marketing departments are now used to evaluating their digital advertising strategies using rigorous data analysis. And like pay-per-click ads, virtual events provide a wealth of data on click-throughs, page visits, and video views. The more robust platforms will even track which users are the most active, and for how long. <a href="https://www.virtualedge.org/5-tips-to-organize-private-event-virtually/" rel="nofollow">private virtual events</a>, <a href="https://www.virtualedge.org/event-planner-salary/" rel="nofollow">event coordinator role</a> and <a href="https://www.virtualedge.org/fun-icebreakers-ideas-for-virtual-teams/" rel="nofollow">virtual ice breaker games</a>
  • Anonymous
  • | Jan 24 2022
  • | Reply
How to get Free Spins at Bet365 - Tatsuberbet<br />How to register with Bet365 – Tatsuberbet. Bet <a href="https://thauberbet.com/sbobet/" rel="nofollow">sbobet ทางเข้า</a> 365 also has a fantastic sportsbook, and online casino that gives you <a href="https://casinoinjapan.com/bons-casino/" rel="nofollow">ボンズ カジノ</a>
  • parkersaas
  • | Mar 03 2022
  • | Reply
How to Start with a casino slot - JT Hub<br />A slot machine is <a href="https://www.jtmhub.com/%ec%84%b8%ec%a2%85%ed%8a%b9%eb%b3%84%ec%9e%90%ec%b9%98%ec%b5%9c%eb%8c%80%ea%b7%9c%eb%aa%a8%ec%b6%9c%ec%9e%a5%ec%95%88%eb%a7%88.html/" rel="nofollow">세종특별자치 출장마사지</a> a game of <a href="https://www.mapyro.com/%ea%b4%91%eb%aa%85%ec%a3%bc%eb%b3%80-%ea%b0%80%ea%b9%8c%ec%9a%b4%ec%b6%9c%ec%9e%a5%ec%83%b5.html/" rel="nofollow">광명 출장마사지</a> chance. · <a href="https://drmcd.com/%ec%9d%98%ec%a0%95%eb%b6%80%ec%97%90-%eb%8c%80%ed%95%9c-%ec%9a%b0%ec%88%98%ed%95%9c%ec%b6%9c%ec%9e%a5%ec%95%88%eb%a7%88%eb%a6%ac%eb%b7%b0.html/" rel="nofollow">의정부 출장안마</a> Step 2: Look <a href="https://www.mapyro.com/%ec%84%b1%eb%82%a8%ec%b5%9c%ea%b3%a0%ec%9d%98%ec%b6%9c%ec%9e%a5%ec%83%b5%eb%b0%9b%ec%95%84%eb%b3%b4%ec%84%b8%ec%9a%94.html/" rel="nofollow">성남 출장안마</a> for the free spins on a slot machine, choose one of the slots <a href="https://www.jtmhub.com/%ec%a7%84%ec%a3%bc%ec%b6%9c%ec%9e%a5%ec%95%88%eb%a7%88%ec%9d%b8%ea%b8%b0-%ec%88%9c%ec%9c%84.html/" rel="nofollow">진주 출장샵</a> on the table. · Step 3: Turn the spinning
  • aarancadwell
  • | Mar 05 2022
  • | Reply
Play the Slots at Yoo Casino<br />Take advantage of our great promotions and get the best slots at Yoo Casino. <a href="https://drmcd.com/%ec%9a%b8%ec%82%b0%ea%b4%91%ec%97%ad%ec%b5%9c%ea%b3%a0%ec%8b%9c%ec%84%a4%ec%b6%9c%ec%9e%a5%ec%83%b5.html" rel="nofollow">울산광역 출장샵</a> Sign-up now <a href="https://www.mapyro.com/%ec%83%81%ec%a3%bc%ec%b5%9c%ec%83%81%ec%9d%98-%ea%b4%80%eb%a6%ac%ec%b6%9c%ec%9e%a5%ec%83%b5.html" rel="nofollow">상주 출장마사지</a> and start playing! <a href="https://www.jtmhub.com/%ec%82%ac%ec%b2%9c%ec%b5%9c%eb%8c%80%ea%b7%9c%eb%aa%a8%ec%b6%9c%ec%9e%a5%eb%a7%88%ec%82%ac%ec%a7%80.html" rel="nofollow">사천 출장마사지</a> Free Spins No Deposit <a href="https://www.jtmhub.com/%ec%a0%84%ec%a3%bc%ec%b5%9c%ea%b3%a0%ec%8b%9c%ec%84%a4%ec%b6%9c%ec%9e%a5%ec%95%88%eb%a7%88.html" rel="nofollow">전주 출장마사지</a> Required. <a href="https://www.mapyro.com/%ec%a0%9c%ec%b2%9c%ec%b5%9c%ec%83%81%ec%9d%98-%ea%b4%80%eb%a6%ac%ec%b6%9c%ec%9e%a5%eb%a7%88%ec%82%ac%ec%a7%80.html" rel="nofollow">제천 출장마사지</a>