This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Connection createConnection() throws TimeoutException, InterruptedException { | |
ConnectionFactory factory = new ConnectionFactory(); | |
// "guest"/"guest" by default, limited to localhost connections | |
factory.setUsername("guest"); | |
factory.setPassword("guest"); | |
factory.setVirtualHost("/"); | |
factory.setHost("127.0.0.1"); | |
factory.setPort(5672); | |
return connectToRabbitMQ(factory); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void prepareRabbitQueue(Channel channel) throws IOException { | |
int prefetchCount = 1; | |
channel.basicQos(prefetchCount); | |
channel.queueDeclare(QUEUE_INPUT, true, false, false, null); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void startWork() throws IOException, TimeoutException, InterruptedException { | |
Channel channel = createConnection().createChannel(); | |
prepareRabbitQueue(channel); | |
DeliverCallback deliverCallback = (consumerTag, delivery) -> { | |
String message = new String(delivery.getBody(), StandardCharsets.UTF_8); | |
System.out.println(" [x] Received '" + message + "'"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private MinioClient getMinioClient() { | |
return MinioClient.builder() | |
.endpoint("localhost", 9001, false) | |
.credentials("minio", "minio123") | |
.build(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private InputStream downloadOriginalBookAsStream(){ | |
InputStream stream; | |
try { | |
stream = getMinioClient().getObject( | |
GetObjectArgs.builder() | |
.bucket("original-ebook") | |
.object("alice.epub") | |
.build()); | |
}catch (InvalidKeyException | NoSuchAlgorithmException | ErrorResponseException | InvalidResponseException | InvalidBucketNameException | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void handleFileUpload(String filename) { | |
MinioClient minioClient = getMinioClient(); | |
try { | |
ObjectWriteResponse response = createBucketAndUploadFile(minioClient, filename); | |
if (response != null) { | |
String url = createURL(minioClient, filename); | |
System.out.println("Created url: " + url); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ObjectWriteResponse createBucketAndUploadFile(MinioClient minioClient, String filename) throws | |
IOException, InvalidKeyException, InvalidResponseException, InsufficientDataException, NoSuchAlgorithmException, ServerException, InternalException, XmlParserException, InvalidBucketNameException, ErrorResponseException, RegionConflictException { | |
if (!minioClient.bucketExists(BucketExistsArgs.builder().bucket("ebookcreator").build())) { | |
minioClient.makeBucket(MakeBucketArgs.builder().bucket("ebookcreator").build()); | |
} | |
return minioClient.uploadObject(UploadObjectArgs.builder() | |
.bucket("ebookcreator") | |
.object(filename) | |
.filename(filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String createURL(MinioClient minioClient, String filename) throws | |
IOException, InvalidKeyException, InvalidResponseException, InsufficientDataException, InvalidExpiresRangeException, ServerException, InternalException, NoSuchAlgorithmException, XmlParserException, InvalidBucketNameException, ErrorResponseException { | |
return minioClient.getPresignedObjectUrl( | |
GetPresignedObjectUrlArgs.builder() | |
.method(Method.GET) | |
.bucket("ebookcreator") | |
.object(filename) | |
.expiry(2, TimeUnit.HOURS) | |
.build()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nl.siegmann.epublib.domain.Book; | |
import nl.siegmann.epublib.domain.Resource; | |
import nl.siegmann.epublib.epub.EpubReader; | |
import nl.siegmann.epublib.epub.EpubWriter; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.util.ArrayList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.7' | |
services: | |
avc-rabbit: | |
image: rabbitmq:3-management | |
container_name: rabbitmq | |
ports: | |
- "15672:15672" | |
- "5672:5672" |