feat: add Microservices Bulkhead pattern (#3228) (#3597)

* feat: add Microservices Bulkhead pattern (#3228)

* fix: cancel queued calls on bulkhead shutdown

Shutdown now cancels the queued futures so callers do not hang, a shutdown racing a submit is no longer counted as a rejection, and interrupted inventory checks are logged. The class diagram is a rendered PNG.

---------

Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com>
This commit is contained in:
DoksanbirandIlkka Seppälä authored and GitHub committed 2026-09-13 09:53:54 +03:00
1 parent dd24a29f80
commit 4cabb204f2
15 files changed
+1352

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

@@ -0,0 +1,53 @@
@startuml
package com.iluwatar.bulkhead {
interface RemoteService {
+ call(request : String) : String {abstract}
}
class Bulkhead {
- name : String
- maxConcurrentCalls : int
- maxQueueSize : int
- executor : ThreadPoolExecutor
- rejectedCalls : AtomicLong
+ Bulkhead(name : String, maxConcurrentCalls : int, maxQueueSize : int)
+ submit(task : Callable<T>) : Future<T>
+ getName() : String
+ getMaxConcurrentCalls() : int
+ getMaxQueueSize() : int
+ getActiveCalls() : int
+ getQueuedCalls() : int
+ getRejectedCalls() : long
+ shutdown() : void
+ close() : void
}
class BulkheadFullException {
- bulkheadName : String
+ BulkheadFullException(bulkheadName : String)
+ getBulkheadName() : String
}
class PaymentService {
- latency : Duration
+ PaymentService(latency : Duration)
+ call(request : String) : String
}
class InventoryService {
+ InventoryService()
+ call(request : String) : String
}
class App {
- PAYMENT_LATENCY : Duration {static}
- WAIT_TIMEOUT : Duration {static}
+ App()
+ main(args : String[]) : void {static}
}
}
Bulkhead ..|> AutoCloseable
BulkheadFullException --|> RuntimeException
PaymentService ..|> RemoteService
InventoryService ..|> RemoteService
Bulkhead ..> BulkheadFullException
App ..> Bulkhead
App ..> PaymentService
App ..> InventoryService
App ..> BulkheadFullException
@enduml