How to Make Akka.NET Programming Easier by Designing Events Well
In this blog post we’re going to cover some best practices you can use when designing domain events and objects intended to work with Akka.NET. If you follow these best practices you’ll run into fewer errors, clearer log messages, and a better extensibility experience.
Use Marker / Identity Interfaces Generously
This first tip is designed to make it easier to extend your messaging systems without having to manually update the
Receive<T> statements on a large number of actors.
Suppose I’m working the code from our new Akka.Cluster Workshop - in this application we have a large number of domain events for the purpose of trading stocks:
Bid- offer to buy N units of stock at a specific price point;
Ask- offer to sell N units of stock at a specific price point;
Match- the stock trading system has matched an
Askorder with a
Fill- some amount of a
Askorder has been filled by a
All of these events have several common identifiers and properties that can be really useful for routing, sharding, or distributing these messages:
- The stock ticker symbol (MSFT, TEAM, AMD, etc…);
- The id of the order; and
- They all represent live trading events happening as a result of trader activity - this is distinct from an event emitted by the exchange indicating what the newest “market price” for a specific ticker symbol is.
Well, in order to make my system more extensible and easier to debug I’m going to introduce some common marker interfaces - for instance, an
Tools for Akka.Cluster.Sharding Management and Akka.Remote Management
We introduced Petabridge.Cmd in 2017 to make it easy for Akka.NET users to deploy, monitor, and manage their Akka.NET applications. We have now expanded the capabilities of Petabridge.Cmd by introducing two new command palettes to further simplify the way you monitor your Akka.NET applications. The new command palettes will allow you to monitor your system connections with Petabridge.Cmd.Remote and allow you to obtain sharding information using Petabridge.Cmd.Cluster.Sharding.
If you have not heard of Petabridge.Cmd yet, please take a look at our introduction YouTube video for Petabridge.Cmd
- Description of Petabridge.Cmd.
- How Petabridge.Cmd works.
- How Petabridge.Cmd uses command palettes.
- Demo of setting up Petabridge.Cmd and the use of commands.
Let’s cover the 4 new commands that we have introduced with Petabridge.Cmd.Remote. These can be used with applications using Akka.Remote or Akka.Cluster:
- remote stats - allows you to see the number of Association and Disassociation events seen by the node running your Petabridge.Cmd.Host;
- remote connections - provides you with the number of active remote connections to the local host;
- remote tail - writes all of the connections and disconnections events out to the console until stopped via Control + C and;
- remote history - shows the connection events witnessed by the node. Can show up to 1,000 events.
We encourage you to give these commands a try in your application. Below you can see the output of some of the commands in our remote command palette. We ran the
remote connections on a cluster and you can see the connection of our host node to all of the remote nodes. We also ran our
remote history command with...
What's the difference between Akka.NET, Kafka, RabbitMQ, and other message-driven technologies? Can they work together?
A while back I created a thread on Twitter to attempt to explain the difference between Akka.NET and some other popular message-distribution and queuing technologies, such as Apache Kafka and RabbitMQ.
Common question I get from users who are just starting to look at @AkkaDotNET : why use something like Akka .NET and not Kafka / RabbitMQ? What's the differences between these two pieces of technology? Can they be used together? Or are they competing technologies?— Aaron Stannard (@Aaronontheweb) January 29, 2019
I’m going to cover that in some more detail in this post because it’s a common question asked by many developers who are just starting to look into Akka.NET.
Differences between Akka.NET, Kafka, RabbitMQ, and Other Messaging Systems
Message brokers, enterprise message buses, message queues, event hubs, and so on - for the sake of simplicity, which I’m certain will enrage developers in some corners of the Internet, I’m going to lump these technologies together into a single category: these are message distribution systems.
The manner in which they distribute messages varies and for our purposes those differences are totally immaterial (sorry, vendors.) The point is: producers write messages into these systems and the goal is, with varying degrees of reliability, concurrency, and asynchrony, to distribute these messages for processing to one or more downstream consumers.
Message distribution systems are transports - they aren’t involved in the act of creating or consuming messages. Only in delivering and routing these messages from their sources and to their destinations.
Where Akka.NET differs: Akka.NET actors are fundamentally message processing and message producing technologies.
Akka.NET actors are responsible for managing business state or executing commands, both of which occur when an actor receives a message.
Where the confusion occurs, however,...