提交 a4d23f5c 编写于 作者: H hudingrong

第三节

上级 abeaa0f8
24-04-03.10:27:41.976 [main ] WARN ClassPathMapperScanner - No MyBatis mapper was found in '[cn.bugstack]' package. Please check your configuration.
24-04-05.17:42:28.254 [RMI TCP Connection(16)-2.0.0.1] WARN HealthEndpointSupport - Health contributor org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator (db) took 53954ms to respond
24-04-05.17:42:39.038 [redisson-netty-2-2] WARN RedisReactiveHealthIndicator - Redis health check failed
org.springframework.data.redis.RedisSystemException: NOAUTH Authentication required.. channel: [id: 0x2c1446a4, L:/192.168.30.92:64003 - R:120.78.91.227/120.78.91.227:6379] data: CommandData [promise=java.util.concurrent.CompletableFuture@331b138c[Not completed, 1 dependents], command=(INFO), params=[server], codec=org.redisson.client.codec.StringCodec]; nested exception is org.redisson.client.RedisAuthRequiredException: NOAUTH Authentication required.. channel: [id: 0x2c1446a4, L:/192.168.30.92:64003 - R:120.78.91.227/120.78.91.227:6379] data: CommandData [promise=java.util.concurrent.CompletableFuture@331b138c[Not completed, 1 dependents], command=(INFO), params=[server], codec=org.redisson.client.codec.StringCodec]
at org.redisson.spring.data.connection.RedissonBaseReactive.lambda$read$5(RedissonBaseReactive.java:91)
at reactor.core.publisher.Mono.lambda$onErrorMap$31(Mono.java:3811)
at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:94)
at reactor.core.publisher.MonoNext$NextSubscriber.onError(MonoNext.java:93)
at reactor.core.publisher.FluxCreate$BaseSink.error(FluxCreate.java:474)
at reactor.core.publisher.FluxCreate$BufferAsyncSink.drain(FluxCreate.java:802)
at reactor.core.publisher.FluxCreate$BufferAsyncSink.error(FluxCreate.java:747)
at reactor.core.publisher.FluxCreate$SerializedFluxSink.drainLoop(FluxCreate.java:237)
at reactor.core.publisher.FluxCreate$SerializedFluxSink.drain(FluxCreate.java:213)
at reactor.core.publisher.FluxCreate$SerializedFluxSink.error(FluxCreate.java:189)
at org.redisson.reactive.CommandReactiveService.lambda$reactive$1(CommandReactiveService.java:60)
at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:774)
at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:750)
at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:488)
at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1990)
at org.redisson.command.RedisExecutor.handleError(RedisExecutor.java:583)
at org.redisson.command.RedisExecutor.handleResult(RedisExecutor.java:565)
at org.redisson.command.RedisExecutor.checkAttemptPromise(RedisExecutor.java:553)
at org.redisson.command.RedisExecutor.lambda$execute$5(RedisExecutor.java:195)
at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:774)
at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:750)
at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:488)
at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1990)
at org.redisson.client.protocol.CommandData.tryFailure(CommandData.java:87)
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:368)
at org.redisson.client.handler.CommandDecoder.decodeCommand(CommandDecoder.java:205)
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:144)
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:120)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:529)
at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:366)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.redisson.client.RedisAuthRequiredException: NOAUTH Authentication required.. channel: [id: 0x2c1446a4, L:/192.168.30.92:64003 - R:120.78.91.227/120.78.91.227:6379] data: CommandData [promise=java.util.concurrent.CompletableFuture@331b138c[Not completed, 1 dependents], command=(INFO), params=[server], codec=org.redisson.client.codec.StringCodec]
... 23 common frames omitted
24-04-05.17:42:39.145 [RMI TCP Connection(16)-2.0.0.1] WARN HealthEndpointSupport - Health contributor org.springframework.boot.actuate.autoconfigure.health.HealthEndpointConfiguration$AdaptedReactiveHealthContributors$1 (redis) took 10845ms to respond
24-04-05.18:05:52.824 [HikariPool-1 housekeeper] WARN HikariPool - HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=4m57s651ms233µs).
24-04-05.18:51:19.253 [redisson-netty-2-22] ERROR rejectedExecution - Failed to submit a listener notification task. Event loop shut down?
java.util.concurrent.RejectedExecutionException: event executor terminated
at io.netty.util.concurrent.SingleThreadEventExecutor.reject(SingleThreadEventExecutor.java:934)
at io.netty.util.concurrent.SingleThreadEventExecutor.offerTask(SingleThreadEventExecutor.java:351)
at io.netty.util.concurrent.SingleThreadEventExecutor.addTask(SingleThreadEventExecutor.java:344)
at io.netty.util.concurrent.SingleThreadEventExecutor.execute(SingleThreadEventExecutor.java:836)
at io.netty.util.concurrent.SingleThreadEventExecutor.execute0(SingleThreadEventExecutor.java:827)
at io.netty.util.concurrent.SingleThreadEventExecutor.execute(SingleThreadEventExecutor.java:817)
at io.netty.util.concurrent.DefaultPromise.safeExecute(DefaultPromise.java:862)
at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:500)
at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:636)
at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:625)
at io.netty.util.concurrent.DefaultPromise.setSuccess(DefaultPromise.java:97)
at io.netty.channel.group.DefaultChannelGroupFuture.setSuccess0(DefaultChannelGroupFuture.java:200)
at io.netty.channel.group.DefaultChannelGroupFuture.access$400(DefaultChannelGroupFuture.java:41)
at io.netty.channel.group.DefaultChannelGroupFuture$1.operationComplete(DefaultChannelGroupFuture.java:75)
at io.netty.channel.group.DefaultChannelGroupFuture$1.operationComplete(DefaultChannelGroupFuture.java:48)
at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:590)
at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:583)
at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:559)
at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:492)
at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:636)
at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:625)
at io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:105)
at io.netty.channel.DefaultChannelPromise.trySuccess(DefaultChannelPromise.java:84)
at io.netty.channel.AbstractChannel$CloseFuture.setClosed(AbstractChannel.java:1164)
at io.netty.channel.AbstractChannel$AbstractUnsafe.doClose0(AbstractChannel.java:755)
at io.netty.channel.AbstractChannel$AbstractUnsafe.close(AbstractChannel.java:731)
at io.netty.channel.AbstractChannel$AbstractUnsafe.close(AbstractChannel.java:620)
at io.netty.channel.nio.NioEventLoop.closeAll(NioEventLoop.java:838)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:595)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
24-04-03.10:27:41.230 [main ] INFO Application - Starting Application using Java 1.8.0_241 on Hudingrong with PID 23744 (E:\resource\market_platform\xfg-frame-archetype-lite\xfg-frame-archetype-lite-app\target\classes started by 86189 in E:\resource\market_platform\xfg-frame-archetype-lite)
24-04-03.10:27:41.233 [main ] INFO Application - The following 1 profile is active: "dev"
24-04-03.10:27:41.976 [main ] WARN ClassPathMapperScanner - No MyBatis mapper was found in '[cn.bugstack]' package. Please check your configuration.
24-04-03.10:27:42.458 [main ] INFO TomcatWebServer - Tomcat initialized with port(s): 8091 (http)
24-04-03.10:27:42.467 [main ] INFO Http11NioProtocol - Initializing ProtocolHandler ["http-nio-8091"]
24-04-03.10:27:42.468 [main ] INFO StandardService - Starting service [Tomcat]
24-04-03.10:27:42.468 [main ] INFO StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.75]
24-04-03.10:27:42.629 [main ] INFO [/] - Initializing Spring embedded WebApplicationContext
24-04-03.10:27:42.629 [main ] INFO ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 1329 ms
24-04-03.10:27:43.331 [main ] INFO Http11NioProtocol - Starting ProtocolHandler ["http-nio-8091"]
24-04-03.10:27:43.350 [main ] INFO TomcatWebServer - Tomcat started on port(s): 8091 (http) with context path ''
24-04-03.10:27:43.362 [main ] INFO Application - Started Application in 2.792 seconds (JVM running for 4.844)
24-04-05.17:38:41.351 [main ] INFO Application - Starting Application using Java 1.8.0_241 on Hudingrong with PID 22032 (E:\resource\market_platform\xfg-frame-archetype-lite\xfg-frame-archetype-lite-app\target\classes started by 86189 in E:\resource\market_platform\xfg-frame-archetype-lite)
24-04-05.17:38:41.355 [main ] INFO Application - The following 1 profile is active: "dev"
24-04-05.17:38:42.242 [main ] INFO RepositoryConfigurationDelegate - Multiple Spring Data modules found, entering strict repository configuration mode
24-04-05.17:38:42.244 [main ] INFO RepositoryConfigurationDelegate - Bootstrapping Spring Data Redis repositories in DEFAULT mode.
24-04-05.17:38:42.266 [main ] INFO RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 8 ms. Found 0 Redis repository interfaces.
24-04-05.17:38:42.845 [main ] INFO TomcatWebServer - Tomcat initialized with port(s): 8091 (http)
24-04-05.17:38:42.854 [main ] INFO Http11NioProtocol - Initializing ProtocolHandler ["http-nio-8091"]
24-04-05.17:38:42.855 [main ] INFO StandardService - Starting service [Tomcat]
24-04-05.17:38:42.855 [main ] INFO StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.75]
24-04-05.17:38:43.001 [main ] INFO [/] - Initializing Spring embedded WebApplicationContext
24-04-05.17:38:43.001 [main ] INFO ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 1578 ms
24-04-05.17:39:14.543 [main ] INFO Version - Redisson 3.23.4
24-04-05.17:39:15.424 [redisson-netty-2-6] INFO MasterPubSubConnectionPool - 1 connections initialized for 120.78.91.227/120.78.91.227:6379
24-04-05.17:39:15.738 [redisson-netty-2-23] INFO MasterConnectionPool - 10 connections initialized for 120.78.91.227/120.78.91.227:6379
24-04-05.17:41:07.774 [main ] INFO EndpointLinksResolver - Exposing 1 endpoint(s) beneath base path '/actuator'
24-04-05.17:41:23.098 [main ] INFO Http11NioProtocol - Starting ProtocolHandler ["http-nio-8091"]
24-04-05.17:41:23.612 [main ] INFO TomcatWebServer - Tomcat started on port(s): 8091 (http) with context path ''
24-04-05.17:41:29.793 [main ] INFO Application - Started Application in 169.057 seconds (JVM running for 171.573)
24-04-05.17:41:34.363 [RMI TCP Connection(16)-2.0.0.1] INFO HikariDataSource - HikariPool-1 - Starting...
24-04-05.17:41:34.595 [RMI TCP Connection(17)-2.0.0.1] INFO [/] - Initializing Spring DispatcherServlet 'dispatcherServlet'
24-04-05.17:41:34.609 [RMI TCP Connection(17)-2.0.0.1] INFO DispatcherServlet - Initializing Servlet 'dispatcherServlet'
24-04-05.17:41:35.876 [RMI TCP Connection(17)-2.0.0.1] INFO DispatcherServlet - Completed initialization in 1254 ms
24-04-05.17:42:24.568 [RMI TCP Connection(16)-2.0.0.1] INFO HikariDataSource - HikariPool-1 - Start completed.
24-04-05.17:42:28.254 [RMI TCP Connection(16)-2.0.0.1] WARN HealthEndpointSupport - Health contributor org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator (db) took 53954ms to respond
24-04-05.17:42:39.038 [redisson-netty-2-2] WARN RedisReactiveHealthIndicator - Redis health check failed
org.springframework.data.redis.RedisSystemException: NOAUTH Authentication required.. channel: [id: 0x2c1446a4, L:/192.168.30.92:64003 - R:120.78.91.227/120.78.91.227:6379] data: CommandData [promise=java.util.concurrent.CompletableFuture@331b138c[Not completed, 1 dependents], command=(INFO), params=[server], codec=org.redisson.client.codec.StringCodec]; nested exception is org.redisson.client.RedisAuthRequiredException: NOAUTH Authentication required.. channel: [id: 0x2c1446a4, L:/192.168.30.92:64003 - R:120.78.91.227/120.78.91.227:6379] data: CommandData [promise=java.util.concurrent.CompletableFuture@331b138c[Not completed, 1 dependents], command=(INFO), params=[server], codec=org.redisson.client.codec.StringCodec]
at org.redisson.spring.data.connection.RedissonBaseReactive.lambda$read$5(RedissonBaseReactive.java:91)
at reactor.core.publisher.Mono.lambda$onErrorMap$31(Mono.java:3811)
at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:94)
at reactor.core.publisher.MonoNext$NextSubscriber.onError(MonoNext.java:93)
at reactor.core.publisher.FluxCreate$BaseSink.error(FluxCreate.java:474)
at reactor.core.publisher.FluxCreate$BufferAsyncSink.drain(FluxCreate.java:802)
at reactor.core.publisher.FluxCreate$BufferAsyncSink.error(FluxCreate.java:747)
at reactor.core.publisher.FluxCreate$SerializedFluxSink.drainLoop(FluxCreate.java:237)
at reactor.core.publisher.FluxCreate$SerializedFluxSink.drain(FluxCreate.java:213)
at reactor.core.publisher.FluxCreate$SerializedFluxSink.error(FluxCreate.java:189)
at org.redisson.reactive.CommandReactiveService.lambda$reactive$1(CommandReactiveService.java:60)
at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:774)
at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:750)
at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:488)
at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1990)
at org.redisson.command.RedisExecutor.handleError(RedisExecutor.java:583)
at org.redisson.command.RedisExecutor.handleResult(RedisExecutor.java:565)
at org.redisson.command.RedisExecutor.checkAttemptPromise(RedisExecutor.java:553)
at org.redisson.command.RedisExecutor.lambda$execute$5(RedisExecutor.java:195)
at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:774)
at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:750)
at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:488)
at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1990)
at org.redisson.client.protocol.CommandData.tryFailure(CommandData.java:87)
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:368)
at org.redisson.client.handler.CommandDecoder.decodeCommand(CommandDecoder.java:205)
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:144)
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:120)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:529)
at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:366)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.redisson.client.RedisAuthRequiredException: NOAUTH Authentication required.. channel: [id: 0x2c1446a4, L:/192.168.30.92:64003 - R:120.78.91.227/120.78.91.227:6379] data: CommandData [promise=java.util.concurrent.CompletableFuture@331b138c[Not completed, 1 dependents], command=(INFO), params=[server], codec=org.redisson.client.codec.StringCodec]
... 23 common frames omitted
24-04-05.17:42:39.145 [RMI TCP Connection(16)-2.0.0.1] WARN HealthEndpointSupport - Health contributor org.springframework.boot.actuate.autoconfigure.health.HealthEndpointConfiguration$AdaptedReactiveHealthContributors$1 (redis) took 10845ms to respond
24-04-05.18:05:52.824 [HikariPool-1 housekeeper] WARN HikariPool - HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=4m57s651ms233µs).
24-04-05.18:51:19.253 [redisson-netty-2-22] ERROR rejectedExecution - Failed to submit a listener notification task. Event loop shut down?
java.util.concurrent.RejectedExecutionException: event executor terminated
at io.netty.util.concurrent.SingleThreadEventExecutor.reject(SingleThreadEventExecutor.java:934)
at io.netty.util.concurrent.SingleThreadEventExecutor.offerTask(SingleThreadEventExecutor.java:351)
at io.netty.util.concurrent.SingleThreadEventExecutor.addTask(SingleThreadEventExecutor.java:344)
at io.netty.util.concurrent.SingleThreadEventExecutor.execute(SingleThreadEventExecutor.java:836)
at io.netty.util.concurrent.SingleThreadEventExecutor.execute0(SingleThreadEventExecutor.java:827)
at io.netty.util.concurrent.SingleThreadEventExecutor.execute(SingleThreadEventExecutor.java:817)
at io.netty.util.concurrent.DefaultPromise.safeExecute(DefaultPromise.java:862)
at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:500)
at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:636)
at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:625)
at io.netty.util.concurrent.DefaultPromise.setSuccess(DefaultPromise.java:97)
at io.netty.channel.group.DefaultChannelGroupFuture.setSuccess0(DefaultChannelGroupFuture.java:200)
at io.netty.channel.group.DefaultChannelGroupFuture.access$400(DefaultChannelGroupFuture.java:41)
at io.netty.channel.group.DefaultChannelGroupFuture$1.operationComplete(DefaultChannelGroupFuture.java:75)
at io.netty.channel.group.DefaultChannelGroupFuture$1.operationComplete(DefaultChannelGroupFuture.java:48)
at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:590)
at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:583)
at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:559)
at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:492)
at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:636)
at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:625)
at io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:105)
at io.netty.channel.DefaultChannelPromise.trySuccess(DefaultChannelPromise.java:84)
at io.netty.channel.AbstractChannel$CloseFuture.setClosed(AbstractChannel.java:1164)
at io.netty.channel.AbstractChannel$AbstractUnsafe.doClose0(AbstractChannel.java:755)
at io.netty.channel.AbstractChannel$AbstractUnsafe.close(AbstractChannel.java:731)
at io.netty.channel.AbstractChannel$AbstractUnsafe.close(AbstractChannel.java:620)
at io.netty.channel.nio.NioEventLoop.closeAll(NioEventLoop.java:838)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:595)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
24-04-05.18:51:19.260 [SpringApplicationShutdownHook] INFO HikariDataSource - HikariPool-1 - Shutdown initiated...
24-04-05.18:51:19.482 [SpringApplicationShutdownHook] INFO HikariDataSource - HikariPool-1 - Shutdown completed.
......@@ -100,6 +100,11 @@
<artifactId>commons-codec</artifactId>
<version>1.15</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>3.23.4</version>
</dependency>
<!-- 工程模块 -->
<dependency>
......
......@@ -841,3 +841,110 @@ Caused by: java.net.SocketException: Socket closed
at com.mysql.cj.protocol.a.MultiPacketReader.readHeader(MultiPacketReader.java:44)
at com.mysql.cj.protocol.a.NativeProtocol.readMessage(NativeProtocol.java:538)
... 61 common frames omitted
24-04-07.16:11:22.663 [main ] ERROR TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@40317ba2] to prepare test instance [cn.bugstack.test.infrastructure.AwardDaoTest@58d79479]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cn.bugstack.test.infrastructure.AwardDaoTest': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'redissonService': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:332)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:417)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:119)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:43)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:248)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'redissonService': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:544)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:520)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:673)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:228)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:329)
... 27 common frames omitted
24-04-07.16:33:17.051 [HikariPool-1 housekeeper] WARN HikariPool - HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=7m16s984ms175µs300ns).
24-04-07.16:35:18.207 [HikariPool-1 housekeeper] WARN HikariPool - HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=2m1s144ms256µs700ns).
24-04-07.17:45:56.345 [redisson-netty-2-2] ERROR CommandDecoder - Unable to decode data. channel: [id: 0x2a921f8f, L:/192.168.3.8:60342 - R:120.78.91.227/120.78.91.227:6379], reply: ReplayingDecoderByteBuf(ridx=498, widx=498), command: (GET), promise: java.util.concurrent.CompletableFuture@7fc021bc[Not completed, 1 dependents], params: [big_market_strategy_award_key_100002]
com.esotericsoftware.kryo.KryoException: Encountered unregistered class ID: 89
at com.esotericsoftware.kryo.util.DefaultClassResolver.readClass(DefaultClassResolver.java:159)
at com.esotericsoftware.kryo.Kryo.readClass(Kryo.java:758)
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:869)
at org.redisson.codec.Kryo5Codec$4.decode(Kryo5Codec.java:144)
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:394)
at org.redisson.client.handler.CommandDecoder.decodeCommand(CommandDecoder.java:205)
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:144)
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:120)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:529)
at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:366)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
24-04-07.17:45:56.361 [redisson-netty-2-2] ERROR ErrorsLoggingHandler - Exception occured. Channel: [id: 0x2a921f8f, L:/192.168.3.8:60342 - R:120.78.91.227/120.78.91.227:6379]
io.netty.handler.codec.DecoderException: com.esotericsoftware.kryo.KryoException: Encountered unregistered class ID: 89
at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:421)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.esotericsoftware.kryo.KryoException: Encountered unregistered class ID: 89
at com.esotericsoftware.kryo.util.DefaultClassResolver.readClass(DefaultClassResolver.java:159)
at com.esotericsoftware.kryo.Kryo.readClass(Kryo.java:758)
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:869)
at org.redisson.codec.Kryo5Codec$4.decode(Kryo5Codec.java:144)
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:394)
at org.redisson.client.handler.CommandDecoder.decodeCommand(CommandDecoder.java:205)
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:144)
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:120)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:529)
at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:366)
... 17 common frames omitted
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -78,6 +78,10 @@
<artifactId>converter-gson</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
</dependency>
<!-- 工程模块;启动依赖 trigger->domain, infrastructure-->
<dependency>
......
package cn.bugstack.config;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.BaseCodec;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.Encoder;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.io.IOException;
/**
* Redis 客户端,使用 Redisson <a href="https://github.com/redisson/redisson">Redisson</a>
*
* @author Fuzhengwei bugstack.cn @小傅哥
*/
@Configuration
@EnableConfigurationProperties(RedisClientConfigProperties.class)
public class RedisClientConfig {
@Bean("redissonClient")
public RedissonClient redissonClient(ConfigurableApplicationContext applicationContext, RedisClientConfigProperties properties) {
Config config = new Config();
// 根据需要可以设定编解码器;https://github.com/redisson/redisson/wiki/4.-%E6%95%B0%E6%8D%AE%E5%BA%8F%E5%88%97%E5%8C%96
config.setCodec(new RedisCodec());
config.useSingleServer()
.setAddress("redis://" + properties.getHost() + ":" + properties.getPort())
.setPassword(properties.getPassword())
.setConnectionPoolSize(properties.getPoolSize())
.setConnectionMinimumIdleSize(properties.getMinIdleSize())
.setIdleConnectionTimeout(properties.getIdleTimeout())
.setConnectTimeout(properties.getConnectTimeout())
.setRetryAttempts(properties.getRetryAttempts())
.setRetryInterval(properties.getRetryInterval())
.setPingConnectionInterval(properties.getPingInterval())
.setKeepAlive(properties.isKeepAlive())
;
return Redisson.create(config);
}
static class RedisCodec extends BaseCodec {
private final Encoder encoder = in -> {
ByteBuf out = ByteBufAllocator.DEFAULT.buffer();
try {
ByteBufOutputStream os = new ByteBufOutputStream(out);
JSON.writeJSONString(os, in, SerializerFeature.WriteClassName);
return os.buffer();
} catch (IOException e) {
out.release();
throw e;
} catch (Exception e) {
out.release();
throw new IOException(e);
}
};
private final Decoder<Object> decoder = (buf, state) -> JSON.parseObject(new ByteBufInputStream(buf), Object.class);
@Override
public Decoder<Object> getValueDecoder() {
return decoder;
}
@Override
public Encoder getValueEncoder() {
return encoder;
}
}
}
package cn.bugstack.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* @author Fuzhengwei bugstack.cn @小傅哥
* @description Redis 连接配置 <a href="https://github.com/redisson/redisson/tree/master/redisson-spring-boot-starter">redisson-spring-boot-starter</a>
* @create 2023-12-23 09:51
*/
@Data
@ConfigurationProperties(prefix = "redis.sdk.config", ignoreInvalidFields = true)
public class RedisClientConfigProperties {
/** host:ip */
private String host;
/** 端口 */
private int port;
/** 账密 */
private String password;
/** 设置连接池的大小,默认为64 */
private int poolSize = 64;
/** 设置连接池的最小空闲连接数,默认为10 */
private int minIdleSize = 10;
/** 设置连接的最大空闲时间(单位:毫秒),超过该时间的空闲连接将被关闭,默认为10000 */
private int idleTimeout = 10000;
/** 设置连接超时时间(单位:毫秒),默认为10000 */
private int connectTimeout = 10000;
/** 设置连接重试次数,默认为3 */
private int retryAttempts = 3;
/** 设置连接重试的间隔时间(单位:毫秒),默认为1000 */
private int retryInterval = 1000;
/** 设置定期检查连接是否可用的时间间隔(单位:毫秒),默认为0,表示不进行定期检查 */
private int pingInterval = 0;
/** 设置是否保持长连接,默认为true */
private boolean keepAlive = true;
}
......@@ -17,18 +17,25 @@ spring:
datasource:
username: root
password: eIRZoTNHLXZXm4^V*
url: jdbc:mysql://120.78.91.227:3306/big-market?useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=UTC&useSSL=true
url: jdbc:mysql://120.78.91.227:3306/big_market?useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=UTC&useSSL=true
driver-class-name: com.mysql.cj.jdbc.Driver
# hikari:
# pool-name: Retail_HikariCP
# minimum-idle: 15 #最小空闲连接数量
# idle-timeout: 180000 #空闲连接存活最大时间,默认600000(10分钟)
# maximum-pool-size: 25 #连接池最大连接数,默认是10
# auto-commit: true #此属性控制从池返回的连接的默认自动提交行为,默认值:true
# max-lifetime: 18 #此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认1800000即30分钟
# connection-timeout: 30000 #数据库连接超时时间,默认30秒,即30000
# connection-test-query: SELECT 1
# type: com.zaxxer.hikari.HikariDataSource
hikari:
pool-name: Retail_HikariCP
minimum-idle: 15 #最小空闲连接数量
idle-timeout: 180000 #空闲连接存活最大时间,默认600000(10分钟)
maximum-pool-size: 25 #连接池最大连接数,默认是10
auto-commit: true #此属性控制从池返回的连接的默认自动提交行为,默认值:true
max-lifetime: 18 #此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认1800000即30分钟
connection-timeout: 30000 #数据库连接超时时间,默认30秒,即30000
connection-test-query: SELECT 1
type: com.zaxxer.hikari.HikariDataSource
# redis配置
redis:
sdk:
config:
host: 120.78.91.227
port: 6379
password: bYBnbyRt1q64Mrmpld8g
mybatis:
mapper-locations: classpath:/mybatis/mapper/*.xml
......
......@@ -22,5 +22,11 @@
from strategy_award
limit 10
</select>
<select id="queryStrategyAwardListByStrategyId"
resultMap="dataMap">
select strategy_id, award_id, award_count, award_count_surplus,award_rate
from strategy_award
where strategy_id = #{strategyId}
</select>
</mapper>
package cn.bugstack.test.domain;
import cn.bugstack.domain.strategy.service.armory.IStrategyArmory;
import cn.bugstack.infrastructure.persistent.redis.IRedisService;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.redisson.api.RMap;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.*;
/**
* @author Fuzhengwei bugstack.cn @小傅哥
* @description 策略领域测试
* @create 2023-12-23 11:33
*/
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class StrategyTest {
@Resource
private IStrategyArmory strategyArmory;
/**
* 策略ID;100001L、100002L 装配的时候创建策略表写入到 Redis Map 中
*/
@Test
public void test_strategyArmory() {
strategyArmory.assembleLotteryStrategy(100002L);
log.info("测试结果:{}");
}
/**
* 从装配的策略中随机获取奖品ID值
*/
@Test
public void test_getAssembleRandomVal() {
log.info("测试结果:{} - 奖品ID值", strategyArmory.getRandomAwardId(100002L));
}
@Resource
private IRedisService redisService;
@Test
public void test_map() {
RMap<Integer, Integer> map = redisService.getMap("strategy_id_100001");
map.put(1, 101);
map.put(2, 101);
map.put(3, 101);
map.put(4, 102);
map.put(5, 102);
map.put(6, 102);
map.put(7, 103);
map.put(8, 103);
map.put(9, 104);
map.put(10, 105);
log.info("测试结果:{}", redisService.getMap("strategy_id_100001").get(1));
}
@Test
public void test_shuffle(){
Map<Integer, Integer> strategyAwardSearchRateTable = new HashMap<>();
// 添加内容到Map中
strategyAwardSearchRateTable.put(1, 10);
strategyAwardSearchRateTable.put(2, 20);
strategyAwardSearchRateTable.put(3, 30);
strategyAwardSearchRateTable.put(4, 40);
// 将Map中的值转换为List
List<Integer> valueList = new ArrayList<>(strategyAwardSearchRateTable.values());
// 使用Collections.shuffle()方法对值的List进行乱序
Collections.shuffle(valueList);
// 将乱序后的值重新放回Map中
Map<Integer, Integer> randomizedMap = new LinkedHashMap<>();
Iterator<Integer> valueIterator = valueList.iterator();
for (Integer key : strategyAwardSearchRateTable.keySet()) {
randomizedMap.put(key, valueIterator.next());
}
// 打印乱序后的Map内容
for (Map.Entry<Integer, Integer> entry : randomizedMap.entrySet()) {
System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue());
}
}
}
package cn.bugstack.test.infrastructure;
import cn.bugstack.domain.strategy.service.armory.StrategyArmory;
import cn.bugstack.infrastructure.persistent.dao.IAwardDao;
import cn.bugstack.infrastructure.persistent.po.Award;
import cn.bugstack.infrastructure.persistent.redis.IRedisService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.redisson.api.RMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.connection.RedisServer;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -25,10 +32,56 @@ public class AwardDaoTest {
@Resource
private IAwardDao awardDao;
@Resource
private IRedisService redisService;
@Autowired
private StrategyArmory strategyArmory;
@Test
public void test_queryAwardList() {
List<Award> awards = awardDao.queryAwardList();
log.info("测试结果:{}", JSON.toJSONString(awards));
}
@Test
public void test_redis() {
RMap<Integer, Integer> map = redisService.getMap("strategy_id_100001");
map.put(1, 101);
map.put(2, 101);
map.put(3, 101);
map.put(4, 102);
map.put(5, 102);
map.put(6, 102);
map.put(7, 103);
map.put(8, 103);
map.put(9, 104);
map.put(10, 105);
log.info("测试结果:{}", redisService.getMap("strategy_id_100001").get(1));
//System.out.println(redisServer.getValue("20240405")+"");
}
@Test
public void test_strategyArmory() {
strategyArmory.assembleLotteryStrategy(100002L);
}
/**
* 从装配的策略中随机获取奖品ID值
*/
@Test
public void test_getAssembleRandomVal() {
for (int i = 0; i < 10; i++) {
Integer randomAwardId = strategyArmory.getRandomAwardId(100002L);
if (randomAwardId == 106) {
log.info("测试结果:{} {} - 奖品ID值",i,randomAwardId );
}
}
}
}
package cn.bugstack.domain.strategy.model.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* @description: 策略奖品实体
* @author: hdr
* @PACKAGE_NAME: cn.bugstack.domain.strategy.model.entity
* @DATE: 2024/4/7
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StrategyAwardEntity {
/** 抽奖策略ID */
private Long strategyId;
/** 抽奖奖品ID - 内部流转使用 */
private Integer awardId;
/** 奖品库存总量 */
private Integer awardCount;
/** 奖品库存剩余 */
private Integer awardCountSurplus;
/** 奖品中奖概率 */
private BigDecimal awardRate;
}
package cn.bugstack.domain.strategy.repository;
import cn.bugstack.domain.strategy.model.entity.StrategyAwardEntity;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @description: 策略仓储接口
* @author: hdr
* @PACKAGE_NAME: cn.bugstack.domain.strategy.repository
* @DATE: 2024/4/5
*/
public interface IStrategyRepository {
/**
* 查询策略对应的数据
* @param strategy 策略id
* @return 策略数据
*/
List<StrategyAwardEntity> queryStrategyAwardList(Long strategy);
/**
* @param strategyId 策略id
* @param rateRange 概率
* @param shuffleStrategyAwardSearchRateTables 所有保存的概率
*/
void storeStrategyAwardSearchRateTables(Long strategyId, Integer rateRange, HashMap<Integer, Integer> shuffleStrategyAwardSearchRateTables);
/**
*
* @param strategyId 获取概率值
* @return
*/
int getRandomAwardId(Long strategyId);
/**
* 获取哦奖品id
* @param strategyId
* @param nextInt
* @return
*/
Integer getStrategyAwardAssemble(Long strategyId, int nextInt);
}
package cn.bugstack.domain.strategy.service.armory;
/**
* @description:
* @author: hdr
* @PACKAGE_NAME: cn.bugstack.domain.strategy.service.armory
* @DATE: 2024/4/5
*/
public interface IStrategyArmory {
/**
* 抽奖策略
* @param strategy
*/
void assembleLotteryStrategy(Long strategy);
/**
* 获取随机奖品id
* @param strategyId
* @return
*/
Integer getRandomAwardId(Long strategyId);
}
package cn.bugstack.domain.strategy.service.armory;
import cn.bugstack.domain.strategy.model.entity.StrategyAwardEntity;
import cn.bugstack.domain.strategy.repository.IStrategyRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.security.SecureRandom;
import java.util.*;
import java.util.stream.Collectors;
/**
* @description:
* @author: hdr
* @PACKAGE_NAME: cn.bugstack.domain.strategy.service.armory
* @DATE: 2024/4/5
*/
@Slf4j
@Service
public class StrategyArmory implements IStrategyArmory {
@Autowired
private IStrategyRepository repository;
@Override
public void assembleLotteryStrategy(Long strategy) {
// 1. 查询策略配置
List<StrategyAwardEntity> awardEntityList = repository.queryStrategyAwardList(strategy);
// 2. 获取最小概率值
BigDecimal minAwardRate = awardEntityList.stream().map(StrategyAwardEntity::getAwardRate)
.min(BigDecimal::compareTo)
.orElse(BigDecimal.ZERO);
// 3. 获取概率值总和
BigDecimal totalAwardRate = awardEntityList.stream()
.map(StrategyAwardEntity::getAwardRate)
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 4. 用 1% 0.001获取概率范围,百分位、千分位、万分位
BigDecimal rateRange = totalAwardRate.divide(minAwardRate, 0, RoundingMode.CEILING);
ArrayList<Object> strategyAwardSearchRateTables = new ArrayList(rateRange.intValue());
for (StrategyAwardEntity strategyAwardEntity : awardEntityList) {
Integer awardId = strategyAwardEntity.getAwardId();
BigDecimal awardRate = strategyAwardEntity.getAwardRate();
// 5. 计算出每个概率值需要存储到查找表的数量,循环填充
log.info("rateRange.multiply(awardRate).setScale(0, RoundingMode.CEILING).intValue()"+rateRange.multiply(awardRate).setScale(0, RoundingMode.CEILING).intValue());
for (int i = 0; i < rateRange.multiply(awardRate).setScale(0, RoundingMode.CEILING).intValue(); i++) {
strategyAwardSearchRateTables.add(awardId);
}
// 6. 乱序
Collections.shuffle(strategyAwardSearchRateTables);
// 7.
HashMap<Integer, Integer> shuffleStrategyAwardSearchRateTables = new HashMap<>();
for (int i = 0; i < strategyAwardSearchRateTables.size(); i++) {
shuffleStrategyAwardSearchRateTables.put(i, (Integer) strategyAwardSearchRateTables.get(i));
}
log.info(shuffleStrategyAwardSearchRateTables.size()+"");
// 8. 存储到 redis中
repository.storeStrategyAwardSearchRateTables(strategy,shuffleStrategyAwardSearchRateTables.size(), shuffleStrategyAwardSearchRateTables);
}
}
@Override
public Integer getRandomAwardId(Long strategyId) {
int rateRange = repository.getRandomAwardId(strategyId);
return repository.getStrategyAwardAssemble(strategyId,new SecureRandom().nextInt(rateRange));
}
}
......@@ -18,6 +18,11 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>3.23.4</version>
</dependency>
<!-- 系统模块 -->
<dependency>
<groupId>cn.bugstack</groupId>
......
......@@ -2,6 +2,7 @@ package cn.bugstack.infrastructure.persistent.dao;
import cn.bugstack.infrastructure.persistent.po.StrategyAward;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
......@@ -15,4 +16,10 @@ public interface IStrategyAwardDao {
List<StrategyAward> queryStrategyAwardList();
/**
* 查询策略下的数据
* @param strategyId
* @return
*/
List<StrategyAward> queryStrategyAwardListByStrategyId(@Param("strategyId") Long strategyId);
}
package cn.bugstack.infrastructure.persistent.redis;
import org.redisson.api.*;
/**
* @description: redisson相关服务
* @author: hdr
* @PACKAGE_NAME: cn.bugstack.infrastructure.persistent.redis
* @DATE: 2024/4/5
*/
public interface IRedisService {
/**
* 设置指定 key 的值
*
* @param key 键
* @param value 值
*/
<T> void setValue(String key, T value);
/**
* 设置指定 key 的值
*
* @param key 键
* @param value 值
* @param expired 过期时间
*/
<T> void setValue(String key, T value, long expired);
/**
* 获取指定 key 的值
*
* @param key 键
* @return 值
*/
<T> T getValue(String key);
/**
* 获取队列
*
* @param key 键
* @param <T> 泛型
* @return 队列
*/
<T> RQueue<T> getQueue(String key);
/**
* 加锁队列
*
* @param key 键
* @param <T> 泛型
* @return 队列
*/
<T> RBlockingQueue<T> getBlockingQueue(String key);
/**
* 延迟队列
*
* @param rBlockingQueue 加锁队列
* @param <T> 泛型
* @return 队列
*/
<T> RDelayedQueue<T> getDelayedQueue(RBlockingQueue<T> rBlockingQueue);
/**
* 自增 Key 的值;1、2、3、4
*
* @param key 键
* @return 自增后的值
*/
long incr(String key);
/**
* 指定值,自增 Key 的值;1、2、3、4
*
* @param key 键
* @return 自增后的值
*/
long incrBy(String key, long delta);
/**
* 自减 Key 的值;1、2、3、4
*
* @param key 键
* @return 自增后的值
*/
long decr(String key);
/**
* 指定值,自增 Key 的值;1、2、3、4
*
* @param key 键
* @return 自增后的值
*/
long decrBy(String key, long delta);
/**
* 移除指定 key 的值
*
* @param key 键
*/
void remove(String key);
/**
* 判断指定 key 的值是否存在
*
* @param key 键
* @return true/false
*/
boolean isExists(String key);
/**
* 将指定的值添加到集合中
*
* @param key 键
* @param value 值
*/
void addToSet(String key, String value);
/**
* 判断指定的值是否是集合的成员
*
* @param key 键
* @param value 值
* @return 如果是集合的成员返回 true,否则返回 false
*/
boolean isSetMember(String key, String value);
/**
* 将指定的值添加到列表中
*
* @param key 键
* @param value 值
*/
void addToList(String key, String value);
/**
* 获取列表中指定索引的值
*
* @param key 键
* @param index 索引
* @return 值
*/
String getFromList(String key, int index);
/**
* 获取Map
*
* @param key 键
* @return 值
*/
<K, V> RMap<K, V> getMap(String key);
/**
* 将指定的键值对添加到哈希表中
*
* @param key 键
* @param field 字段
* @param value 值
*/
void addToMap(String key, String field, String value);
/**
* 获取哈希表中指定字段的值
*
* @param key 键
* @param field 字段
* @return 值
*/
String getFromMap(String key, String field);
/**
* 获取哈希表中指定字段的值
*
* @param key 键
* @param field 字段
* @return 值
*/
<K, V> V getFromMap(String key, K field);
/**
* 将指定的值添加到有序集合中
*
* @param key 键
* @param value 值
*/
void addToSortedSet(String key, String value);
/**
* 获取 Redis 锁(可重入锁)
*
* @param key 键
* @return Lock
*/
RLock getLock(String key);
/**
* 获取 Redis 锁(公平锁)
*
* @param key 键
* @return Lock
*/
RLock getFairLock(String key);
/**
* 获取 Redis 锁(读写锁)
*
* @param key 键
* @return RReadWriteLock
*/
RReadWriteLock getReadWriteLock(String key);
/**
* 获取 Redis 信号量
*
* @param key 键
* @return RSemaphore
*/
RSemaphore getSemaphore(String key);
/**
* 获取 Redis 过期信号量
* <p>
* 基于Redis的Redisson的分布式信号量(Semaphore)Java对象RSemaphore采用了与java.util.concurrent.Semaphore相似的接口和用法。
* 同时还提供了异步(Async)、反射式(Reactive)和RxJava2标准的接口。
*
* @param key 键
* @return RPermitExpirableSemaphore
*/
RPermitExpirableSemaphore getPermitExpirableSemaphore(String key);
/**
* 闭锁
*
* @param key 键
* @return RCountDownLatch
*/
RCountDownLatch getCountDownLatch(String key);
/**
* 布隆过滤器
*
* @param key 键
* @param <T> 存放对象
* @return 返回结果
*/
<T> RBloomFilter<T> getBloomFilter(String key);
}
package cn.bugstack.infrastructure.persistent.redis;
import org.redisson.api.*;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.Duration;
/**
* @description: redisson 相关服务
* @author: hdr
* @PACKAGE_NAME: cn.bugstack.infrastructure.persistent.redis
* @DATE: 2024/4/5
*/
@Service("redissonService")
public class RedisService implements IRedisService {
@Resource
private RedissonClient redissonClient;
public <T> void setValue(String key, T value) {
redissonClient.<T>getBucket(key).set(value);
}
@Override
public <T> void setValue(String key, T value, long expired) {
RBucket<T> bucket = redissonClient.getBucket(key);
bucket.set(value, Duration.ofMillis(expired));
}
public <T> T getValue(String key) {
return redissonClient.<T>getBucket(key).get();
}
@Override
public <T> RQueue<T> getQueue(String key) {
return redissonClient.getQueue(key);
}
@Override
public <T> RBlockingQueue<T> getBlockingQueue(String key) {
return redissonClient.getBlockingQueue(key);
}
@Override
public <T> RDelayedQueue<T> getDelayedQueue(RBlockingQueue<T> rBlockingQueue) {
return redissonClient.getDelayedQueue(rBlockingQueue);
}
@Override
public long incr(String key) {
return redissonClient.getAtomicLong(key).incrementAndGet();
}
@Override
public long incrBy(String key, long delta) {
return redissonClient.getAtomicLong(key).addAndGet(delta);
}
@Override
public long decr(String key) {
return redissonClient.getAtomicLong(key).decrementAndGet();
}
@Override
public long decrBy(String key, long delta) {
return redissonClient.getAtomicLong(key).addAndGet(-delta);
}
@Override
public void remove(String key) {
redissonClient.getBucket(key).delete();
}
@Override
public boolean isExists(String key) {
return redissonClient.getBucket(key).isExists();
}
public void addToSet(String key, String value) {
RSet<String> set = redissonClient.getSet(key);
set.add(value);
}
public boolean isSetMember(String key, String value) {
RSet<String> set = redissonClient.getSet(key);
return set.contains(value);
}
public void addToList(String key, String value) {
RList<String> list = redissonClient.getList(key);
list.add(value);
}
public String getFromList(String key, int index) {
RList<String> list = redissonClient.getList(key);
return list.get(index);
}
@Override
public <K, V> RMap<K, V> getMap(String key) {
return redissonClient.getMap(key);
}
public void addToMap(String key, String field, String value) {
RMap<String, String> map = redissonClient.getMap(key);
map.put(field, value);
}
public String getFromMap(String key, String field) {
RMap<String, String> map = redissonClient.getMap(key);
return map.get(field);
}
@Override
public <K, V> V getFromMap(String key, K field) {
return redissonClient.<K, V>getMap(key).get(field);
}
public void addToSortedSet(String key, String value) {
RSortedSet<String> sortedSet = redissonClient.getSortedSet(key);
sortedSet.add(value);
}
@Override
public RLock getLock(String key) {
return redissonClient.getLock(key);
}
@Override
public RLock getFairLock(String key) {
return redissonClient.getFairLock(key);
}
@Override
public RReadWriteLock getReadWriteLock(String key) {
return redissonClient.getReadWriteLock(key);
}
@Override
public RSemaphore getSemaphore(String key) {
return redissonClient.getSemaphore(key);
}
@Override
public RPermitExpirableSemaphore getPermitExpirableSemaphore(String key) {
return redissonClient.getPermitExpirableSemaphore(key);
}
@Override
public RCountDownLatch getCountDownLatch(String key) {
return redissonClient.getCountDownLatch(key);
}
@Override
public <T> RBloomFilter<T> getBloomFilter(String key) {
return redissonClient.getBloomFilter(key);
}
}
package cn.bugstack.infrastructure.persistent.repository;
import cn.bugstack.domain.strategy.model.entity.StrategyAwardEntity;
import cn.bugstack.domain.strategy.repository.IStrategyRepository;
import cn.bugstack.infrastructure.persistent.dao.IStrategyAwardDao;
import cn.bugstack.infrastructure.persistent.po.StrategyAward;
import cn.bugstack.infrastructure.persistent.redis.IRedisService;
import cn.bugstack.infrastructure.persistent.redis.RedisService;
import cn.bugstack.types.common.Constants;
import lombok.extern.slf4j.Slf4j;
import org.redisson.misc.Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @description: 策略仓储实现
* @author: hdr
* @PACKAGE_NAME: cn.bugstack.infrastructure.persistent.repository
* @DATE: 2024/4/7
*/
@Repository
@Slf4j
public class StrategyRepository implements IStrategyRepository {
@Autowired
private IStrategyAwardDao strategyAwardDao;
@Autowired
private IRedisService redisService;
@Override
public List<StrategyAwardEntity> queryStrategyAwardList(Long strategy) {
// 1. 查询redis中是否有保存策略数据有的话直接返回
String cacheKey = Constants.RedisKey.STRATEGY_AWARD_KEY + strategy;
List<StrategyAwardEntity> strategyAwardEntities = redisService.getValue(cacheKey);
if (strategyAwardEntities != null && !strategyAwardEntities.isEmpty()) {
return strategyAwardEntities;
}
// 2. 没有保存策略数据则查询数据库
List<StrategyAward> strategyAwards = strategyAwardDao.queryStrategyAwardListByStrategyId(strategy);
List<StrategyAwardEntity> strategyAwardEntityList = strategyAwards.stream().map(item -> {
StrategyAwardEntity strategyAwardEntity = new StrategyAwardEntity();
strategyAwardEntity.setStrategyId(item.getStrategyId());
strategyAwardEntity.setAwardId(item.getAwardId());
strategyAwardEntity.setAwardCount(item.getAwardCount());
strategyAwardEntity.setAwardRate(item.getAwardRate());
strategyAwardEntity.setAwardCountSurplus(item.getAwardCountSurplus());
return strategyAwardEntity;
}).collect(Collectors.toList());
// 2.1 保存到redis中
redisService.setValue(cacheKey,strategyAwardEntityList);
return strategyAwardEntityList;
}
@Override
public void storeStrategyAwardSearchRateTables(Long strategyId, Integer rateRange, HashMap<Integer, Integer> shuffleStrategyAwardSearchRateTables) {
// 1. 存储概率值
redisService.setValue(Constants.RedisKey.STRATEGY_RATE_RANGE_KEY + strategyId, rateRange.intValue());
// 2. 存储概率查找表
Map<Integer, Integer> cacheRateTable = redisService.getMap(Constants.RedisKey.STRATEGY_RATE_TABLE_KEY + strategyId);
cacheRateTable.putAll(shuffleStrategyAwardSearchRateTables);
}
@Override
public int getRandomAwardId(Long strategyId) {
return redisService.getValue(Constants.RedisKey.STRATEGY_RATE_RANGE_KEY + strategyId);
}
@Override
public Integer getStrategyAwardAssemble(Long strategyId, int nextInt) {
return redisService.getFromMap(Constants.RedisKey.STRATEGY_RATE_TABLE_KEY + strategyId,nextInt);
}
}
......@@ -4,4 +4,11 @@ public class Constants {
public final static String SPLIT = ",";
public static class RedisKey {
public static String STRATEGY_AWARD_KEY = "big_market_strategy_award_key_";
public static String STRATEGY_RATE_TABLE_KEY = "big_market_strategy_rate_table_key_";
public static String STRATEGY_RATE_RANGE_KEY = "big_market_strategy_rate_range_key_";
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册