Setup Azure Service bus

What is Azure Service Bus messaging?

Azure Service Bus messaging is an asynchronous messaging cloud platform that enables you to send data between decoupled systems. Azure Service bus is developed and provided by Microsoft.

Azure Service bus is hosted on Azure. There are different types of messaging built into Azure Service bus but for now and the purpose of this post I'm focused solely on Queues and the basic messaging we need to get started.

Pricing

There are 3 pricing levels for Azure Service bus. Each level comes with some added features.

Basic - €0.0422 per million operations

Standard - €8.433/mo for the First 12.5M Operations

  • Next 88M Ops (13M - 100M Ops) / Month €0.6746 per million operations
  • Next 2,400M Ops (100M - 2,500M Ops) / Month €0.4217 per million operations
  • Over 2,501M Ops / Month €0.1687 per million operations

Premium

Daily €18.77 fixed rate per Message Unit

As pointed out above we're focusing on Queues at the moment so I'm ignoring brokered connections and topics for the moment.

All prices for North Europe in EURO for more Azure Service Bus Pricing

Get Started

To get started we need to go to Azure Portal

On the left click new and search for "Service Bus" this will open the market place and let you select Service bus
Create Azure Service Bus

Select Service Bus, and then select Create.

Next we need to give it a name and resource group and stuff.

Define Service Bus

Select a name, Subscription and then Set the resource group to use an existing or to create a new one.

Also select the pricing tier you want to use.

And hit Create.

That's it your service bus is now being setup for use.

Service Bus up and running

Setup the Queue and access keys

So now we have our service bus created we need to create the queue. Under General select Queues

Create queue

Select Add Queue, and give it a name.

Create queue

We need to get the access keys so we can use the queue. Above queue select "Shared Access Policies" after a second a default "RootManageSharedAccessKey" will appear,

Open the "RootManageSharedAccessKey"

Azure Shared access keys

These keys you will need next so we can use this service bus queue.

What is Azure Service Bus messaging? Azure Service Bus messaging is an asynchronous messaging cloud platform that enables you to send data between decoupled systems. Azure Service bus is developed and provided by Microsoft. Azure Service bus is hosted on Azure. There are different types of messaging built into Azure…

Read More

Application Services Message bus

As our applications and services grow and we start to break more into Microservices a key part of building applications is Messaging. Being able to pass messages between the applications quickly becomes critical to our service.

Over the next few blog posts I'll look at getting started with different messaging systems and how to use them. It's not a compare it's a getting started in each of them.

Why do we need messaging

Messaging allows communication between applications. For example we create a user in our database and then create a message onto our message bus. Our email service is listening to the message bus. Gets the new message and sends the welcome email. We've now wired two applications to work together over a message bus.

Microservices

Microservices is a particular way of designing software applications as suites of independently deployable services. In a microservices world communication between applications has to be robust and scalable. Message buses provide a flexible solution to this. We can create services and deploy them in different places. You can even have services in different languages, once they can read the same message bus they can do what they need to do.

What next

Over the next few posts I'll introduce different Message bus services and providers.

As our applications and services grow and we start to break more into Microservices a key part of building applications is Messaging. Being able to pass messages between the applications quickly becomes critical to our service. Over the next few blog posts I'll look at getting started with different messaging…

Read More

ASP .NET Core RTM Roundup

As of this post in August 2016, .NET core is in RTM I wanted to round up a bunch of things as of now and update my earlier post on ASP .NET Core but also I intend to use this post as a way of gathering content I think is useful, I've made sure to keep things here that are about .NET core RTM or RC2 where noted.

Important note, this blog post serves as a collection of some things I've found on .NET core RTM. It will change as I add new things.

Roadmap Blog post from MSDN

Getting started

First and foremost and just to start us off right, we have getting started. The new docs site for ASP is brillant

Create an MVC Net Core web app in Visual studio.

Getting started with Visual Studio

Want to use the command line? Well you can do that now.

Simple as

mkdir aspnetcoreapp
cd aspnetcoreapp
dotnet new

Get started from the command line

Building stuff

Scott Hanselman walks through creating a small Web API in .NET Core in Exploring a minimal WebAPI with ASP.NET Core another from Scott where he jumps into Nancy FX Exploring a minimal WebAPI with .NET Core and NancyFX

David Paquette covers using View Components in ASP.NET core LOADING VIEW COMPONENTS FROM A CLASS LIBRARY IN ASP.NET CORE MVC

For more on View Components David has us covered with Goodbye Child Actions, Hello View Components

Chris Myers takes us into building a Web API that runs in Docker, it's a really great step by step guide Stateful Microservice with .NET Core, Docker, and PostreSQL

Laurent Kempe goes wild with .NET core in Docker on Azure Build, ship and run ASP.NET Core on Microsoft Azure using Docker Cloud

Jerrie Pelser gets into Tag helpers and using them in a web app Accessing the Request object inside a Tag Helper in ASP.NET Core

Joonas Westlin gives us a look using Azure AD in .NET Core ASP.NET Core 1.0 Azure AD Authentication

Matthew Jones with some dependency injection in ASP .NET core Getting Started with Dependency Injection in ASP.NET Core

More Dependency injection this time from Shawn Wildermuth ASP.NET Core Dependency Injection

Ben Cull shows how you can store session variables in ASP.​NET Core, and also use a backing store such as Redis or SQL Server Cache instead of the default in-memory implementation. Using Sessions and HttpContext in ASP.NET Core and MVC Core

This post on the ComponentOne blog is another in an ongoing series on how to build your own Tag Helper. TagHelpers : Authoring Nested TagHelpers in ASP.NET Core MVC

Jon Hilton shows how to Compile your changes on the fly with .NET Core Watch

Radu Matei has an Introduction to ASP.NET Core MVC API

Marius Schulz shows us how to go about Simulating Latency in ASP.NET Core

Ben Cull using Global Routes for ASP.NET Core MVC

Jürgen Gutsch how you can configure the length of time that static content such as Javascript files, images and stylesheets are cached on the client side. Add HTTP headers to static files in ASP.​NET Core

As of this post in August 2016, .NET core is in RTM I wanted to round up a bunch of things as of now and update my earlier post on ASP .NET Core but also I intend to use this post as a way of gathering content I think is…

Read More

ASP Web API Routing Basics

Web API has a default route of HOST/API/Controller but what if we don't want that. How do we change it? Well it's actually easy, so lets do it.

Routing in ASP Web API

Routing in Web API is very straight forward and if you have done any work in ASP MVC then it will be familiar it's just in a different place. Remember you can have WEB API and MVC co existing in the same web application. By having them in different routing tables it means you can change it as you want.

All source code is here

Routing Table

In the App_Start folder you will find WebApiConfig.cs you will find a method called register and you will see the default route

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

This is the default route, anything that comes in on API it will look for the {controller} name and pass the data there.

So lets change that, instead of using /api/ to pass it lets change it to /serversncode/ we do that by adding a new route

        config.Routes.MapHttpRoute(
            name: "ApiV2",
            routeTemplate: "serversncode/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

Now when we run the Web API we have two routes we can do the default /api/ or a /serversncode/

The routing here is the same as for MVC so if you have played with those routes these are the same.

Web API has a default route of HOST/API/Controller but what if we don't want that. How do we change it? Well it's actually easy, so lets do it. Routing in ASP Web API Routing in Web API is very straight forward and if you have done any work…

Read More

ASP Web API POST JSON

Prevouisly on Serversncode we created a WEB API that created Data into a Azure Table storage. This had a POST method that accepts the parameters, ASP WEB API.

But what if we wanted to pass the data in as part of a JSON. Well lets do that. Source code is here

First up lets create our Player Class, Last Time we created the PlayerEntity class this is for our table Storage but we don't want to pass that around, we want a player class so we can pass that into the POST method.

In Models create a new Class Player

public class Player
{
    public string Sport_VC { get; set; }
    public string Club_VC { get; set; }
    public string First_Name_VC { get; set; }
    public string Last_Name_VC { get; set; }
    public string Position_VC { get; set; }
}

To make a clear break from this work and the last post we're going to create a new WebAPI Controller called PlayerJController.

    [HttpPost]
    public string Post([FromBody] Player record)
    {
        string sResponse = "";

        // Create the entity with a partition key for sport and a row
        // Row should be unique within that partition
        PlayerEntity _record = new PlayerEntity(record.Sport_VC, sRow);

        _record.Sport_VC = record.Sport_VC;
        _record.First_Name_VC = record.First_Name_VC;
        _record.Last_Name_VC = record.Last_Name_VC;
        _record.Club_VC = record.Club_VC;
        _record.Position_VC = record.Position_VC;

        return sResponse;
    }

I've cleaned the code above of the work we do to create the Azure table etc. Just to keep it simple.

.NET will handle the heavy lifting for us. If we open Postman now and create a new POST call to our new API method.

Test API

  • Change it to a Post Method
  • Select Body, and RAW type out the JSON body
  • Change the Application type to "JSON (application/json)
  • Enter the URL localhost:999090/API/PlayerJ

That's it when you run that it will send the JSON into the API method and you can work with it to create the player entity and store it in Azure Table storage.

Prevouisly on Serversncode we created a WEB API that created Data into a Azure Table storage. This had a POST method that accepts the parameters, ASP WEB API. But what if we wanted to pass the data in as part of a JSON. Well lets do that. Source code is…

Read More