Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ private synchronized AuthKeyStorageProvider getStorageProvider() {
providers.size(),
providers.stream().map(AuthKeyStorageProvider::name).toList());

storageProvider = selectProvider(providers, configuredStorageProvider.orElse(null), "storage");
storageProvider = ProviderSelection.select(
providers,
configuredStorageProvider.orElse(null),
"storage",
AuthKeyStorageProvider::name,
AuthKeyStorageProvider::priority,
AuthKeyStorageProvider::isAvailable);

return storageProvider;
}
Expand All @@ -178,7 +184,13 @@ private synchronized Optional<AuthKeyCacheProvider> getCacheProvider() {
providers.stream().map(AuthKeyCacheProvider::name).toList());

try {
cacheProvider = selectProvider(providers, configuredCacheProvider.orElse(null), "cache");
cacheProvider = ProviderSelection.select(
providers,
configuredCacheProvider.orElse(null),
"cache",
AuthKeyCacheProvider::name,
AuthKeyCacheProvider::priority,
AuthKeyCacheProvider::isAvailable);

// Inject Redis data source if this is the Redis provider
if (cacheProvider instanceof RedisAuthKeyCacheProvider redisProvider && redisDataSource.isPresent()) {
Expand All @@ -193,20 +205,4 @@ private synchronized Optional<AuthKeyCacheProvider> getCacheProvider() {
return Optional.empty();
}
}

private <T> T selectProvider(List<? extends T> providers, String configured, String type) {
return ProviderSelection.select(
providers,
configured,
type,
provider -> provider instanceof AuthKeyStorageProvider p
? p.name()
: ((AuthKeyCacheProvider) provider).name(),
provider -> provider instanceof AuthKeyStorageProvider p
? p.priority()
: ((AuthKeyCacheProvider) provider).priority(),
provider -> provider instanceof AuthKeyStorageProvider p
? p.isAvailable()
: ((AuthKeyCacheProvider) provider).isAvailable());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,14 @@ private synchronized RoleStorageProvider getStorageProvider() {
providers.size(),
providers.stream().map(RoleStorageProvider::name).toList());

storageProvider = selectProvider(providers, configuredStorageProvider.orElse(null));

return storageProvider;
}

private RoleStorageProvider selectProvider(List<RoleStorageProvider> providers, String configured) {
return ProviderSelection.select(
storageProvider = ProviderSelection.select(
providers,
configured,
configuredStorageProvider.orElse(null),
"role storage",
RoleStorageProvider::name,
RoleStorageProvider::priority,
RoleStorageProvider::isAvailable);

return storageProvider;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,13 @@ private synchronized StorageRepositoryProvider getRepositoryProvider() {
providers.size(),
providers.stream().map(StorageRepositoryProvider::name).toList());

repositoryProvider = selectProvider(providers, configuredRepositoryProvider.orElse(null), "repository");
repositoryProvider = ProviderSelection.select(
providers,
configuredRepositoryProvider.orElse(null),
"repository",
StorageRepositoryProvider::name,
StorageRepositoryProvider::priority,
StorageRepositoryProvider::isAvailable);

return repositoryProvider;
}
Expand All @@ -169,7 +175,13 @@ private synchronized Optional<ConfigurationCacheProvider> getCacheProvider() {
providers.stream().map(ConfigurationCacheProvider::name).toList());

try {
cacheProvider = selectProvider(providers, configuredCacheProvider.orElse(null), "cache");
cacheProvider = ProviderSelection.select(
providers,
configuredCacheProvider.orElse(null),
"cache",
ConfigurationCacheProvider::name,
ConfigurationCacheProvider::priority,
ConfigurationCacheProvider::isAvailable);
cacheProviderResolved = true;
return Optional.of(cacheProvider);
} catch (StorageProviderException e) {
Expand All @@ -178,20 +190,4 @@ private synchronized Optional<ConfigurationCacheProvider> getCacheProvider() {
return Optional.empty();
}
}

private <T> T selectProvider(List<? extends T> providers, String configured, String type) {
return ProviderSelection.select(
providers,
configured,
type,
provider -> provider instanceof StorageRepositoryProvider p
? p.name()
: ((ConfigurationCacheProvider) provider).name(),
provider -> provider instanceof StorageRepositoryProvider p
? p.priority()
: ((ConfigurationCacheProvider) provider).priority(),
provider -> provider instanceof StorageRepositoryProvider p
? p.isAvailable()
: ((ConfigurationCacheProvider) provider).isAvailable());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,13 @@ private synchronized TranslationConfigStorageProvider getStorageProvider() {
providers.size(),
providers.stream().map(TranslationConfigStorageProvider::name).toList());

storageProvider = selectProvider(providers, configuredStorageProvider.orElse(null), "storage");
storageProvider = ProviderSelection.select(
providers,
configuredStorageProvider.orElse(null),
"translation config storage",
TranslationConfigStorageProvider::name,
TranslationConfigStorageProvider::priority,
TranslationConfigStorageProvider::isAvailable);
return storageProvider;
}

Expand All @@ -191,7 +197,13 @@ private synchronized Optional<TranslationConfigCacheProvider> getCacheProvider()
providers.stream().map(TranslationConfigCacheProvider::name).toList());

try {
cacheProvider = selectProvider(providers, configuredCacheProvider.orElse(null), "cache");
cacheProvider = ProviderSelection.select(
providers,
configuredCacheProvider.orElse(null),
"translation config cache",
TranslationConfigCacheProvider::name,
TranslationConfigCacheProvider::priority,
TranslationConfigCacheProvider::isAvailable);

// Inject Redis data source if available
if (cacheProvider instanceof RedisTranslationConfigCacheProvider redisCacheProvider) {
Expand All @@ -211,20 +223,4 @@ private synchronized Optional<TranslationConfigCacheProvider> getCacheProvider()
return Optional.empty();
}
}

private <T> T selectProvider(List<? extends T> providers, String configured, String type) {
return ProviderSelection.select(
providers,
configured,
"translation config " + type,
provider -> provider instanceof TranslationConfigStorageProvider p
? p.name()
: ((TranslationConfigCacheProvider) provider).name(),
provider -> provider instanceof TranslationConfigStorageProvider p
? p.priority()
: ((TranslationConfigCacheProvider) provider).priority(),
provider -> provider instanceof TranslationConfigStorageProvider p
? p.isAvailable()
: ((TranslationConfigCacheProvider) provider).isAvailable());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import aussie.adapter.out.ProviderSelection;
import aussie.core.port.out.ApiKeyRepository;
import aussie.core.port.out.AuthKeyCache;
import aussie.core.port.out.StorageHealthIndicator;
Expand Down Expand Up @@ -84,17 +85,26 @@ private void setCacheProviderResolved(AuthKeyStorageProviderLoader loader) throw
private Object invokeSelectProvider(
AuthKeyStorageProviderLoader loader, java.util.List<?> providers, String configured, String type)
throws Exception {
final var method = AuthKeyStorageProviderLoader.class.getDeclaredMethod(
"selectProvider", java.util.List.class, String.class, String.class);
method.setAccessible(true);
try {
return method.invoke(loader, providers, configured, type);
} catch (java.lang.reflect.InvocationTargetException e) {
if (e.getCause() instanceof RuntimeException re) {
throw re;
}
throw e;
if ("storage".equals(type)) {
@SuppressWarnings("unchecked")
final var storageProviders = (java.util.List<AuthKeyStorageProvider>) providers;
return ProviderSelection.select(
storageProviders,
configured,
type,
AuthKeyStorageProvider::name,
AuthKeyStorageProvider::priority,
AuthKeyStorageProvider::isAvailable);
}
@SuppressWarnings("unchecked")
final var cacheProviders = (java.util.List<AuthKeyCacheProvider>) providers;
return ProviderSelection.select(
cacheProviders,
configured,
type,
AuthKeyCacheProvider::name,
AuthKeyCacheProvider::priority,
AuthKeyCacheProvider::isAvailable);
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import aussie.adapter.out.ProviderSelection;
import aussie.core.port.out.RoleRepository;
import aussie.core.port.out.StorageHealthIndicator;
import aussie.spi.RoleStorageProvider;
Expand All @@ -39,10 +40,13 @@ private void setStorageProvider(RoleStorageProviderLoader loader, RoleStoragePro

private RoleStorageProvider invokeSelectProvider(
RoleStorageProviderLoader loader, List<RoleStorageProvider> providers) throws Exception {
final var method =
RoleStorageProviderLoader.class.getDeclaredMethod("selectProvider", List.class, String.class);
method.setAccessible(true);
return (RoleStorageProvider) method.invoke(loader, providers, null);
return ProviderSelection.select(
providers,
null,
"role storage",
RoleStorageProvider::name,
RoleStorageProvider::priority,
RoleStorageProvider::isAvailable);
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import aussie.adapter.out.ProviderSelection;
import aussie.core.port.out.ConfigurationCache;
import aussie.core.port.out.ServiceRegistrationRepository;
import aussie.core.port.out.StorageHealthIndicator;
Expand Down Expand Up @@ -65,17 +66,26 @@ private void setCacheProviderResolved(StorageProviderLoader loader) throws Excep

private Object invokeSelectProvider(StorageProviderLoader loader, List<?> providers, String configured, String type)
throws Exception {
final var method =
StorageProviderLoader.class.getDeclaredMethod("selectProvider", List.class, String.class, String.class);
method.setAccessible(true);
try {
return method.invoke(loader, providers, configured, type);
} catch (java.lang.reflect.InvocationTargetException e) {
if (e.getCause() instanceof RuntimeException re) {
throw re;
}
throw e;
if ("repository".equals(type)) {
@SuppressWarnings("unchecked")
final var repositoryProviders = (List<StorageRepositoryProvider>) providers;
return ProviderSelection.select(
repositoryProviders,
configured,
type,
StorageRepositoryProvider::name,
StorageRepositoryProvider::priority,
StorageRepositoryProvider::isAvailable);
}
@SuppressWarnings("unchecked")
final var cacheProviders = (List<ConfigurationCacheProvider>) providers;
return ProviderSelection.select(
cacheProviders,
configured,
type,
ConfigurationCacheProvider::name,
ConfigurationCacheProvider::priority,
ConfigurationCacheProvider::isAvailable);
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import aussie.adapter.out.ProviderSelection;
import aussie.core.port.out.StorageHealthIndicator;
import aussie.core.port.out.TranslationConfigCache;
import aussie.core.port.out.TranslationConfigRepository;
Expand Down Expand Up @@ -78,17 +79,26 @@ private void setCacheProviderResolved(TranslationConfigStorageLoader loader) thr
private Object invokeSelectProvider(
TranslationConfigStorageLoader loader, java.util.List<?> providers, String configured, String type)
throws Exception {
final var method = TranslationConfigStorageLoader.class.getDeclaredMethod(
"selectProvider", java.util.List.class, String.class, String.class);
method.setAccessible(true);
try {
return method.invoke(loader, providers, configured, type);
} catch (java.lang.reflect.InvocationTargetException e) {
if (e.getCause() instanceof RuntimeException re) {
throw re;
}
throw e;
}
if ("storage".equals(type)) {
@SuppressWarnings("unchecked")
final var storageProviders = (java.util.List<TranslationConfigStorageProvider>) providers;
return ProviderSelection.select(
storageProviders,
configured,
"translation config storage",
TranslationConfigStorageProvider::name,
TranslationConfigStorageProvider::priority,
TranslationConfigStorageProvider::isAvailable);
}
@SuppressWarnings("unchecked")
final var cacheProviders = (java.util.List<TranslationConfigCacheProvider>) providers;
return ProviderSelection.select(
cacheProviders,
configured,
"translation config cache",
TranslationConfigCacheProvider::name,
TranslationConfigCacheProvider::priority,
TranslationConfigCacheProvider::isAvailable);
}

@Nested
Expand Down
11 changes: 1 addition & 10 deletions guidebook/04-rate-limiting.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,7 @@ The message key format is `aussie:ratelimit:ws:msg:{serviceId}:{clientId}:{conne

The defaults for message rate limiting are aggressive: 100 messages per 1 second with a burst capacity of 50. The 1-second window (line 195 of `RateLimitingConfig.java`) is much shorter than the 60-second window for HTTP traffic. This reflects the reality of WebSocket usage: message rates are measured in messages-per-second, not messages-per-minute.

When a message exceeds the rate limit, `WebSocketProxySession` closes the connection with code `4429` (line 259), which mirrors HTTP 429 in the WebSocket close code space (4000-4999 is the application-defined range). The `MessageRateLimitHandler` functional interface (line 12 of `api/src/main/java/aussie/core/service/ratelimit/MessageRateLimitHandler.java`) provides a callback-based API:

```java
@FunctionalInterface
public interface MessageRateLimitHandler {
Uni<Void> checkAndProceed(Runnable onAllowed);
}
```

This design avoids blocking. The handler checks the rate limit reactively, and if allowed, invokes the `onAllowed` callback to forward the message to the upstream service.
When a message exceeds the rate limit, `WebSocketProxySession` closes the connection with code `4429`, which mirrors HTTP 429 in the WebSocket close code space (4000-4999 is the application-defined range). The gateway wires `WebSocketRateLimitService.checkMessageLimit` into each session. The session pauses the source socket, performs the check reactively, and forwards the frame only after the check succeeds; a failed check closes the session with `4429`.

### Connection Cleanup

Expand Down
1 change: 0 additions & 1 deletion guidebook/appendix-a-package-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ Domain services implementing inbound ports and composing outbound ports. All are

| Class | Description |
|---|---|
| `MessageRateLimitHandler` | Functional interface for WebSocket message-level rate limit callbacks. |
| `RateLimitResolver` | Resolves the `EffectiveRateLimit` for a request by merging platform defaults with service and endpoint overrides. Enforces platform ceiling. |
| `WebSocketRateLimitService` | Rate limiting for WebSocket connection establishment and per-connection message throughput. |

Expand Down
Loading