Thursday, January 30, 2014

EasyNetQ: Publishing Non-Persistent Messages

logo_design_150

In AMQP, buried in the basic.properties object that gets sent along with each published message, there is a delivery_mode setting. You can set it to either ‘persistent’ (1), or ‘non-persistent’ (2). It controls whether a message is persisted to disk or not. In the AMQP spec:

“The server SHOULD respect the persistent property of basic messages and SHOULD make a best-effort to hold persistent basic messages on a reliable storage mechanism.”

Of course it’s pointless setting delivery_mode to ‘persistent’ if you’re not publishing to a durable queue.

By default EasyNetQ sets delivery_mode to persistent (1) when calling IBus.Publish. We make the assumption that people would want this safe behaviour out-of-the-box. However, it does introduce a performance hit, so if you don’t care about losing messages in the case of a server restart you should be able to change this behaviour.

From version 0.26.3, EasyNetQ has a new boolean connection string parameter ‘persistentMessages’. By default it is set to true, but if you don’t need persistent messages, but do need high performance, set it to false:

vas bus = RabbitHutch.CreateBus("host=localhost;persistentMessages=false");

This setting has no effect on the advanced API (IAdvancedBus) where you have access to basic.properties and are free to set delivery_mode on a message by message basis.

Tuesday, January 21, 2014

In Praise of TestDriven.NET

I’ve been using TestDriven.NET by Jamie Cansdale for quite a few years now. Ostensibly it’s a unit test runner, but that is not the real reason why you should use it. The killer feature, the one that will give you developer super powers, is the ability to run any arbitrary code under the cursor.

TestDriven allows you to run individual unit tests simply by placing the cursor within the test method and running the command ‘RunTests’ (I have this mapped to the F8 key - who uses bookmarks anyway?) The really cool thing is that the method doesn’t need to be attributed as a unit test, it can be any arbitrary method. Any return value from the method is written to the Visual Studio output console, as are any Console.WriteLine() or Console.Write() statements. This gives you immediate feedback on any code with a single keystroke.

 TestDriven

Why is this awesome? The key to productive software development is reducing latency; the cycle time between an action and its results. That’s why continuous integration and continuous delivery are such huge wins. When you’re coding, the quicker you can try a quick experiment and see the results, the more productive you will be. The big problem with compiled languages like C, C++, Java, and C# is that the compilation cycle acts as huge barrier to iteration. I still remember with horror how I used to write some code, launch my application, navigate to where the feature would be exercised (taking care to enter the correct parameters of course) and then watch it fail. And then I’d repeat the same tedious cycle over and over again. That’s one of the main reasons why .NET developers spend so much time stepping through code in the (admittedly excellent) debugger, because it’s hard otherwise to know how the last few lines of code you wrote are executing. Now I run code continuously without launching anything. Simply write a function, F8, iterate. It’s so much more productive.

I know fellow developers who use other tools as a scratchpad for iterative experiments. LinqPad is very popular and ScriptCS is deservedly getting a lot of attention. But TestDriven has a huge advantage over these because it works inside your Visual Studio environment. There’s no need to copy and paste your experiment into your application, you iterate in place and in the context of your existing code.

Give it a try. I’ve found it a game  changer for C# development. It’s a pretty good test runner too.

Thursday, January 02, 2014

The Geek Christmas Quiz 2013: The Answers!

Here are the answers to this year’s Geek Christmas Quiz.

What does this acronym stand for? (one point per correct answer)
    1. AWS – Amazon Web Services
    2. SQL – Structured Query Language
    3. NATO – North Atlantic Treaty Organization
    4. GNU – GNU is Not Unix
    5. SCSI – Small Computer Serial Interface
    6. HTML – Hyper Text Markup Language
    7. HTTP – Hyper Text Transfer Protocol
    8. ReST – Representational State Transfer
    9. NASA – National Aeronautics and Space Administration
    10. RAF – Royal Air Force

Name that computer (one point for the model, another for the company/inventor)

NeXT Cube / NeXT Apple II / Apple Difference Engine / Babbage
IBM PC / IBM Macintosh / Apple ZX Spectrum / Sinclair
System 360 / IBM Colossus / Tommy Flowers PlayStation / Sony

Name that programming language (one point for each correct answer)

  1. BASIC
  2. C#
  3. C
  4. F#
  5. Python
  6. T-SQL
  7. Bash
  8. Lisp/Scheme/Clojure
  9. Haskell

Science fiction (one point for each correct answer)

    1. "These are not the droids you are looking for" (what film?) – Start Wars IV
    2. "Open the pod bay doors please HAL" (what film, or book?) – 2001 A Space Odyssey
    3. Who wrote Rendezvous with Rama? – Arthur C Clarke
    4. What spaceship uses dilithium crystals – USS Enterprise
    5. what does the acronym CREW in Iain Bank's culture novels mean when referring to weapons - Coherent Radiation Emission Weapon
    6. Name 3 futurama characters - http://en.wikipedia.org/wiki/List_of_Futurama_characters
    7. Who wrote the 3 laws of robotics? – Isaac Asimov
    8. What is the first law of robotics? – “A robot may not injure a human being or, through inaction, allow a human being to come to harm”
    9. Who is the leader of the Daleks? - Davros
    10. Directive? (which film?) – Wall-E

Science (one point for each correct answer)

    1. 1 degree fahrenheit is a different size to 1 degree centigrade which means they must cross at some point. At what temperature are both scales the same? - -40.
    2. When and where was the first cell in your body created? - The egg that created you was formed inside of your mother’s fetus while she was inside of your grandmother’s womb.
    3. What is the device which blends air and fuel in an internal combustion engine called? – Carburettor.
    4. What was the name of the first hydrogen (thermonuclear) bomb test? – Mike.
    5. What is special about Sirius, the Dog Star? – It is the brightest star in the night sky.
    6. What year did the last man land on the moon? – 1972 (Apollo 17)
    7. Who invented the jet engine? – Frank Whittle.
    8. In trigonometry what is calculated by dividing the adjacent by the hypotenuse? - Cosine
    9. Which part of the Earth lies between the outer core and the crust? – The mantle.
    10. Where in the body are alveoli to be found? – The lungs.

Name that cartoon character (one point for each correct answer)

Lisa (Simpsons) Iron Man Fone Bone
Denis the Menace Tom & Jerry Kiki (Kiki’s Delivery Service)
Pointy Haired Boss Professor Calculus Dan Dare