Compare commits

...

2 Commits

Author SHA1 Message Date
lingniu
87830fee09 refactor: make session store redis by default 2026-07-01 10:31:26 +08:00
lingniu
53a9b3b3b7 docs: clarify jt808 mileage metric storage 2026-07-01 10:30:53 +08:00
5 changed files with 20 additions and 12 deletions

View File

@@ -35,7 +35,6 @@ The local-day minimum and maximum GPS total mileage values stay on that same met
KAFKA_TOPIC_JT808_EVENT=vehicle.event.jt808.v1
VEHICLE_STAT_ENABLED=true
VEHICLE_STAT_JT808_MILEAGE_ENABLED=true
VEHICLE_STAT_REPOSITORY_TYPE=jdbc
MYSQL_JDBC_URL=<jdbc-url>
MYSQL_USERNAME=<user>
MYSQL_PASSWORD=<password>

View File

@@ -7,7 +7,7 @@ import java.time.Duration;
@ConfigurationProperties(prefix = "lingniu.ingest.session")
public class SessionProperties {
private Store store = Store.MEMORY;
private Store store = Store.REDIS;
private Duration ttl = Duration.ofMinutes(30);
@@ -16,6 +16,9 @@ public class SessionProperties {
}
public void setStore(Store store) {
if (store == Store.MEMORY) {
throw new IllegalStateException("session.store supports only redis; configured value: memory");
}
this.store = store;
}

View File

@@ -17,15 +17,10 @@ import org.springframework.data.redis.core.StringRedisTemplate;
@EnableConfigurationProperties(SessionProperties.class)
public class SessionCoreAutoConfiguration {
@Bean
@ConditionalOnProperty(prefix = "lingniu.ingest.session", name = "store", havingValue = "memory")
public Object rejectedLegacyMemorySessionStore() {
throw new IllegalStateException("session.store=memory has been removed; configure session.store=redis");
}
@Bean
@ConditionalOnBean(StringRedisTemplate.class)
@ConditionalOnProperty(prefix = "lingniu.ingest.session", name = "store", havingValue = "redis")
@ConditionalOnProperty(prefix = "lingniu.ingest.session", name = "store", havingValue = "redis",
matchIfMissing = true)
@ConditionalOnMissingBean
public SessionStore redisSessionStore(StringRedisTemplate redis, SessionProperties properties) {
// Redis 只保存会话元数据索引;真实 Netty Channel 仍在各协议进程本地内存中。

View File

@@ -43,12 +43,22 @@ class SessionCoreAutoConfigurationTest {
}
@Test
void rejectsLegacyMemorySessionStoreMode() {
void usesRedisSessionStoreByDefaultWhenRedisTemplateExists() {
contextRunner
.withBean(StringRedisTemplate.class, () -> mock(StringRedisTemplate.class))
.run(context -> {
assertThat(context).hasSingleBean(SessionStore.class);
assertThat(context).hasSingleBean(RedisSessionStore.class);
});
}
@Test
void rejectsMemorySessionStoreModeWithRedisOnlyRule() {
contextRunner
.withPropertyValues("lingniu.ingest.session.store=memory")
.run(context -> assertThat(context.getStartupFailure())
.hasRootCauseInstanceOf(IllegalStateException.class)
.hasMessageContaining("session.store=memory has been removed")
.hasMessageContaining("session.store=redis"));
.hasStackTraceContaining("session.store supports only redis")
.hasStackTraceContaining("memory"));
}
}

View File

@@ -29,6 +29,7 @@ class VehicleStatRepositoryContractTest {
.contains("daily_mileage_km = max_total_mileage_km - min_total_mileage_km")
.contains("Do not create or write a protocol-specific JT808 daily-mileage table.")
.doesNotContain("Redis `Jt808MileageStateStore`")
.doesNotContain("VEHICLE_STAT_REPOSITORY_TYPE")
.doesNotContain("REDIS_HOST")
.doesNotContain("GPS segment distance")
.doesNotContain("speed integral");