Skip to content

Allow AMQPAppender to set a custom route key #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class RabbitMQAppender extends AppenderSkeleton {
private String exchange = "vcloud.logging.events";
private String appenderId = System.getProperty("HOSTNAME");
private String queueNameFormatString = "%s.%s";
private String routingString = null;
private ExecutorService workerPool = Executors.newCachedThreadPool();

public RabbitMQAppender() {
Expand Down Expand Up @@ -124,6 +125,14 @@ public String getQueueNameFormatString() {
return queueNameFormatString;
}

public String getRouteString() {
return this.routingString;
}

public void setRouteString(String route) {
this.routingString = route;
}

public void setQueueNameFormatString(String queueNameFormatString) {
this.queueNameFormatString = queueNameFormatString;
}
Expand Down Expand Up @@ -207,7 +216,7 @@ class AppenderPublisher implements Callable<LoggingEvent> {

public LoggingEvent call() throws Exception {
String id = String.format("%s:%s", appenderId, System.currentTimeMillis());
String routingKey = String.format(queueNameFormatString, event.getLevel().toString(), event.getLoggerName());
String routingKey = getRoutKey();

AMQP.BasicProperties props = new AMQP.BasicProperties();
props.setCorrelationId(id);
Expand All @@ -218,5 +227,13 @@ public LoggingEvent call() throws Exception {

return event;
}

private String getRoutKey() {
if(getRouteString() == null) {
return String.format(queueNameFormatString, event.getLevel().toString(), event.getLoggerName());
} else {
return getRouteString();
}
}
}
}