Skip to content

Commit fa1aa1c

Browse files
authored
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. * Remove inadvertently pushed file.
1 parent 4f3a153 commit fa1aa1c

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
@@ -242,6 +242,9 @@ subprojects { subproject ->
242242
compileKotlin.dependsOn updateCopyrights
243243

244244
test {
245+
maxHeapSize = '2g'
246+
jvmArgs '-XX:+HeapDumpOnOutOfMemoryError'
247+
245248
testLogging {
246249
events "skipped", "failed"
247250
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.4.0-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
@@ -187,7 +187,11 @@ private void handleException(org.springframework.amqp.core.Message amqpMessage,
187187
protected void invokeHandlerAndProcessResult(@Nullable org.springframework.amqp.core.Message amqpMessage,
188188
Channel channel, Message<?> message) throws Exception { // NOSONAR
189189

190-
if (logger.isDebugEnabled()) {
190+
boolean projectionUsed = amqpMessage == null ? false : amqpMessage.getMessageProperties().isProjectionUsed();
191+
if (projectionUsed) {
192+
amqpMessage.getMessageProperties().setProjectionUsed(false);
193+
}
194+
if (logger.isDebugEnabled() && !projectionUsed) {
191195
logger.debug("Processing [" + message + "]");
192196
}
193197
InvocationResult result = null;

0 commit comments

Comments
 (0)