add Routes and Processors
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s

This commit is contained in:
2026-08-22 02:04:48 +02:00
parent f73ec33aeb
commit 5b7c41c829
7 changed files with 174 additions and 17 deletions
@@ -21,22 +21,21 @@ public class QueueMediaLink extends RouteBuilder {
@Override
public void configure() throws Exception {
from("jms:queue:media.link")
.errorHandler(deadLetterChannel("jms:queue:DLQ")
.maximumRedeliveries(0)
.useOriginalMessage()
.onPrepareFailure(exchange -> {
exchange.getIn().setHeader("FailureReason", "processing failed");
})
)
.routeId("media.link")
.log("${body}")
.trace(true)
.process(new CheckLinkProcessor(mediaFileService))
.choice()
.errorHandler(deadLetterChannel("jms:queue:DLQ")
.maximumRedeliveries(0)
.useOriginalMessage()
.onPrepareFailure(exchange -> {
exchange.getIn().setHeader("FailureReason", "processing failed");
}))
.routeId("media.link")
.log("${body}")
.trace(true)
.process(new CheckLinkProcessor(mediaFileService))
.choice()
.when(exchangeProperty("linkId").isNotNull())
.to("jms:queue:media.link.add")
.to("jms:queue:media.link.add")
.otherwise()
.to("jms:queue:DLQ")
.to("jms:queue:media.link.add.processed");
.to("jms:queue:DLQ")
.to("jms:queue:media.link.processed");
}
}
@@ -0,0 +1,41 @@
package de.thpeetz.kontor.integration.routes;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import de.thpeetz.kontor.integration.services.CheckLoFiProcessor;
import de.thpeetz.kontor.services.MediaFileService;
@Component
public class QueueMediaLoFi extends RouteBuilder {
@Autowired
private final MediaFileService mediaFileService;
@Autowired
public QueueMediaLoFi(MediaFileService mediaFileService) {
this.mediaFileService = mediaFileService;
}
@Override
public void configure() throws Exception {
from("jms:queue:media.lofi")
.errorHandler(deadLetterChannel("jms:queue:DLQ")
.maximumRedeliveries(0)
.useOriginalMessage()
.onPrepareFailure(exchange -> {
exchange.getIn().setHeader("FailureReason", "processing failed");
}))
.routeId("media.lofi")
.log("${body}")
.trace(true)
.process(new CheckLoFiProcessor(mediaFileService))
.choice()
.when(exchangeProperty("linkId").isNotNull())
.to("jms:queue:media.lofi.add")
.otherwise()
.to("jms:queue:DLQ")
.to("jms:queue:media.lofi.processed");
}
}
@@ -0,0 +1,41 @@
package de.thpeetz.kontor.integration.routes;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import de.thpeetz.kontor.integration.services.CheckLoFiProcessor;
import de.thpeetz.kontor.services.MediaFileService;
@Component
public class QueueMediaVideo extends RouteBuilder {
@Autowired
private final MediaFileService mediaFileService;
@Autowired
public QueueMediaVideo(MediaFileService mediaFileService) {
this.mediaFileService = mediaFileService;
}
@Override
public void configure() throws Exception {
from("jms:queue:media.video")
.errorHandler(deadLetterChannel("jms:queue:DLQ")
.maximumRedeliveries(0)
.useOriginalMessage()
.onPrepareFailure(exchange -> {
exchange.getIn().setHeader("FailureReason", "processing failed");
}))
.routeId("media.video")
.log("${body}")
.trace(true)
.process(new CheckLoFiProcessor(mediaFileService))
.choice()
.when(exchangeProperty("linkId").isNotNull())
.to("jms:queue:media.video.add")
.otherwise()
.to("jms:queue:DLQ")
.to("jms:queue:media.video.processed");
}
}
@@ -0,0 +1,37 @@
package de.thpeetz.kontor.integration.services;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import de.thpeetz.kontor.services.MediaFileService;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class CheckLoFiProcessor implements Processor {
private final MediaFileService mediaFileService;
public CheckLoFiProcessor(MediaFileService mediaFileService) {
this.mediaFileService = mediaFileService;
}
@Override
public void process(Exchange exchange) throws Exception {
String messageBody = exchange.getIn().getBody(String.class);
log.info("message body: {}", messageBody);
JSONParser parser = new JSONParser();
try {
JSONObject jsonObject = (JSONObject) parser.parse(messageBody);
String url = (String) jsonObject.get("url");
log.info("found url: {}", url);
exchange.getIn().setHeader("linkId", null);
} catch (ParseException pe) {
log.info("parse exception: {}", pe.toString());
exchange.getIn().setHeader("linkId", null);
}
}
}
@@ -0,0 +1,37 @@
package de.thpeetz.kontor.integration.services;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import de.thpeetz.kontor.services.MediaFileService;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class CheckVideoProcessor implements Processor {
private final MediaFileService mediaFileService;
public CheckVideoProcessor(MediaFileService mediaFileService) {
this.mediaFileService = mediaFileService;
}
@Override
public void process(Exchange exchange) throws Exception {
String messageBody = exchange.getIn().getBody(String.class);
log.info("message body: {}", messageBody);
JSONParser parser = new JSONParser();
try {
JSONObject jsonObject = (JSONObject) parser.parse(messageBody);
String url = (String) jsonObject.get("url");
log.info("found url: {}", url);
exchange.getIn().setHeader("linkId", null);
} catch (ParseException pe) {
log.info("parse exception: {}", pe.toString());
exchange.getIn().setHeader("linkId", null);
}
}
}