Integrate Min.io sdk compatible with all S3 Api compliant vendors. Available for jdk and native runtime.
Project configuration
Once you have your Quarkus project configured you can add the minio
extension
to your project by running the following command in your project base directory:
./mvnw quarkus:add-extension -Dextensions="minio"
This will add the following to your pom.xml
:
<dependency>
<groupId>io.quarkiverse.minio</groupId>
<artifactId>quarkus-minio</artifactId>
<version>3.3.1</version>
</dependency>
Native support only
If you need configless programmatic only creation of MinioClient, then your project should be configured as followed :
<dependency>
<groupId>io.quarkiverse.minio</groupId>
<artifactId>quarkus-minio-native</artifactId>
<version>3.3.1</version>
</dependency>
Usage
An io.minio.MinioClient
is made available to your application as a CDI bean if configuration is found.
package com.acme.minio;
import io.minio.MinioClient;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
@ApplicationScoped
public class SampleService {
@Inject
MinioClient minioClient;
@ConfigProperty(name = "minio.bucket-name")
String bucketName;
public String getObject(String name) {
try (InputStream is = minio.getObject(
GetObjectArgs.builder()
.bucket(bucketName)
.object(objectName)
.build());
) {
// Do whatever you want...
} catch (MinioException e) {
throw new IllegalStateException(e);
}
}
}
Multiple Minio clients
Configuring Multiple MinioClients
Defining multiple minio clients works exactly the same way as defining a single minio client, with one important change: you define a name.
In the following example, you have 3 different minio clients:
-
The default one,
-
A minio client named
other
, -
A minio client named
public
,
each with its own configuration.
quarkus.minio.url=http://localhost:9000
quarkus.minio.access-key=minioaccess
quarkus.minio.secret-key=miniosecret
quarkus.minio.other.enabled=true
quarkus.minio.other.url=http://acme:9000
quarkus.minio.other.access-key=minioaccess
quarkus.minio.other.secret-key=miniosecret
quarkus.minio.public.enabled=true
quarkus.minio.public.url=http://public:9000
quarkus.minio.public.access-key=minioaccess
quarkus.minio.public.secret-key=miniosecret
Notice there is an extra bit in the key.
The syntax is as follows: quarkus.minio.[optional name.][bucket property]
.
Named minio clients need to specify at least one build time property so that Quarkus knows they exist. Generally this will be the `enabled` property.
Named MinioClient injection
When using multiple minio clients, each MinioClient
also has the io.quarkiverse.minio.client.MinioQualifier
qualifier with the name of the minio client as the value.
Using the above properties to configure three different minio clients, you can also inject each one as follows:
@Inject
MinioClient defaultMinioClient;
@Inject
@MinioQualifier("public")
MinioClient publicMinioClient;
@Inject
@MinioQualifier("other")
MinioClient otherMinioClient;
Dev Services
Quarkus supports a feature called Dev Services that allows you to create various containers without any config.
What that means in practice is that if you have Docker running and have not configured quarkus.minio.url
,
Quarkus will automatically start a Minio container when running tests or in dev mode, and automatically
configure the connection.
When running the production version of the application, the Minio connection needs to be configured as normal.
If using multiple minio client, all will target the same container. At the moment it’s also not possible to configure devservices individually for each minio client. |
Shared server
Most of the time you need to share the server between applications. Dev Services for Minio implements a service discovery mechanism for your multiple Quarkus applications running in dev mode to share a single server.
Dev Services for Minio starts the container with the quarkus-dev-service-minio label which is used to identify the container.
|
If you need multiple (shared) servers, you can configure the quarkus.minio.devservices.service-name
attribute and indicate the server name.
It looks for a container with the same value, or starts a new one if none can be found.
The default service name is minio
.
Containers are started using Testcontainers and support reusable instances. If you add the property testcontainers.reuse.enable=true
in your
Testcontainers configuration file, then the container will not be stopped after each run, and can be reused. See https://www.testcontainers.org/features/reuse/#how-to-use-it
for more information.
Sharing is enabled by default in dev mode, but disabled in test mode.
You can disable the sharing with quarkus.minio.devservices.shared=false
.
Configuration Reference
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Type |
Default |
|||
---|---|---|---|---|
Enable or disable Dev Services explicitly. Dev Services are automatically enabled unless Environment variable: |
boolean |
|||
Optional fixed port the dev service will listen to. If not defined, the port will be chosen randomly. Environment variable: |
int |
|||
The Minio container image to use. Environment variable: |
string |
|
||
Indicates if the Minio server managed by Quarkus Dev Services is shared. When shared, Quarkus looks for running containers using label-based service discovery. If a matching container is found, it is used, and so a second one is not started. Otherwise, Dev Services for Minio starts a new container. The discovery uses the Container sharing is only used in dev mode. Environment variable: |
boolean |
|
||
The value of the This property is used when you need multiple shared Minio servers. Environment variable: |
string |
|
||
Minio root username access key. Environment variable: |
string |
|
||
Minio root username secret key. Environment variable: |
string |
|
||
Should the extension provide a Environment variable: |
boolean |
|
||
If value is Value is set for minio clients produced. Environment variable: |
boolean |
|||
The minio server URL.
Environment variable: |
string |
|||
The minio server access key Environment variable: |
string |
|||
The minio server secret key Environment variable: |
string |
|||
An optional bucket region Environment variable: |
string |
|||
Should the extension provide a Environment variable: |
boolean |
|
||
The minio server URL.
Environment variable: |
string |
|||
The minio server access key Environment variable: |
string |
|||
The minio server secret key Environment variable: |
string |
|||
An optional bucket region Environment variable: |
string |