Search in sources :

Example 1 with ActiveMQMessage

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());
}
Also used : Exchange(org.apache.camel.Exchange) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) Message(javax.jms.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Test(org.junit.Test)

Example 2 with ActiveMQMessage

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);
    }
}
Also used : MessageDispatch(org.apache.activemq.command.MessageDispatch) ActiveMQSessionGetter(com.navercorp.pinpoint.plugin.activemq.client.field.getter.ActiveMQSessionGetter) ActiveMQSession(org.apache.activemq.ActiveMQSession) SocketGetter(com.navercorp.pinpoint.plugin.activemq.client.field.getter.SocketGetter) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) Transport(org.apache.activemq.transport.Transport) SocketAddress(java.net.SocketAddress) Socket(java.net.Socket) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 3 with ActiveMQMessage

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();
    }
}
Also used : MessageDispatch(org.apache.activemq.command.MessageDispatch) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage)

Example 4 with ActiveMQMessage

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;
}
Also used : MessageDispatch(org.apache.activemq.command.MessageDispatch) ActiveMQSessionGetter(com.navercorp.pinpoint.plugin.activemq.client.field.getter.ActiveMQSessionGetter) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) Message(org.apache.activemq.command.Message) ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage)

Aggregations

ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)4 MessageDispatch (org.apache.activemq.command.MessageDispatch)3 ActiveMQSessionGetter (com.navercorp.pinpoint.plugin.activemq.client.field.getter.ActiveMQSessionGetter)2 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)2 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)1 SocketGetter (com.navercorp.pinpoint.plugin.activemq.client.field.getter.SocketGetter)1 Socket (java.net.Socket)1 SocketAddress (java.net.SocketAddress)1 Message (javax.jms.Message)1 ActiveMQConnection (org.apache.activemq.ActiveMQConnection)1 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)1 ActiveMQSession (org.apache.activemq.ActiveMQSession)1 Message (org.apache.activemq.command.Message)1 Transport (org.apache.activemq.transport.Transport)1 Exchange (org.apache.camel.Exchange)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 Test (org.junit.Test)1