Package com.tnsai.coordination.messaging
Class DistributedMessageBrokerFactory
java.lang.Object
com.tnsai.coordination.messaging.DistributedMessageBrokerFactory
SPI-based factory for discovering and creating
DistributedMessageBroker instances.
Implementations are discovered via META-INF/services/com.tnsai.coordination.messaging.DistributedMessageBroker.
Each implementation is identified by its DistributedMessageBroker.getType() value.
Usage
// Discover all available broker types
List<String> types = DistributedMessageBrokerFactory.availableTypes();
// -> ["redis", "nats"]
// Create a specific broker
DistributedMessageBroker broker = DistributedMessageBrokerFactory.create("redis");
broker.connect(Map.of("host", "localhost"));
- Since:
- 0.2.3
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionReturns the types of all available brokers discovered via SPI.static DistributedMessageBrokerCreates a distributed message broker by type.static booleanisAvailable(String type) Checks whether a broker type is available.
-
Method Details
-
create
Creates a distributed message broker by type.- Parameters:
type- the broker type (e.g., "redis", "kafka")- Returns:
- the broker instance
- Throws:
NoSuchElementException- if no broker of the given type is registered
-
availableTypes
Returns the types of all available brokers discovered via SPI.- Returns:
- list of broker type names
-
isAvailable
Checks whether a broker type is available.- Parameters:
type- the broker type to check- Returns:
- true if a broker of this type is registered
-