use of org.apache.activemq.command.ActiveMQMessage in project camel by apache.
the class ActiveMQOriginalDestinationTest method testActiveMQOriginalDestination.
@Test
public void testActiveMQOriginalDestination() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.sendBody("activemq:queue:foo", "Hello World");
assertMockEndpointsSatisfied();
// consume from bar
Exchange out = consumer.receive("activemq:queue:bar", 5000);
assertNotNull(out);
// and we should have foo as the original destination
JmsMessage msg = out.getIn(JmsMessage.class);
Message jms = msg.getJmsMessage();
ActiveMQMessage amq = assertIsInstanceOf(ActiveMQMessage.class, jms);
ActiveMQDestination original = amq.getOriginalDestination();
assertNotNull(original);
assertEquals("foo", original.getPhysicalName());
assertEquals("Queue", original.getDestinationTypeAsString());
}
use of org.apache.activemq.command.ActiveMQMessage in project pinpoint by naver.
the class ActiveMQMessageConsumerDispatchInterceptor method doInBeforeTrace.
@Override
protected void doInBeforeTrace(SpanRecorder recorder, Object target, Object[] args) {
recorder.recordServiceType(ActiveMQClientConstants.ACTIVEMQ_CLIENT);
ActiveMQSession session = ((ActiveMQSessionGetter) target)._$PINPOINT$_getActiveMQSession();
ActiveMQConnection connection = session.getConnection();
Transport transport = getRootTransport(((TransportGetter) connection)._$PINPOINT$_getTransport());
Socket socket = ((SocketGetter) transport)._$PINPOINT$_getSocket();
SocketAddress localSocketAddress = socket.getLocalSocketAddress();
String endPoint = ActiveMQClientUtils.getEndPoint(localSocketAddress);
// Endpoint should be the local socket address of the consumer.
recorder.recordEndPoint(endPoint);
SocketAddress remoteSocketAddress = socket.getRemoteSocketAddress();
String remoteAddress = ActiveMQClientUtils.getEndPoint(remoteSocketAddress);
// Remote address is the socket address of where the consumer is connected to.
recorder.recordRemoteAddress(remoteAddress);
MessageDispatch md = (MessageDispatch) args[0];
ActiveMQMessage message = (ActiveMQMessage) md.getMessage();
ActiveMQDestination destination = message.getDestination();
// Rpc name is the URI of the queue/topic we're consuming from.
recorder.recordRpcName(destination.getQualifiedName());
// Record acceptor host as the queue/topic name in order to generate virtual queue node.
recorder.recordAcceptorHost(destination.getPhysicalName());
String parentApplicationName = ActiveMQClientHeader.getParentApplicationName(message, null);
if (!recorder.isRoot() && parentApplicationName != null) {
short parentApplicationType = ActiveMQClientHeader.getParentApplicationType(message, ServiceType.UNDEFINED.getCode());
recorder.recordParentApplication(parentApplicationName, parentApplicationType);
}
}
use of org.apache.activemq.command.ActiveMQMessage in project pinpoint by naver.
the class ActiveMQMessageConsumerDispatchInterceptor method createTrace.
@Override
protected Trace createTrace(Object target, Object[] args) {
if (!validate(target, args)) {
return null;
}
MessageDispatch md = (MessageDispatch) args[0];
ActiveMQMessage message = (ActiveMQMessage) md.getMessage();
if (filterDestination(message.getDestination())) {
return null;
}
// These might trigger unmarshalling.
if (!ActiveMQClientHeader.getSampled(message, true)) {
return traceContext.disableSampling();
}
String transactionId = ActiveMQClientHeader.getTraceId(message, null);
if (transactionId != null) {
long parentSpanId = ActiveMQClientHeader.getParentSpanId(message, SpanId.NULL);
long spanId = ActiveMQClientHeader.getSpanId(message, SpanId.NULL);
short flags = ActiveMQClientHeader.getFlags(message, (short) 0);
final TraceId traceId = traceContext.createTraceId(transactionId, parentSpanId, spanId, flags);
return traceContext.continueTraceObject(traceId);
} else {
return traceContext.newTraceObject();
}
}
use of org.apache.activemq.command.ActiveMQMessage in project pinpoint by naver.
the class ActiveMQMessageConsumerDispatchInterceptor method validate.
private boolean validate(Object target, Object[] args) {
if (!(target instanceof ActiveMQMessageConsumer)) {
return false;
}
if (!(target instanceof ActiveMQSessionGetter)) {
if (isDebug) {
logger.debug("Invalid target object. Need field accessor({}).", ActiveMQSessionGetter.class.getName());
}
return false;
}
if (!validateTransport(((ActiveMQSessionGetter) target)._$PINPOINT$_getActiveMQSession())) {
return false;
}
if (args == null || args.length < 1) {
return false;
}
if (!(args[0] instanceof MessageDispatch)) {
return false;
}
MessageDispatch md = (MessageDispatch) args[0];
Message message = md.getMessage();
if (!(message instanceof ActiveMQMessage)) {
return false;
}
return true;
}
Aggregations