Go to file
Andrea Cavalli 477932e051 Bugfix?
2022-11-09 16:56:48 +01:00
src/main/java/it/cavallium/filequeue Bugfix? 2022-11-09 16:56:48 +01:00
.gitignore first commit 2022-10-10 01:10:05 +02:00
pom.xml Bugfix? 2022-11-09 16:56:48 +01:00
README.md Add readme 2022-10-10 01:18:31 +02:00

FileQueue

Store messages on a disk queue in a fast producer, slow consumer scenario.

var tmpFile = Paths.get("temp.queue.bin");
try (var queue = new it.cavallium.filequeue.DiskQueueToConsumer<String>(tmpFile, new Serializer<String>() {
  @Override
  public byte[] serialize(String data) throws IOException {
    return data.getBytes(StandardCharsets.US_ASCII);
  }
}, new Deserializer<String>() {
  @Override
  public String deserialize(byte[] data) throws IOException {
    return new String(data, StandardCharsets.US_ASCII);
  }
}, text -> {
  System.out.println("Received: %s", text);
  
  // Return true if the message has been consumed, false to retry later
  return true;
})) {
  queue.startQueue();
    
  final var text = "test-message";
	
  while (true) {
    System.out.println("Emitted: %s", text);
    queue.add(text);
  }
}