Skip to content

Commit

Permalink
GH-1148: Revert Log4j Appender Change
Browse files Browse the repository at this point in the history
Resolves #1148

Fix is now in Spring Framework.
  • Loading branch information
garyrussell authored and artembilan committed Jan 31, 2020
1 parent 028550c commit ef00f2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ext {
rabbitmqHttpClientVersion = '2.1.0.RELEASE'
reactorVersion = '3.2.12.RELEASE'
springRetryVersion = '1.2.4.RELEASE'
springVersion = project.hasProperty('springVersion') ? project.springVersion : '5.1.11.RELEASE'
springVersion = project.hasProperty('springVersion') ? project.springVersion : '5.1.14.BUILD-SNAPSHOT'


expandPlaceholders = '**/quick-tour.xml'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public class AmqpAppender extends AbstractAppender {
/**
* The template.
*/
private RabbitTemplate rabbitTemplate;
private final RabbitTemplate rabbitTemplate = new RabbitTemplate();

/**
* Where LoggingEvents are queued to send.
Expand Down Expand Up @@ -256,12 +256,18 @@ public static AmqpAppender createAppender(// NOSONAR NCSS line count
* Submit the required number of senders into the pool.
*/
private void startSenders() {
this.rabbitTemplate.setConnectionFactory(this.manager.connectionFactory);
if (this.manager.async) {
this.manager.senderPool = Executors.newCachedThreadPool();
for (int i = 0; i < this.manager.senderPoolSize; i++) {
this.manager.senderPool.submit(new EventSender());
}
}
else if (this.manager.maxSenderRetries > 0) {
RetryTemplate retryTemplate = new RetryTemplate();
RetryPolicy retryPolicy = new SimpleRetryPolicy(this.manager.maxSenderRetries);
retryTemplate.setRetryPolicy(retryPolicy);
this.rabbitTemplate.setRetryTemplate(retryTemplate);
}
}

@Override
Expand All @@ -287,22 +293,6 @@ protected Message postProcessMessageBeforeSend(Message message, Event event) {
}

protected void sendEvent(Event event, Map<?, ?> properties) {
synchronized (this) {
if (this.rabbitTemplate == null) {
if (this.manager.activateOptions()) {
this.rabbitTemplate = new RabbitTemplate(this.manager.connectionFactory);
if (!this.manager.async && this.manager.maxSenderRetries > 0) {
RetryTemplate retryTemplate = new RetryTemplate();
RetryPolicy retryPolicy = new SimpleRetryPolicy(this.manager.maxSenderRetries);
retryTemplate.setRetryPolicy(retryPolicy);
this.rabbitTemplate.setRetryTemplate(retryTemplate);
}
}
else {
throw new AmqpException("Cannot create template");
}
}
}
LogEvent logEvent = event.getEvent();
String name = logEvent.getLoggerName();
Level level = logEvent.getLevel();
Expand Down Expand Up @@ -368,7 +358,7 @@ protected void doSend(Event event, LogEvent logEvent, MessageProperties amqpProp
message = new Message(msgBody.toString().getBytes(), amqpProps); //NOSONAR (default charset)
}
message = postProcessMessageBeforeSend(message, event);
this.rabbitTemplate.send(this.manager.exchangeName, routingKey, message); // NOSONAR (sync)
this.rabbitTemplate.send(this.manager.exchangeName, routingKey, message);
}
catch (AmqpException e) {
int retries = event.incrementRetries();
Expand Down Expand Up @@ -661,7 +651,7 @@ protected AmqpManager(LoggerContext loggerContext, String name) {
super(loggerContext, name);
}

boolean activateOptions() {
private boolean activateOptions() {
ConnectionFactory rabbitConnectionFactory = createRabbitConnectionFactory();
if (rabbitConnectionFactory != null) {
Assert.state(this.applicationId != null, "applicationId is required");
Expand All @@ -683,6 +673,7 @@ boolean activateOptions() {
this.clientConnectionProperties);
}
setUpExchangeDeclaration();
this.senderPool = Executors.newCachedThreadPool();
return true;
}
return false;
Expand Down

0 comments on commit ef00f2d

Please sign in to comment.