Wednesday, 15 November 2017

Enterprise Service Bus libraries for .NET – MassTransit

One in a series of posts giving a quick overview of ESB libraries for .NET

MassTransit is an open-source library which apparently began as a response to some perceived deficiencies in the version of NServiceBus that was around in 2007. The project did a major rewrite in 2014, introducing async support and switching from MSMQ to RabbitMQ as the preferred transport.

Messages

Messages are POCO classes. There is no requirement to inherit from any base class or implement a specific interface.

Publishing

http://masstransit-project.com/MassTransit/usage/producing-messages.html

Messages are published using IPublishEndpoint, which is provided by ConsumeContext for consumers or by the IBus interface

public async Task NotifyOrderSubmitted(IPublishEndpoint publishEndpoint)
{
    await publishEndpoint.Publish<OrderSubmitted>(new
    {
        OrderId = "27",
        OrderDate = DateTime.UtcNow,
    });
}

Subscribing

http://masstransit-project.com/MassTransit/usage/message-consumers.html

A subscribing class (or consumer) implements the IConsumer<T> interface.
public class UpdateCustomerConsumer :
    IConsumer<UpdateCustomerAddress>
{
    public async Task Consume(ConsumeContext<UpdateCustomerAddress> context)
    {
        await Console.Out.WriteLineAsync($"Updating customer: {context.Message.CustomerId}");

        // update the customer address
    }
}

A consumer needs to be connected to an endpoint to receive messages

var busControl = Bus.Factory.CreateUsingRabbitMq(cfg =>
{
    var host = cfg.Host(new Uri("rabbitmq://localhost/"), h =>
    {
        h.Username("guest");
        h.Password("guest");
    });

    cfg.ReceiveEndpoint(host, "customer_update_queue", e =>
    {
        e.Consumer<UpdateCustomerConsumer>();
    });
});

Tuesday, 14 November 2017

Enterprise Service Bus libraries for .NET – NServiceBus

One in a series of posts giving a quick overview of ESB libraries for .NET

Originally an open-source library developed by Udi Dahan, the licensing was changed after version 2 to put it on a more commercial footing, and the software is now developed and supported by Udi’s company – Particular Software. The source code remains on Github.

NServiceBus is a tried and tested library. It has grown a lot since it's humble beginnings and now is once part of a suite of tools and libraries for building distributed applications. It's no surprise that Udi Dahan just happens to be highly regarded as an expert in distributed software architecture.

https://docs.particular.net/nservicebus/messaging/publish-subscribe/publish-handle-event

Messages

Messages need to either implement a marker interface or use defined conventions.
namespace Domain.Messages
{
  public class UserCreatedEvent : IEvent
  {
    public string Name { get; set; }
  }
}
Or
var conventions = endpointConfiguration.Conventions();

conventions.DefiningEventsAs(
 type =>

     {
       return type.Namespace == "MyNamespace.Messages.Events";
 });

Publishing

You can publish an event from within another handler or when you create an endpoint.
This example shows publishing an event from an endpoint:

var endpointInstance = await Endpoint.Start(endpointConfiguration)
    .ConfigureAwait(false);
    await endpointInstance.Publish(new MyEvent())
      .ConfigureAwait(false);

Subscribing

To handle an event, implement IHandleMessages<T>

public class UserCreatedHandler : IHandleMessages<UserCreatedEvent>
{
  public Task Handle(UserCreatedEvent message, IMessageHandlerContext context)
  { … }
}

NServiceBus will automatically locate handlers by looking for implementations of IHandleMessages<T>



Sunday, 5 November 2017

Enterprise Service Bus libraries for .NET

As a software application becomes larger, you may want to break it into separate parts, both to manage complexity but also to aid scalability. But if you break an application apart, how will the separate parts communicate? One approach is to employ messaging using a publish/subscribe (pub/sub) bus.

A few years ago, I worked on an application that used NServiceBus just for this purpose, but I thought it would be useful to survey the .NET landscape to find out what’s available today.

Here’s a summary of the libraries I’ll be looking at over the next few blog posts:

Name

URL

Transports

Minimum Framework

License

Dependencies

NServiceBus v6

https://docs.particular.net/nservicebus

Azure Service Bus, In-memory?, MSMQ, RabbitMQ, SQL Server

4.5.2

Commercial

-

MassTransit

http://masstransit-project.com/

Azure Service Bus, In-memory, RabbitMQ

4.5(.2?)

Apache 2.0

GreenPipes (>= 1.2.0)

NewId (>= 3.0.1)

Newtonsoft.Json (>= 10.0.3)

Newtonsoft.Json.Bson (>= 1.0.1)

NimbusAPI

https://github.com/NimbusAPI/Nimbus

Azure Service Bus

4.5

MIT

Microsoft.WindowsAzure.ConfigurationManager (= 2.0.3) Nimbus.InfrastructureContracts (>= 2.0.0.98)

Nimbus.MessageContracts (>= 2.0.0.98)

WindowsAzure.ServiceBus (>= 2.1.3 && <= 2.1.4)

Shuttle.Esb

http://shuttle.github.io/shuttle-esb/

MSMQ, RabbitMQ, SQL Server

4.0?

BSD 3

Shuttle.Core.Infrastructure (>= 8.0.6)

Rebus

https://github.com/rebus-org/Rebus

Azure Service Bus, MSMQ, RabbitMQ

4.5

MIT

Newtonsoft.Json (>= 9.0.1)

These libraries range from the relatively simple and tightly focused to the complete ‘enterprise-level’ configurable, extensible and/or fully supported.

Some of these libraries distinguish between an ‘event’ (notify subscribers that something has happened) and a ‘command’ (tell subscribers that they should perform an action). Some support long-running business processes, often known as ‘sagas’. Some support distributed transactions. Some use dependency injection and can integrate with an inversion-of-control container.

And because the feature sets vary so widely, I’ll just be highlighting how each library implements publishing an ‘event’ message, and how you subscribe to these messages.

Tuesday, 17 October 2017

Conditionally format rows in Excel depending on date range

Sometimes I get asked Excel questions. This is one of those times!

Given a spreadsheet with rows that contain a start and finish date, format the rows in the past, present and future in different colours, so that it looks like this:

Spreadsheet showing rows with different colours

I initially tried using a formula with Excel’s Conditional Formatting feature. Despite this being the recommended solution in some search results, I just found it set the one format for all the rows – not what I wanted. This post by Joseph D’Emanuele put me on the right track.

Here’s what I ended up doing:

  1. Add a new column next to your existing data
    Spreadsheet with extra Status column added
  2. In the first cell of this new column, insert the formula
    =IF(B2 < TODAY(), "Past", IF(A2 > TODAY(), "Future", "Current"))
  3. Copy this formula down to the remaining rows. eg.
    Spreadsheet with Status column populated
  4. Now select all the rows you want to format (for me that’s A2:D5)
  5. On the Home menu tab, select Conditional Formatting, then Manage Rules
  6. You will add 3 rules – one for each status.
  7. Click New Rule
  8. Select Use a formula to determine which cells to format
  9. In Format values where this formula is true, enter =INDIRECT("D" &ROW()) = "Future"
  10. Click Format and choose the desired formatting to apply for Future dates
  11. Click OK and repeat adding new rules for “Current” and “Past”
  12. You should end up with something like this:
    Excel's Conditional Formatting Rules Manager dialog box
  13. Click OK and you should have rows formatted different colours depending on whether the start/finish date is in the past, current or in the future!
  14. You can optionally choose to hide the Status row if you’d rather not see it all the time.

Note that the formula in the conditional formatting (=INDIRECT("D" &ROW()) = "Future") is hard-coded to the column – “D” in my case. If you move data around, you’ll need to update this to refer to the new column letter.

Friday, 1 September 2017

On the NBN

We switched over to the NBN at home a couple of months ago. Unfortunately since the last change of Government in Australia, it appears that all NBN rollouts are getting fibre to the node (FTTN) rather than original plan of fibre to the premises (FTTP). So with the node servicing our neighbourhood being a fair distance from our house, it looks like the best we can expect for the foreseeable future is ~40MB. That is a 4x increase on what we used to get with ADSL2+, but it is a shame we can’t get the full 100MB if we wanted to pay for it.

40MB isn’t too bad – I know of others that are only getting 20 (and there’s stories of some that switch over from ADSL to get a slower speed than what they used to have). Just seems a lost opportunity that if everyone had got fibre, I’m sure that would be capable of being upgraded in the future to even beyond 100MB.

Wednesday, 30 August 2017

ShaggyMax screen protectors

My old laptop ended up getting a really scratched display. The keyboard obviously had been rubbing against the glass for a while, which was a shame. I think this was made worse because the only thing separating them was two rubber feet that had come loose after a few years.

My new laptop has a different design with a small rubber strip that goes all the way around the edge, which seems to do a better job. Nevertheless, I did want to get something that would help protect the display and reduce the chance of scratches.

A bit of Googling came up with a few options. A call out to Twitter ended up with an in-person response from Ryan showing me he’d got a ShaggyMax-brand protector for his brand new 9560 (the newer version of my 9550).

That was good enough for me, so I’ve now got my own!

I bought a 15.4” Laptop Screen Protector. You can buy them through Amazon, or direct from their website. Here’s what it looks like on my laptop:


Laptop with screen protector covering keyboard

It’s a microfibre cloth that is thin enough that it doesn’t interfere with closing the lid, but hopefully will be thick enough to softly cushion and protect the glass. So far, so good.

Saturday, 26 August 2017

NDC Sydney 2017

Delegate badgeMy second time attending NDC Sydney, and this was extra special as I’d been accepted as a speaker. I was excited and pretty nervous!

I flew over Tuesday evening. It was quite windy with a fair bit of turbulence on the flight. A decent tailwind meant even though we left Adelaide late, we still got into Sydney on time.


Wednesday

Jennifer MarsmanThe conference kicked off with a keynote from Jennifer Marsman talking about using EEG and Machine Learning to perform lie detection (on her husband!). Not sure about the lie detection, but I do like the application of EEG to enable things like controlling a wheelchair, and it was useful to learn about the different kinds of algorithms and models you used for different types of problems.

Barry DorransBarry Dorrans walked through a bunch of security vulnerabilities that had been discovered in .NET. Some subtle causes and a few things to watch out for in your own code.

Edith HarbaughEdith Harbaugh gave a good overview of using feature flags. She is from Launch Darkly, a company that provides ‘feature flags as a service’, though her talk was more general. One point she made was that feature flags can be dynamic – something that can be changed at runtime, not just a config setting that is set at startup.

Damian EdwardsDamian Edwards raced through what’s new in ASP.NET Core. This is looking pretty good.

Bart De SmetBart De Smet is a guru of .NET and CLR internals. I've watched some of his Pluralsight courses already. This talk on C# internals was fascinating.

20170816_062053378_iOSFilip Ekberg dug into asynchronous programming.

20170816_074407961_iOSRounding out the day with Jimmy Bogard doing CI with Azure.
20170816_103047694_iOSWednesday evening there was a cruise on Sydney harbour. It was a little chillier than the last time I’d been out, but nice food and great to socialise with other attendees.

Thursday

20170816_230056563_iOSFirst thing Michele Bustamante stepped through using Docker.


Then it was my talk on using Chocolatey and Boxstarter! All my demos went off without a hitch and there were lots of questions from the audience. I think the early attendees appreciated the bonus chocolate frogs too.
Thanks to Ben for coming along and being a friendly face in the front row (and taking the photo!)

I hung around because Bart De Smet was up after me diving in to a bunch of areas of .NET to watch out for when you really care about performance.

Steve SandersonSteve Sanderson showed off some nice options available now in ASP.NET Core.

Richard CampbellThe one and only Richard Campbell with a history lesson about .NET. Informative and entertaining.

Dina GoldshteinDina Goldshtein on self-monitoring apps. Some interesting ways to do logging and diagnostics.

Finally a bit more Michelle Bustamante with more Docker – this time looking at some of the orchestration tools.

Thursday evening there was a social evening, including a bunch of pretty funny “short stories about failure” from some of the speakers. Some people partied on late into the night, but I retired early.

Friday

Nick BlumhardtNick Blumhardt gave a great talk introducing SeriLog and structured logging.

Kylie HuntKylie Hunt talked about dealing with problem bosses. A mix of good suggestions and sharing personal experiences.
Maybe I’m just an old fuddy-duddy, but personally I’m less impressed by speakers at conferences that need a swear jar.

Laura Bell Laura Bell had some good content on building in security.

Cosmo robot with Lars KlintLars Klint did a really interesting talk about Cosmo – a little programmable robot.
Jimmy PelletierLast talk I caught was from Jimmy Pelletier on how his team introduced micro services into their architecture.

There was the option of attending PubConf after the main conference had finished, but I’d already made plans to catch up with some old Adelaide friends who are now living in Sydney. It was really great to spend Friday evening and Saturday with them before my flight home in the late afternoon.

Here’s a pretty waterfall that I saw on Saturday when we went out for a walk. It's been dry in Sydney recently, so imagine what it would be like after a bit of rain.
Waterfall

All in all, again NDC Sydney didn’t disappoint and I can only hope it continues to grow and get better next year. There were quite a few times where I was spoiled for choice. I'll be looking forward to catching up on missed sessions when the recordings are published in a few weeks. It was great to see the Adelaide contingent growing from 2 last year to 9 (that I know of). The word is getting out that this is THE developer conference you should attend!