Search in sources :

Example 6 with ActiveMQDestination

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

the class ExclusiveTest method testExclusiveQueueConsumerSettingUsingAddressQueueParameters.

@Test
public void testExclusiveQueueConsumerSettingUsingAddressQueueParameters() throws Exception {
    ConnectionFactory fact = getCF();
    Connection connection = fact.createConnection();
    try {
        Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Queue queue = session.createQueue("random?exclusive=true");
        assertEquals("random", queue.getQueueName());
        ActiveMQDestination a = (ActiveMQDestination) queue;
        assertTrue(a.getQueueAttributes().getExclusive());
        MessageProducer producer = session.createProducer(queue);
        MessageConsumer consumer1 = session.createConsumer(queue);
        MessageConsumer consumer2 = session.createConsumer(queue);
        MessageConsumer consumer3 = session.createConsumer(queue);
        connection.start();
        for (int j = 0; j < 100; j++) {
            TextMessage message = session.createTextMessage();
            message.setText("Message" + j);
            producer.send(message);
        }
        // All msgs should go to the first consumer
        for (int j = 0; j < 100; j++) {
            TextMessage tm = (TextMessage) consumer1.receive(10000);
            assertNotNull(tm);
            assertEquals("Message" + j, tm.getText());
            tm = (TextMessage) consumer2.receiveNoWait();
            assertNull(tm);
            tm = (TextMessage) consumer3.receiveNoWait();
            assertNull(tm);
        }
    } finally {
        connection.close();
    }
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Test(org.junit.Test)

Example 7 with ActiveMQDestination

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

the class AMQPToJMSCoreTest method testMessageDestination.

@Test
public void testMessageDestination() throws Exception {
    System.out.println("foo");
    AmqpClient client = new AmqpClient(new URI("tcp://127.0.0.1:61616"), null, null);
    AmqpConnection amqpconnection = client.connect();
    try {
        AmqpSession session = amqpconnection.createSession();
        AmqpSender sender = session.createSender(queueName);
        AmqpMessage message = new AmqpMessage();
        message.setMessageId("MessageID:" + 0);
        // message.setApplicationProperty("_AMQ_ROUTING_TYPE", (byte) 1);
        message.getWrappedMessage().setHeader(new Header());
        message.getWrappedMessage().getHeader().setDeliveryCount(new UnsignedInteger(2));
        sender.send(message);
    } finally {
        amqpconnection.close();
    }
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
    Connection connection = null;
    try {
        connection = factory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = session.createConsumer(ActiveMQJMSClient.createQueue(queueName));
        connection.start();
        Message message = consumer.receive(2000);
        Assert.assertNotNull(message);
        ActiveMQDestination jmsDestination = (ActiveMQDestination) message.getJMSDestination();
        Assert.assertEquals(queueName, jmsDestination.getAddress());
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) MessageConsumer(javax.jms.MessageConsumer) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Message(javax.jms.Message) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) Connection(javax.jms.Connection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) URI(java.net.URI) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Header(org.apache.qpid.proton.amqp.messaging.Header) UnsignedInteger(org.apache.qpid.proton.amqp.UnsignedInteger) Session(javax.jms.Session) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Test(org.junit.Test)

Example 8 with ActiveMQDestination

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

the class ResourceAdapterTest method testStartActivation.

@Test
public void testStartActivation() throws Exception {
    ActiveMQServer server = createServer(false);
    try {
        server.start();
        ServerLocator locator = createInVMNonHALocator();
        ClientSessionFactory factory = createSessionFactory(locator);
        ClientSession session = factory.createSession(false, false, false);
        ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue("test");
        session.createQueue(queue.getSimpleAddress(), queue.getSimpleAddress(), true);
        session.close();
        ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
        ra.setConnectorClassName(INVM_CONNECTOR_FACTORY);
        ra.setUserName("userGlobal");
        ra.setPassword("passwordGlobal");
        ra.start(new BootstrapContext());
        Connection conn = ra.getDefaultActiveMQConnectionFactory().createConnection();
        conn.close();
        ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
        spec.setResourceAdapter(ra);
        spec.setUseJNDI(false);
        spec.setUser("user");
        spec.setPassword("password");
        spec.setDestinationType("javax.jms.Topic");
        spec.setDestination("test");
        spec.setMinSession(1);
        spec.setMaxSession(1);
        ActiveMQActivation activation = new ActiveMQActivation(ra, new MessageEndpointFactory(), spec);
        activation.start();
        activation.stop();
        ra.stop();
        locator.close();
    } finally {
        server.stop();
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ActiveMQActivation(org.apache.activemq.artemis.ra.inflow.ActiveMQActivation) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Connection(javax.jms.Connection) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Test(org.junit.Test)

Example 9 with ActiveMQDestination

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

the class ObjectFactoryTest method testDestination.

@Test(timeout = 1000)
public void testDestination() throws Exception {
    // Create sample destination
    ActiveMQDestination dest = (ActiveMQDestination) ActiveMQJMSClient.createQueue(RandomUtil.randomString());
    // Create reference
    Reference ref = JNDIReferenceFactory.createReference(dest.getClass().getName(), dest);
    // Get object created based on reference
    ActiveMQDestination temp;
    JNDIReferenceFactory refFactory = new JNDIReferenceFactory();
    temp = (ActiveMQDestination) refFactory.getObjectInstance(ref, null, null, null);
    // Check settings
    assertEquals(dest.getAddress(), temp.getAddress());
}
Also used : Reference(javax.naming.Reference) JNDIReferenceFactory(org.apache.activemq.artemis.jndi.JNDIReferenceFactory) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Test(org.junit.Test)

Example 10 with ActiveMQDestination

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

the class DestinationObjectFactoryTest method testReference.

// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testReference() throws Exception {
    ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue(RandomUtil.randomString());
    Reference reference = queue.getReference();
    String factoryName = reference.getFactoryClassName();
    Class<?> factoryClass = Class.forName(factoryName);
    ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
    Object object = factory.getObjectInstance(reference, null, null, null);
    Assert.assertNotNull(object);
    Assert.assertTrue(object instanceof ActiveMQDestination);
    Assert.assertEquals(queue, object);
}
Also used : ObjectFactory(javax.naming.spi.ObjectFactory) Reference(javax.naming.Reference) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Test(org.junit.Test)

Aggregations

ActiveMQDestination (org.apache.activemq.artemis.jms.client.ActiveMQDestination)21 Test (org.junit.Test)14 Connection (javax.jms.Connection)6 MessageConsumer (javax.jms.MessageConsumer)4 Session (javax.jms.Session)4 Reference (javax.naming.Reference)4 MessageProducer (javax.jms.MessageProducer)3 Queue (javax.jms.Queue)3 TextMessage (javax.jms.TextMessage)3 Topic (javax.jms.Topic)3 ObjectFactory (javax.naming.spi.ObjectFactory)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 Queue (org.apache.activemq.artemis.core.server.Queue)3 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)3 Destination (javax.jms.Destination)2 JMSException (javax.jms.JMSException)2 Referenceable (javax.naming.Referenceable)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)2