|
85 | 85 | import im.turms.server.common.infra.reactor.PublisherUtil;
|
86 | 86 | import im.turms.server.common.infra.security.MacUtil;
|
87 | 87 | import im.turms.server.common.infra.time.DateRange;
|
88 |
| -import im.turms.server.common.infra.time.DurationConst; |
89 | 88 | import im.turms.server.common.infra.tracing.TracingCloseableContext;
|
90 | 89 | import im.turms.server.common.infra.tracing.TracingContext;
|
91 | 90 | import im.turms.server.common.storage.mongo.TurmsMongoClient;
|
@@ -196,7 +195,15 @@ private Mono<Void> setUp() {
|
196 | 195 | .getStorage();
|
197 | 196 | Mono<TurmsMongoClient> clientMono =
|
198 | 197 | TurmsMongoClient.of(properties.getMongo(), "message-attachment");
|
199 |
| - TurmsMongoClient mongoClient = clientMono.block(DurationConst.ONE_MINUTE); |
| 198 | + return clientMono.flatMap( |
| 199 | + mongoClient -> initClientAndBuckets(mongoClient, properties, uri, endpoint)); |
| 200 | + } |
| 201 | + |
| 202 | + private Mono<Void> initClientAndBuckets( |
| 203 | + TurmsMongoClient mongoClient, |
| 204 | + MinioStorageProperties properties, |
| 205 | + URI uri, |
| 206 | + String endpoint) { |
200 | 207 | messageAttachmentRepository = new MessageAttachmentRepository(mongoClient);
|
201 | 208 | baseUrl = uri.getScheme()
|
202 | 209 | + "://"
|
@@ -236,10 +243,16 @@ private Mono<Void> setUp() {
|
236 | 243 | } else {
|
237 | 244 | macKey = null;
|
238 | 245 | }
|
239 |
| - initClient(endpoint, |
240 |
| - properties.getRegion(), |
241 |
| - properties.getAccessKey(), |
242 |
| - properties.getSecretKey()); |
| 246 | + String region = properties.getRegion(); |
| 247 | + String accessKey = properties.getAccessKey(); |
| 248 | + String secretKey = properties.getSecretKey(); |
| 249 | + MinioAsyncClient.Builder builder = MinioAsyncClient.builder() |
| 250 | + .endpoint(endpoint) |
| 251 | + .credentials(accessKey, secretKey); |
| 252 | + if (StringUtil.isNotBlank(region)) { |
| 253 | + builder.region(region); |
| 254 | + } |
| 255 | + client = new TurmsMinioAsyncClient(builder.build()); |
243 | 256 |
|
244 | 257 | Mono<Void> initBuckets =
|
245 | 258 | initBuckets().timeout(Duration.ofSeconds(INIT_BUCKETS_TIMEOUT_SECONDS))
|
@@ -268,16 +281,6 @@ private Mono<Void> setUp() {
|
268 | 281 | })));
|
269 | 282 | }
|
270 | 283 |
|
271 |
| - private void initClient(String endpoint, String region, String accessKey, String secretKey) { |
272 |
| - MinioAsyncClient.Builder builder = MinioAsyncClient.builder() |
273 |
| - .endpoint(endpoint) |
274 |
| - .credentials(accessKey, secretKey); |
275 |
| - if (StringUtil.isNotBlank(region)) { |
276 |
| - builder.region(region); |
277 |
| - } |
278 |
| - client = new TurmsMinioAsyncClient(builder.build()); |
279 |
| - } |
280 |
| - |
281 | 284 | // region bucket
|
282 | 285 | private Mono<Void> initBuckets() {
|
283 | 286 | StorageResourceType[] resourceTypes =
|
|
0 commit comments