use of com.rabbitmq.client.Command in project LinkAgent by shulieTech.
the class ChannelNProcessDeliveryInterceptor method beforeFirst.
@Override
public void beforeFirst(Advice advice) {
Object[] args = advice.getParameterArray();
String methodName = advice.getBehaviorName();
if (!PradarSwitcher.isClusterTestEnabled()) {
logger.warn("PradarSwitcher isClusterTestEnabled false, {} to start shadow {} skip it", advice.getTargetClass().getName(), methodName);
return;
}
AMQP.Basic.Deliver m = (AMQP.Basic.Deliver) args[1];
validatePressureMeasurement(m.getConsumerTag());
try {
Command command = (Command) args[0];
BasicProperties contentHeader = (BasicProperties) command.getContentHeader();
Map<String, Object> headers = contentHeader.getHeaders();
if (null != headers && headers.get(PradarService.PRADAR_CLUSTER_TEST_KEY) != null && ClusterTestUtils.isClusterTestRequest(headers.get(PradarService.PRADAR_CLUSTER_TEST_KEY).toString())) {
Pradar.setClusterTest(true);
}
if (!Pradar.isClusterTest()) {
String routingKey = m.getRoutingKey();
if (StringUtils.isNotBlank(routingKey) && ClusterTestUtils.isClusterTestRequest(routingKey)) {
Pradar.setClusterTest(true);
}
String exchange = m.getExchange();
if (StringUtils.isNotBlank(exchange) && ClusterTestUtils.isClusterTestRequest(exchange)) {
Pradar.setClusterTest(true);
}
}
} catch (Throwable e) {
if (Pradar.isClusterTest()) {
throw new PressureMeasureError(e);
}
}
}
use of com.rabbitmq.client.Command in project LinkAgent by shulieTech.
the class ChannelNProcessDeliveryInterceptor method beforeTrace.
@Override
public SpanRecord beforeTrace(Advice advice) {
if (ConfigCache.isWorkWithSpring()) {
return null;
}
Object[] args = advice.getParameterArray();
Command command = (Command) args[0];
Deliver method = (Deliver) args[1];
SpanRecord record = new SpanRecord();
record.setService(method.getExchange());
record.setMethod(method.getRoutingKey());
BasicProperties contentHeader = (BasicProperties) command.getContentHeader();
Map<String, Object> headers = contentHeader.getHeaders();
if (headers != null) {
Map<String, String> rpcContext = new HashMap<String, String>();
for (String key : Pradar.getInvokeContextTransformKeys()) {
String value = ObjectUtils.toString(headers.get(key));
if (!StringUtil.isEmpty(value)) {
rpcContext.put(key, value);
}
}
record.setContext(rpcContext);
}
byte[] body = command.getContentBody();
record.setRequestSize(body.length);
record.setRequest(body);
Channel channel = (Channel) advice.getTarget();
Connection connection = channel.getConnection();
record.setRemoteIp(connection.getAddress().getHostAddress());
record.setPort(connection.getPort() + "");
return record;
}
Aggregations