Search in sources :

Example 1 with ActiveMQTopic

use of org.apache.activemq.command.ActiveMQTopic 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 2 with ActiveMQTopic

use of org.apache.activemq.command.ActiveMQTopic in project ignite by apache.

the class IgniteMqttStreamerTest method testMultipleTopics_NoQoS_MultipleEntriesOneMessage.

/**
     * @throws Exception If failed.
     */
public void testMultipleTopics_NoQoS_MultipleEntriesOneMessage() throws Exception {
    // configure streamer
    streamer.setMultipleTupleExtractor(multipleTupleExtractor());
    streamer.setTopics(MULTIPLE_TOPIC_NAMES);
    // subscribe to cache PUT events
    CountDownLatch latch = subscribeToPutEvents(50);
    // action time
    streamer.start();
    // send messages
    sendMessages(MULTIPLE_TOPIC_NAMES, 0, 50, true);
    // assertions
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    assertCacheEntriesLoaded(50);
    assertTrue(broker.getBroker().getDestinationMap().size() >= 4);
    assertTrue(broker.getBroker().getDestinationMap().containsKey(new ActiveMQTopic("def")));
    assertTrue(broker.getBroker().getDestinationMap().containsKey(new ActiveMQTopic("ghi")));
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 3 with ActiveMQTopic

use of org.apache.activemq.command.ActiveMQTopic in project ignite by apache.

the class IgniteMqttStreamerTest method testMultipleTopics_NoQoS_OneEntryPerMessage.

/**
     * @throws Exception If failed.
     */
public void testMultipleTopics_NoQoS_OneEntryPerMessage() throws Exception {
    // configure streamer
    streamer.setSingleTupleExtractor(singleTupleExtractor());
    streamer.setTopics(MULTIPLE_TOPIC_NAMES);
    // subscribe to cache PUT events
    CountDownLatch latch = subscribeToPutEvents(50);
    // action time
    streamer.start();
    // send messages
    sendMessages(MULTIPLE_TOPIC_NAMES, 0, 50, false);
    // assertions
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    assertCacheEntriesLoaded(50);
    assertTrue(broker.getBroker().getDestinationMap().size() >= 4);
    assertTrue(broker.getBroker().getDestinationMap().containsKey(new ActiveMQTopic("def")));
    assertTrue(broker.getBroker().getDestinationMap().containsKey(new ActiveMQTopic("ghi")));
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 4 with ActiveMQTopic

use of org.apache.activemq.command.ActiveMQTopic 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 ActiveMQTopic

use of org.apache.activemq.command.ActiveMQTopic in project ignite by apache.

the class IgniteJmsStreamerTest method testTopicFromName.

/**
     * @throws Exception If failed.
     */
public void testTopicFromName() throws JMSException, InterruptedException {
    Destination dest = new ActiveMQTopic(TOPIC_NAME);
    try (IgniteDataStreamer<String, String> dataStreamer = grid().dataStreamer(DEFAULT_CACHE_NAME)) {
        JmsStreamer<ObjectMessage, String, String> jmsStreamer = newJmsStreamer(ObjectMessage.class, dataStreamer);
        jmsStreamer.setDestinationType(Topic.class);
        jmsStreamer.setDestinationName(TOPIC_NAME);
        // subscribe to cache PUT events and return a countdown latch starting at CACHE_ENTRY_COUNT
        CountDownLatch latch = subscribeToPutEvents(CACHE_ENTRY_COUNT);
        jmsStreamer.start();
        // produce messages
        produceObjectMessages(dest, false);
        // all cache PUT events received in 10 seconds
        latch.await(10, TimeUnit.SECONDS);
        assertAllCacheEntriesLoaded();
        jmsStreamer.stop();
    }
}
Also used : Destination(javax.jms.Destination) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ObjectMessage(javax.jms.ObjectMessage) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 Destination (javax.jms.Destination)3 TextMessage (javax.jms.TextMessage)3 MessageConsumerBuilder (com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.MessageConsumerBuilder)2 MessageProducerBuilder (com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.MessageProducerBuilder)2 MessageProducer (javax.jms.MessageProducer)2 ObjectMessage (javax.jms.ObjectMessage)2 ActiveMQSession (org.apache.activemq.ActiveMQSession)2 Test (org.junit.Test)2 AssertTextMessageListener (com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.AssertTextMessageListener)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Message (javax.jms.Message)1 MessageConsumer (javax.jms.MessageConsumer)1 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)1