Jasper is a new messaging and command runner framework targeting Netstandard2 my shop has been building as a replacement for part of the old FubuMVC framework. I wrote about the general vision and rationale here.
Earlier today I made a v0.7.0 release of Jasper and its related extensions. The pace of development has kicked back up because we’re getting ready to start doing load and chaos testing with our QA folks later this week and we’re already transitioning some smaller, low volume systems to Jasper. The highlights this time are:
- A lot of optimization for the “cold start” time, especially if you’re using Jasper in combination with ASP.Net Core. I collapsed the ASP.Net Core support back to the core library, so this post is already obsolete.
- The integration with ASP.Net Core is a lot tighter. For example, Jasper is now using the ASP.Net Core logging under its covers, the ASP.Net Core IHostedService, and just generally plays nicer when used in combination with ASP.Net Core applications.
- Jasper now has some support for stateful sagas, but only with Marten-backed persistence. I’ll blog about this one soon, and there will be other saga persistence options coming fairly soon. Sql Server backed persistence at a bare minimum.
- Finer grained control over how certain message types are published
- Mild improvements to the Marten integration. Again, Jasper isn’t hard coupled to Marten and Postgresql, but it’s just been easy to prove out concepts with Marten first.
- More command line usages that I’m showing in the rest of this post;)
Command Line Integration
First off, let’s say that you have a simple Jasper application that listens for incoming messages at a designated port configured with this class:
public class SubscriberApp : JasperRegistry
// Listen for incoming messages via the
// built in, socket transport in a
// fire and forget way at port 2222
To run your Jasper application as a console application, you can use the Jasper.CommandLine library as a quick helper that also adds some diagnostic commands you may find helpful during both development and deployment time. Using your
SubscriberApp class above, you can bootstrap your application in a console application like this:
static int Main(string args)
Once that’s done, you can immediately run your application from the command line with
dotnet run, which would give you some output like this:
Running service 'SubscriberApp'
Application Assembly: Subscriber, Version=126.96.36.199, Culture=neutral, PublicKeyToken=null
Hosting environment: Production
Content root path: [the IHostedEnvironment.ContentRootPath value]
Hosted Service: Jasper.Messaging.MessagingActivator
Hosted Service: Jasper.Messaging.NodeRegistration
Listening for loopback messages
Listening for messages at [url]/messages
Listening for messages at [url]/messages/durable
Active sending agent to loopback://replies/
Active sending agent to loopback://retries/
[Message Type]: [Handler Type and Handler Method Name]
Now listening on: [listener Uri]
Application started. Press Ctrl+C to shut down.
Other than a little bit of contextual information, it’s about what you would get with the ASP.Net Core command line support. If you’re not familiar with the dotnet cli, you can pass command line arguments to your
Program.Main() method by using double dashes to separate arguments that apply to
dotnet run from the arguments that get passed into your main method. Using the Oakton library for parsing Linux style command arguments and flags, your Jasper application can also respond to other commands and optional flags.
Knowing all that, this:
dotnet run -- -v
dotnet run -- --verbose
will run your application with console and debug loggers, and set the minimum log level in the ASP.Net Core logging to “Debug.”
Alternatively, you can also override the log level by:
dotnet run -- --log-level Information
dotnet run -- -l Trace
where the value is one of the values in the LogLevel enumeration.
To override the environment your application is running under, you can use this flag:
dotnet run -- --environment Development
or use the “-e” short version of that.
So what, what else do you got?
You can run a Jasper application, but there’s actually quite a bit more. If you type
dotnet run -- ?, you can see the other available commands:
The “export-json-schema” and “generate-message-types” commands are from an extension library that allows you to export JSON schema documents for the known message types or generate C# classes with the necessary Jasper message type identity from JSON schema documents. The command line support is extensible, allowing you to add prepackaged commands from addon Nugets or even be exposed from your own application. I’m going to leave that to a later post or *gasp*, updated documentation.
Preview the Generated Code
If you read my earlier post on Jasper’s Roslyn-Powered “Special Sauce,” you know that Jasper internally generates and compiles glue code to handle messages or HTTP requests. To help troubleshoot applications or just to understand the interplay between message handlers and any configured middleware, you can use this command to either list out the generated code or export it to a file:
dotnet run -- code -f export.cs
Check out the IoC Container Configuration
As a long time IoC tool author and user, I’m painfully aware that people run into issues with service registrations being incorrect or using erroneous lifecycles. To help ease those issues, Jasper allows you to see the service registrations of your entire application with this command:
dotnet run -- services
This is just displaying the output of the Lamar WhatDoIHave() report, similar to StructureMap’s WhatDoIHave() functionality.
Validate the System
As part of deployment or maybe even local development, you can choose to just start up the application, run all the registered environment checks, and verify that all the known message handlers and HTTP routes can be successfully compiled — with oodles of ugly red textual output if any check along the way fails. That’s done with
dotnet run -- validate.
It’s admittedly kind of boring and I’m running out of time before I need to head home, but there is a
dotnet run -- subscriptions command that you can use to manage message subscriptions at deployment or build time that’s documented here.
I’ll get a decent, business facing example of Jasper’s stateful saga support.