Search in sources :

Example 1 with ActiveMQSession

use of org.apache.activemq.ActiveMQSession in project pinpoint by naver.

the class ActiveMQClientITBase method testQueuePush.

@Test
public void testQueuePush() throws Exception {
    // Given
    final String testQueueName = "TestPushQueue";
    final ActiveMQQueue testQueue = new ActiveMQQueue(testQueueName);
    final String testMessage = "Hello World for Queue!";
    final CountDownLatch consumerLatch = new CountDownLatch(1);
    final Collection<Throwable> consumerThrowables = new CopyOnWriteArrayList<Throwable>();
    // create producer
    ActiveMQSession producerSession = ActiveMQClientITHelper.createSession(getProducerBrokerName(), getProducerBrokerUrl());
    MessageProducer producer = producerSession.createProducer(testQueue);
    final TextMessage expectedTextMessage = producerSession.createTextMessage(testMessage);
    // create consumer
    ActiveMQSession consumerSession = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
    MessageConsumer consumer = consumerSession.createConsumer(testQueue);
    consumer.setMessageListener(new AssertTextMessageListener(consumerLatch, consumerThrowables, expectedTextMessage));
    // When
    producer.send(expectedTextMessage);
    consumerLatch.await(1L, TimeUnit.SECONDS);
    // Then
    assertNoConsumerError(consumerThrowables);
    // Wait till all traces are recorded (consumer traces are recorded from another thread)
    awaitAndVerifyTraceCount(2, 5000L);
    // trace count : 1
    verifyProducerSendEvent(testQueue);
    // trace count : 1
    verifyConsumerPushEvent(testQueue);
}
Also used : ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) MessageConsumer(javax.jms.MessageConsumer) ActiveMQSession(org.apache.activemq.ActiveMQSession) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) CountDownLatch(java.util.concurrent.CountDownLatch) TextMessage(javax.jms.TextMessage) AssertTextMessageListener(com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.AssertTextMessageListener) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.Test)

Example 2 with ActiveMQSession

use of org.apache.activemq.ActiveMQSession in project pinpoint by naver.

the class ActiveMQClientITBase method testTopicPush.

@Test
public void testTopicPush() throws Exception {
    // Given
    final String testTopicName = "TestPushTopic";
    final ActiveMQTopic testTopic = new ActiveMQTopic(testTopicName);
    final String testMessage = "Hello World for Topic!";
    final int numMessageConsumers = 2;
    final CountDownLatch consumerConsumeLatch = new CountDownLatch(numMessageConsumers);
    final Collection<Throwable> consumerThrowables = new CopyOnWriteArrayList<Throwable>();
    // create producer
    ActiveMQSession producerSession = ActiveMQClientITHelper.createSession(getProducerBrokerName(), getProducerBrokerUrl());
    MessageProducer producer = new MessageProducerBuilder(producerSession, testTopic).waitTillStarted().build();
    final TextMessage expectedTextMessage = producerSession.createTextMessage(testMessage);
    // create 2 consumers
    ActiveMQSession consumer1Session = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
    new MessageConsumerBuilder(consumer1Session, testTopic).withMessageListener(new AssertTextMessageListener(consumerConsumeLatch, consumerThrowables, expectedTextMessage)).waitTillStarted().build();
    ActiveMQSession consumer2Session = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
    new MessageConsumerBuilder(consumer2Session, testTopic).withMessageListener(new AssertTextMessageListener(consumerConsumeLatch, consumerThrowables, expectedTextMessage)).waitTillStarted().build();
    // When
    producer.send(expectedTextMessage);
    consumerConsumeLatch.await(1L, TimeUnit.SECONDS);
    // Then
    // Wait till all traces are recorded (consumer traces are recorded from another thread)
    awaitAndVerifyTraceCount(3, 1000L);
    // trace count : 1
    verifyProducerSendEvent(testTopic);
    // trace count : 1
    verifyConsumerPushEvent(testTopic);
    // trace count : 1
    verifyConsumerPushEvent(testTopic);
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) MessageConsumerBuilder(com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.MessageConsumerBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) MessageProducerBuilder(com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.MessageProducerBuilder) ActiveMQSession(org.apache.activemq.ActiveMQSession) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) AssertTextMessageListener(com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.AssertTextMessageListener) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.Test)

Example 3 with ActiveMQSession

use of org.apache.activemq.ActiveMQSession in project pinpoint by naver.

the class ActiveMQClientITBase method testQueuePull.

@Test
public void testQueuePull() throws Exception {
    // Given
    final String testQueueName = "TestPullQueue";
    final ActiveMQQueue testQueue = new ActiveMQQueue(testQueueName);
    final String testMessage = "Hello World for Queue!";
    // create producer
    ActiveMQSession producerSession = ActiveMQClientITHelper.createSession(getProducerBrokerName(), getProducerBrokerUrl());
    MessageProducer producer = producerSession.createProducer(testQueue);
    final TextMessage expectedTextMessage = producerSession.createTextMessage(testMessage);
    // When
    ActiveMQSession consumerSession = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
    MessageConsumer consumer = consumerSession.createConsumer(testQueue);
    // Then
    producer.send(expectedTextMessage);
    Message message = consumer.receive(1000L);
    Assert.assertEquals(testMessage, ((TextMessage) message).getText());
    // Wait till all traces are recorded (consumer traces are recorded from another thread)
    awaitAndVerifyTraceCount(5, 5000L);
    // trace count : 1
    verifyProducerSendEvent(testQueue);
    // trace count : 4
    verifyConsumerPullEvent(testQueue, consumer, expectedTextMessage);
}
Also used : ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) MessageConsumer(javax.jms.MessageConsumer) ActiveMQSession(org.apache.activemq.ActiveMQSession) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 4 with ActiveMQSession

use of org.apache.activemq.ActiveMQSession in project pinpoint by naver.

the class ActiveMQClientITBase method testTopicPull.

@Test
public void testTopicPull() throws Exception {
    // Given
    final String testTopicName = "TestPullTopic";
    final ActiveMQTopic testTopic = new ActiveMQTopic(testTopicName);
    final String testMessage = "Hello World for Topic!";
    // create producer
    ActiveMQSession producerSession = ActiveMQClientITHelper.createSession(getProducerBrokerName(), getProducerBrokerUrl());
    MessageProducer producer = new MessageProducerBuilder(producerSession, testTopic).waitTillStarted().build();
    final TextMessage expectedTextMessage = producerSession.createTextMessage(testMessage);
    // create 2 consumers
    ActiveMQSession consumer1Session = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
    MessageConsumer consumer1 = new MessageConsumerBuilder(consumer1Session, testTopic).waitTillStarted().build();
    ActiveMQSession consumer2Session = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
    MessageConsumer consumer2 = new MessageConsumerBuilder(consumer2Session, testTopic).waitTillStarted().build();
    // When
    producer.send(expectedTextMessage);
    Message message1 = consumer1.receive(1000L);
    Message message2 = consumer2.receive(1000L);
    Assert.assertEquals(testMessage, ((TextMessage) message1).getText());
    Assert.assertEquals(testMessage, ((TextMessage) message2).getText());
    // Wait till all traces are recorded (consumer traces are recorded from another thread)
    awaitAndVerifyTraceCount(9, 5000L);
    // trace count : 1
    verifyProducerSendEvent(testTopic);
    // trace count : 4
    verifyConsumerPullEvent(testTopic, consumer1, expectedTextMessage);
    // trace count : 4
    verifyConsumerPullEvent(testTopic, consumer2, expectedTextMessage);
}
Also used : MessageProducerBuilder(com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.MessageProducerBuilder) ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) MessageConsumer(javax.jms.MessageConsumer) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ActiveMQSession(org.apache.activemq.ActiveMQSession) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) MessageConsumerBuilder(com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.MessageConsumerBuilder) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 5 with ActiveMQSession

use of org.apache.activemq.ActiveMQSession 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)

Aggregations

ActiveMQSession (org.apache.activemq.ActiveMQSession)6 MessageProducer (javax.jms.MessageProducer)4 TextMessage (javax.jms.TextMessage)4 Test (org.junit.Test)4 MessageConsumer (javax.jms.MessageConsumer)3 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)3 ActiveMQSessionGetter (com.navercorp.pinpoint.plugin.activemq.client.field.getter.ActiveMQSessionGetter)2 SocketGetter (com.navercorp.pinpoint.plugin.activemq.client.field.getter.SocketGetter)2 AssertTextMessageListener (com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.AssertTextMessageListener)2 MessageConsumerBuilder (com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.MessageConsumerBuilder)2 MessageProducerBuilder (com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.MessageProducerBuilder)2 Socket (java.net.Socket)2 SocketAddress (java.net.SocketAddress)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Message (javax.jms.Message)2 ActiveMQConnection (org.apache.activemq.ActiveMQConnection)2 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)2 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)2 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)2