Sunday, 13 August 2017

Quick RabbitMq using Docker

I needed a quick RabbitMq installation so I could play with MassTransit, the free open-source .Net message bus framework. Docker to the rescue. I was using the Docker Toolbox on Windows 10 Home.

First things first - RabbitMq is available on the Docker Store as a Docker image called rabbitmq. The documentation is reasonable and I decided I wanted RabbitMq installed with the management plugin. For this test I decided to leave the default RabbitMq username (guest) and password in place. I also elected to expose the default ports for the management plugin (15672) and the standard RabbitMq port (5672) to the host.

Having scanned the documentation the following Docker run command would seem to be in order:

docker run -d --hostname my-rabbit --name some-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:3-management

Note the two –p command line arguments exposing the ports to the host from the Docker container. So, time to crack open the Docker Quickstart Terminal and run the command.

SNAGHTMLf7f8e94

With the Docker container up-and-running I can now go to my local machine and access the RabbitMq management UI running on port 15672.

SNAGHTMLf80a65d

Cool! Looks like we’ve got RabbitMq running in a container.

A quick test application

I decided to run a quick test using a console application to check everything was working. Firstly, I set up a virtual host for the test in the management UI remembering to add the guest user to the virtual host.

SNAGHTMLf83a6cc

Then, using the RabbitMq .Net client I created the ‘Hello World’ application.

using System;
using System.Text;
using RabbitMQ.Client;

namespace RabbitMqTest
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                ConnectionFactory factory = new ConnectionFactory();
                factory.Uri = new Uri("amqp://guest:guest@192.168.99.100:5672/console-test");

                Console.WriteLine("Connecting...");
                IConnection conn = factory.CreateConnection();
                Console.WriteLine("Connected.");

                IModel model = conn.CreateModel();

                var exchangeName = "console-test-exchange";
                var queueName = "console-test-queue";
                var consoleTestRoutingKey = "console-test-routing-key";

                model.ExchangeDeclare(exchangeName, ExchangeType.Direct);
                model.QueueDeclare(queueName, false, false, false, null);
                model.QueueBind(queueName, exchangeName, consoleTestRoutingKey, null);

                byte[] messageBodyBytes = Encoding.UTF8.GetBytes("Hello, world!");
                model.BasicPublish(exchangeName, consoleTestRoutingKey, null, messageBodyBytes);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }
}

I ran the application and headed back into the RabbitMq management UI to check the results. Firstly, was the exchange created?

SNAGHTMLf8b041c

It was. And the queue?

SNAGHTMLf8c5e0f

Success again. You can see there’s one message ready too. By drilling in to the queue you can get messages in the management UI. Let’s see what we got.

SNAGHTMLf8dd03d

Bingo! So, all is well with RabbitMq.

The Sample-ShoppingWeb application

MassTransit has a sample application called Sample-ShoppingWeb which you can get from GitHub.

Firstly, I created a new virtual host in RabbitMq and added the guest user to it. I then made simple changes to the configuration to change the RabbitMqHost setting in the App.config and Web.config files of the TrackingService and Shopping.Web projects respectively.

SNAGHTML1002618c

I ran the example and added a few items to the cart using the Shopping.Web MVC application. Watched as the TrackingService picked up the items via RabbitMq. An examination of the RabbitMq management UI showed a bunch of new exchanges and two new queues.

Done. 


Docker recipes

This post is a quick aide-mémoire for basic command-line Docker operations. It’s well worth reading the Docker documentation for the real deal. I’ve been running Docker on Windows 10 Home – yes, Home – so I’ve had to use Docker Toolbox. I’ve run the commands listed here using the Docker Quickstart Terminal that comes with the Toolbox.

List containers

To list the all containers run the following command:

docker container ls

SNAGHTMLf550b66

See the docker container ls documentation.

Run a Bash shell on a container

To get access to a container using a Bash shell run the following command:

docker exec –it <container-name-here> bash

SNAGHTMLf58ed4c

Friday, 21 July 2017

Setting up SSH for BitBucket on Windows

Back to basics for me today. I’m rebuilding a machine and want to setup SSH to access my BitBucket account (I use BitBucket for my Git repositories). The new machine already has Git installed. I simply used Chocolatey to install Git.

You can skip to full instructions in the BitBucket help if you like.

Step 1 – Check the .ssh directory

The first step is to check that you’ve got an folder called .ssh in your home directory. If it’s missing you need to create it.

SNAGHTML27c673c3

Step 2 – Create the default identity

Run ssh-keygen to create the key. If this is a fresh install there won’t be a default key so you can just hit enter to accept the default name or ender a new one if you want. Enter the passphrase when prompted.

SNAGHTML27c76c2d

Step 3 – Create an SSH config file

Create a config file for SSH.

SNAGHTML27c81a4f

Open the file and edit it. Add the following:

Host bitbucket.org
 IdentityFile ~/.ssh/id_rsa


Step 4 – Update the .bashrc file

Check you’ve got a .bashrc file in your home directory. Create one if you don’t. Open the .bashrc file and edit it. Add the following:

#! /bin/bash 
eval `ssh-agent -s` 
ssh-add ~/.ssh/*_rsa

See also Enter RSA passphrase once when using Git bash.

Close and reopen GitBash. You’ll be prompted for the passphrase.

SNAGHTML27c90088

Step 5 - Configure BitBucket to use the new key

Go to your BitBucket account and navigate to your settings. Adding the key is easy. Follow the steps here.

SNAGHTML27cc8153

SNAGHTML27ce99f2

Check you can access BitBucket using the new key.

SNAGHTML27cf57a4

Done.

Thursday, 26 January 2017

Unscrambling a mess of .Net Core installations

I've had a variety of .Net Core installations on my laptop. The end result was .Net Core not working in Visual Studio 2015 anymore despite uninstalling and reinstalling .Net Core and associated Visual Studio tools. The problem was probably exacerbated by uninstallers not completing correctly and other sundary issues.

In a perfect world I would have paved the machine and started again but at this point that’s not practical. Working in VMs might also be an option but for now I just want a laptop with .Net Core up-and-runing.

Investigation

Firstly I decided to find out what was hanging around on the machine. I opened a command prompt and ran dotnet –version to find out.

2017-01-26 10_47_42-MINGW64__c_source (Admin)

So this is saying I’ve got version 1.0.0-beta-001598. That seems very old to me and something that should have gone ages ago.

Looking in Add/Remove Programs I see something different.

2017-01-26 10_48_16-Control Panel_Programs_Programs and Features

This suggests 2 other versions have been installed: 1.0.0 Preview2-003131 and 1.0.0 Preview2-003133. Hmm…

So, I had a look at the PATH environment variable on the machine and saw some interesting things. The following directories – that all seem related to .Net Core – were listed in this order:

  • c:\Program Files\dotnet\bin
  • c:\Program Files\dotnet
  • c:\Program Files\Microsoft DNX\Dnvm
  • c:\Users\username\.dnx\runtimes\dnx-coreclr-win-x86.1.0.0-rc1-update2\bin
  • c:\Users\username\.dnx\bin

 

Looking in the c:\Program Files\dotnet folder confirmed the installed SDKs but there was something odd. The dotnet.exe appeared in c:\Program Files\dotnet and in c:\Program Files\dotnet\bin. Running them from each location separately revealled different .Net Core versions.

2017-01-26 11_01_39-cmd (Admin)

Yep. Things are in a mess.

The c:\Users\username\.dnx\ diectory is also interesting. That isn’t used anymore. What’s in there I wonder?

2017-01-26 10_53_03-cmd (Admin)

Turns out it’s got the old – now redundant - dnvm application that gives a different version again. There’s a stack of other stuff in theer too. Sheesh, what a mess I’ve made.

Solution

My solution was to do the following:

  • Uninstall the .Net Core and VS Tooling using Add/Remove Programs.
  • Run dnvm uninstall from the old .dnx folder (probably not necessary but what the heck).
  • Manually delete the following directories (and contents):
    • c:\Program Files\dotnet
    • c:\Program Files\Microsoft DNX
    • c:\Users\username\.dnx
  • Remove the same directories as above (and/or sub directories) from both the user and environment $PATH.
  • Restart the machine (probably not necessary - belt and braces).
  • Installed the latest .Net Core SDK and Visual Studio 2015 Tools from here.

 

The result? Working .Net Core in Visual Studio!

There was a nice tidy c:\Program Files\dotnet folder with the dotnet.exe and a subfolder containing the SDKs. That’s it, no other folders required or present.

Thursday, 26 January 2017

Thursday, 12 January 2017

What is Enterprise Architecture as described by TOGAF 9.1?

 

What is Architecture?

The TOGAF documentation initially refers to the original version of ISO/IEC 42010:2007 (Systems and software engineering) which defines architecture in the following terms:

“The fundamental organization of a system, embodied in its components, their relationships to each other and the environment, and the principles governing its design and evolution.” [1] [2]

However, TOGAF defines an architecture as follows:

“1. A formal description of a system, or a detailed plan of the system at component level to guide its implementation
2. The structure of components, their inter-relationships, and the principles and guidelines governing their design and evolution over time” [2] [3]

What is an Enterprise?

An enterprise is defined as follows:

“The highest level (typically) of description of an organization and typically covers all missions and functions. An enterprise will often span multiple organizations.” [4]

What kinds of architecture are dealt with by TOGAF?

TOGAF deals with 4 kinds of architecture:

  • Business Architecture
    • defines the business strategy, governance, organization, and key business processes [2]
    • a description of the structure and interaction between the business strategy, organization, functions, business processes, and information needs [5]
  • Data Architecture
    • describes the structure of an organization's logical and physical data assets and data management resources [2]
    • a description of the structure and interaction of the enterprise's major types and sources of data, logical data assets, physical data assets, and data management resources [6]
  • Application Architecture
    • provides a blueprint for the individual applications to be deployed, their interactions, and their relationships to the core business processes of the organization [2]
    • a description of the structure and interaction of the applications as groups of capabilities that provide key business functions and manage the data assets [7]
  • Technology Architecture
    • describes the logical software and hardware capabilities that are required to support the deployment of business, data, and application services [2]
    • includes IT infrastructure, middleware, networks, communications, processing, standards, etc. [2]
    • a description of the structure and interaction of the platform services, and logical and physical technology components [8]

 

References