Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Affinity Dispatcher is a high-performance, low-latency message routing framework in Java. It routes messages to workers based on key affinity and supports multiple key types.

License

Notifications You must be signed in to change notification settings

ryntric/affinity-dispatcher

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Central LICENSE Maven CI pages-build-deployment

🚀 Affinity Dispatcher

Affinity Dispatcher is a high-performance, low-latency message routing framework in Java. It routes messages to workers based on key affinity and supports multiple key types.


📚 Table of Contents


Overview

The dispatcher uses a multiply-high scaling algorithm to map hash codes to routing nodes efficiently.

Features:

  • Lock-free internal channels (SPSC / MPSC)
  • Configurable worker count & routing nodes
  • Branchless and consistent key routing
  • Low-latency message handling
  • Atomic state management (started, non-started, terminated)

Key Components

🏗️ AffinityDispatcher<T>

Main dispatcher for routing messages to workers.

Supports: int, long, String, byte[] keys

Important Methods:

  • dispatch(String key, T value)
  • dispatch(int key, T value)
  • dispatch(long key, T value)
  • dispatch(byte[] key, T value)
  • start()
  • shutdown() 🛑

👷 Worker<T>

Worker thread consuming messages from its channel.

🗂️ RoutingNode<T>

Routing table node holding a reference to a worker and publishing messages.

📡 Channel<T>

Internal message queue:

  • SPSC – Single-producer, single-consumer
  • MPSC – Multi-producer, single-consumer

🛠️ Usage Example

Handler<Object> handler = (workerName, value) -> {
    System.out.println("Handled by " + workerName + ": " + value);
};
AffinityDispatcher<Object> dispatcher = new AffinityDispatcher<>("test", handler, DefaultHashCodeProvider.INSTANCE, Config.builder().build());
dispatcher.start();

for (int i = 0; i < 10_000_000; i++) {
    dispatcher.dispatch(UUID.randomUUID().toString(), i);
}

About

Affinity Dispatcher is a high-performance, low-latency message routing framework in Java. It routes messages to workers based on key affinity and supports multiple key types.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.