Skip to content

Commit

Permalink
JMS resource fix for receive; FetchMsg property
Browse files Browse the repository at this point in the history
  • Loading branch information
mjok committed Apr 22, 2020
1 parent fc36ce9 commit bc41b7b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@

package com.jkoolcloud.remora.advices;

import static com.jkoolcloud.remora.core.utils.ReflectionUtils.getFieldValue;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.named;

import java.lang.instrument.Instrumentation;
import java.lang.reflect.Method;

import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.QueueReceiver;
import javax.jms.TextMessage;
import javax.jms.*;

import org.tinylog.Logger;
import org.tinylog.TaggedLogger;
Expand All @@ -54,6 +52,9 @@ public class JMSReceiveAdvice extends BaseTransformers implements RemoraAdvice {
public static boolean load = true;
@RemoraConfig.Configurable
public static boolean logging = false;
@RemoraConfig.Configurable
private static boolean fetchMsg = false;

public static TaggedLogger logger;

/**
Expand Down Expand Up @@ -184,9 +185,25 @@ public static void after(@Advice.This MessageConsumer obj, //
ed.addPropertyIfExist("MESSAGE_ID", message.getJMSMessageID());
ed.addPropertyIfExist("CORR_ID", message.getJMSCorrelationID());
ed.addPropertyIfExist("TYPE", message.getJMSType());
if (message instanceof TextMessage) {
Destination jmsDestination = message.getJMSDestination();
if (jmsDestination == null) {
jmsDestination = getFieldValue(message, Destination.class, "destination");
if (logging) {
logger.debug("Destination2: " + jmsDestination);
}
} else {
if (logging) {
logger.debug("Destination1: " + jmsDestination);
}
}
ed.setResource(String.valueOf(jmsDestination), EntryDefinition.ResourceType.QUEUE);
if (fetchMsg && message instanceof TextMessage) {
ed.addPropertyIfExist("MSG", ((TextMessage) message).getText());
}
} else {
if (logging) {
logger.debug("Message is null");
}
}
fillDefaultValuesAfter(ed, startTime, exception, logging ? logger : null);
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class JMSSendAdvice extends BaseTransformers implements RemoraAdvice {
public static boolean load = true;
@RemoraConfig.Configurable
public static boolean logging = false;
@RemoraConfig.Configurable
private static boolean fetchMsg = false;
public static TaggedLogger logger;
static AgentBuilder.Transformer.ForAdvice advice = new AgentBuilder.Transformer.ForAdvice()
.include(JMSSendAdvice.class.getClassLoader()) //
Expand Down Expand Up @@ -125,7 +127,7 @@ public static void before(@Advice.This MessageProducer thiz, //
ed.addPropertyIfExist("MESSAGE_ID", message.getJMSMessageID());
ed.addPropertyIfExist("CORR_ID", message.getJMSCorrelationID());
ed.addPropertyIfExist("TYPE", message.getJMSType());
if (message instanceof TextMessage) {
if (fetchMsg && message instanceof TextMessage) {
ed.addPropertyIfExist("MSG", ((TextMessage) message).getText());
}
try {
Expand Down

0 comments on commit bc41b7b

Please sign in to comment.