Search in sources :

Example 66 with ActiveMQDestination

use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.

the class AdvisoryBrokerTest method testProducerAdvisories.

public void testProducerAdvisories() throws Exception {
    ActiveMQDestination queue = new ActiveMQQueue("test");
    ActiveMQDestination destination = AdvisorySupport.getProducerAdvisoryTopic(queue);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(consumerInfo1);
    assertNoMessagesLeft(connection1);
    // Setup a producer.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    producerInfo2.setDestination(queue);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(producerInfo2);
    // We should get an advisory of the new producer.
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ProducerInfo) m1.getDataStructure()).getProducerId(), producerInfo2.getProducerId());
    // Close the second connection.
    connection2.request(closeConnectionInfo(connectionInfo2));
    connection2.stop();
    // We should get an advisory of the producer closing
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    RemoveInfo r = (RemoveInfo) m1.getDataStructure();
    assertEquals(r.getObjectId(), producerInfo2.getProducerId());
    assertNoMessagesLeft(connection2);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ProducerInfo(org.apache.activemq.command.ProducerInfo) Message(org.apache.activemq.command.Message) RemoveInfo(org.apache.activemq.command.RemoveInfo) StubConnection(org.apache.activemq.broker.StubConnection) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 67 with ActiveMQDestination

use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.

the class DestinationRemoveRestartTest method doCheckRemoveActionAfterRestart.

public void doCheckRemoveActionAfterRestart() throws Exception {
    boolean res = true;
    final ActiveMQDestination[] list = broker.getRegionBroker().getDestinations();
    for (final ActiveMQDestination element : list) {
        final Destination destination = broker.getDestination(element);
        if (destination.getActiveMQDestination().getPhysicalName().equals(destinationName)) {
            res = false;
            break;
        }
    }
    assertTrue("The removed destination is reloaded after restart !", res);
}
Also used : ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 68 with ActiveMQDestination

use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.

the class MessageGroupTest method testGroupedMessagesDeliveredToOnlyOneConsumer.

public void testGroupedMessagesDeliveredToOnlyOneConsumer() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup a first connection
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer1 = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    // Send the messages.
    for (int i = 0; i < 4; i++) {
        TextMessage message = session.createTextMessage("message " + i);
        message.setStringProperty("JMSXGroupID", "TEST-GROUP");
        message.setIntProperty("JMSXGroupSeq", i + 1);
        LOG.info("sending message: " + message);
        producer.send(message);
    }
    // the first 3
    for (int i = 0; i < 3; i++) {
        TextMessage m1 = (TextMessage) consumer1.receive(500);
        assertNotNull("m1 is null for index: " + i, m1);
        assertEquals(m1.getIntProperty("JMSXGroupSeq"), i + 1);
    }
    // Setup a second connection
    Connection connection1 = factory.createConnection(userName, password);
    connection1.start();
    Session session2 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer2 = session2.createConsumer(destination);
    // Close the first consumer.
    consumer1.close();
    // The last messages should now go the the second consumer.
    for (int i = 0; i < 1; i++) {
        TextMessage m1 = (TextMessage) consumer2.receive(500);
        assertNotNull("m1 is null for index: " + i, m1);
        assertEquals(m1.getIntProperty("JMSXGroupSeq"), 4 + i);
    }
    // assert that there are no other messages left for the consumer 2
    Message m = consumer2.receive(100);
    assertNull("consumer 2 has some messages left", m);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Session(javax.jms.Session)

Example 69 with ActiveMQDestination

use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.

the class MessageGroupTest method testAddingConsumer.

public void testAddingConsumer() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup a first connection
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(destination);
    // MessageConsumer consumer = session.createConsumer(destination);
    TextMessage message = session.createTextMessage("message");
    message.setStringProperty("JMSXGroupID", "TEST-GROUP");
    LOG.info("sending message: " + message);
    producer.send(message);
    MessageConsumer consumer = session.createConsumer(destination);
    TextMessage msg = (TextMessage) consumer.receive();
    assertNotNull(msg);
    boolean first = msg.getBooleanProperty("JMSXGroupFirstForConsumer");
    assertTrue(first);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Session(javax.jms.Session)

Example 70 with ActiveMQDestination

use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.

the class MessageGroupConfigTest method doTestGroupConfiguration.

public MessageGroupMap doTestGroupConfiguration(String type, Class classType) throws Exception {
    broker = new BrokerService();
    PolicyEntry defaultEntry = new PolicyEntry();
    defaultEntry.setMessageGroupMapFactoryType(type);
    PolicyMap policyMap = new PolicyMap();
    policyMap.setDefaultEntry(defaultEntry);
    broker.setDestinationPolicy(policyMap);
    broker.start();
    super.topic = false;
    ActiveMQDestination destination = (ActiveMQDestination) createDestination("org.apache.foo");
    Queue brokerDestination = (Queue) broker.getDestination(destination);
    assertNotNull(brokerDestination);
    MessageGroupMap messageGroupMap = brokerDestination.getMessageGroupOwners();
    assertNotNull(messageGroupMap);
    assertTrue(messageGroupMap.getClass().isAssignableFrom(classType));
    return messageGroupMap;
}
Also used : SimpleMessageGroupMap(org.apache.activemq.broker.region.group.SimpleMessageGroupMap) MessageGroupMap(org.apache.activemq.broker.region.group.MessageGroupMap) CachedMessageGroupMap(org.apache.activemq.broker.region.group.CachedMessageGroupMap) PolicyMap(org.apache.activemq.broker.region.policy.PolicyMap) BrokerService(org.apache.activemq.broker.BrokerService) PolicyEntry(org.apache.activemq.broker.region.policy.PolicyEntry) Queue(org.apache.activemq.broker.region.Queue) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Aggregations

ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)165 Session (javax.jms.Session)62 MessageConsumer (javax.jms.MessageConsumer)49 Message (org.apache.activemq.command.Message)46 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)45 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)44 SessionInfo (org.apache.activemq.command.SessionInfo)44 ProducerInfo (org.apache.activemq.command.ProducerInfo)42 Test (org.junit.Test)41 Message (javax.jms.Message)40 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)40 TextMessage (javax.jms.TextMessage)31 BasicOpenWireTest (org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest)24 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)22 MessageProducer (javax.jms.MessageProducer)18 XATransactionId (org.apache.activemq.command.XATransactionId)15 CountDownLatch (java.util.concurrent.CountDownLatch)14 ActiveMQMessageProducer (org.apache.activemq.ActiveMQMessageProducer)12 MessageAck (org.apache.activemq.command.MessageAck)12 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)11