Skip to content

Commit 38aa913

Browse files
garyrussellartembilan
authored andcommitted
Fix DEBUG Logging for Projection
Don't Log Converted Message With Projection `toString()` cannot be invoked on the payload proxy created by the projection factory. Increase memory for builds. * Unlike Kafka, we can't use the converter type to determine if projection was used. * Add null check.
1 parent b881b65 commit 38aa913

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ subprojects { subproject ->
236236
compileKotlin.dependsOn updateCopyrights
237237

238238
test {
239+
maxHeapSize = '2g'
240+
jvmArgs '-XX:+HeapDumpOnOutOfMemoryError'
241+
239242
testLogging {
240243
events "skipped", "failed"
241244
showStandardStreams = project.hasProperty("showStandardStreams") ?: false

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
version=2.3.12-SNAPSHOT
2+
org.gradle.jvmargs=-Xms512m -Xmx4g -XX:MaxPermSize=1024m -XX:MaxMetaspaceSize=1g
23
org.gradlee.caching=true
34
org.gradle.daemon=true
45
org.gradle.parallel=true

spring-amqp/src/main/java/org/springframework/amqp/core/MessageProperties.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ public class MessageProperties implements Serializable {
128128

129129
private boolean lastInBatch;
130130

131+
private boolean projectionUsed;
132+
131133
private transient Type inferredArgumentType;
132134

133135
private transient Method targetMethod;
@@ -552,6 +554,26 @@ public void setLastInBatch(boolean lastInBatch) {
552554
this.lastInBatch = lastInBatch;
553555
}
554556

557+
/**
558+
* Get an internal flag used to communicate that conversion used projection; always
559+
* false at the application level.
560+
* @return true if projection was used.
561+
* @since 2.2.20
562+
*/
563+
public boolean isProjectionUsed() {
564+
return this.projectionUsed;
565+
}
566+
567+
/**
568+
* Set an internal flag used to communicate that conversion used projection; always false
569+
* at the application level.
570+
* @param projectionUsed true for projection.
571+
* @since 2.2.20
572+
*/
573+
public void setProjectionUsed(boolean projectionUsed) {
574+
this.projectionUsed = projectionUsed;
575+
}
576+
555577
/**
556578
* Return the x-death header.
557579
* @return the header.

spring-amqp/src/main/java/org/springframework/amqp/support/converter/AbstractJackson2MessageConverter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ private Object convertContent(Message message, Object conversionHint, MessagePro
305305
if (inferredType != null && this.useProjectionForInterfaces && inferredType.isInterface()
306306
&& !inferredType.getRawClass().getPackage().getName().startsWith("java.util")) { // List etc
307307
content = this.projectingConverter.convert(message, inferredType.getRawClass());
308+
properties.setProjectionUsed(true);
308309
}
309310
else if (inferredType != null && this.alwaysConvertToInferredType) {
310311
content = tryConverType(message, encoding, inferredType);

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/adapter/MessagingMessageListenerAdapter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,11 @@ private void handleException(org.springframework.amqp.core.Message amqpMessage,
183183
protected void invokeHandlerAndProcessResult(@Nullable org.springframework.amqp.core.Message amqpMessage,
184184
Channel channel, Message<?> message) throws Exception { // NOSONAR
185185

186-
if (logger.isDebugEnabled()) {
186+
boolean projectionUsed = amqpMessage == null ? false : amqpMessage.getMessageProperties().isProjectionUsed();
187+
if (projectionUsed) {
188+
amqpMessage.getMessageProperties().setProjectionUsed(false);
189+
}
190+
if (logger.isDebugEnabled() && !projectionUsed) {
187191
logger.debug("Processing [" + message + "]");
188192
}
189193
InvocationResult result = null;

0 commit comments

Comments
 (0)