Search in sources :

Example 6 with ActiveMQQueue

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

the class BrokerPluginExample method sendConsumeCore.

private static void sendConsumeCore() throws JMSException {
    Connection connection = null;
    try {
        // Perform a lookup on the Connection Factory
        ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616");
        Queue queue = new ActiveMQQueue("exampleQueue");
        // Create a JMS Connection
        connection = cf.createConnection();
        // Create a JMS Session
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // Create a JMS Message Producer
        MessageProducer producer = session.createProducer(queue);
        // Create a Text Message
        TextMessage message = session.createTextMessage("This is a text message");
        // Send the Message
        producer.send(message);
        // Create a JMS Message Consumer
        MessageConsumer messageConsumer = session.createConsumer(queue);
        // Start the Connection
        connection.start();
        // Receive the message
        TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
        if (messageReceived.getStringProperty("count") == null) {
            throw new RuntimeException(("missed property count"));
        }
        System.out.println("message = " + messageReceived.getText() + " property count (added by interceptor = " + messageReceived.getStringProperty("count") + ")");
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) ActiveMQQueue(org.apache.activemq.artemis.jms.client.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) ActiveMQQueue(org.apache.activemq.artemis.jms.client.ActiveMQQueue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 7 with ActiveMQQueue

use of org.apache.activemq.artemis.jms.client.ActiveMQQueue in project pentaho-kettle by pentaho.

the class ActiveMQProvider method getDestination.

@Override
public Destination getDestination(JmsDelegate delegate) {
    checkNotNull(delegate.destinationName, getString(PKG, "JmsWebsphereMQ.DestinationNameRequired"));
    String destName = delegate.destinationName;
    return isQueue(delegate) ? new ActiveMQQueue(destName) : new ActiveMQTopic(destName);
}
Also used : ActiveMQTopic(org.apache.activemq.artemis.jms.client.ActiveMQTopic) ActiveMQQueue(org.apache.activemq.artemis.jms.client.ActiveMQQueue) BaseMessages.getString(org.pentaho.di.i18n.BaseMessages.getString)

Example 8 with ActiveMQQueue

use of org.apache.activemq.artemis.jms.client.ActiveMQQueue in project pentaho-kettle by pentaho.

the class ActiveMQProvider method getDestination.

@Override
public Destination getDestination(JmsDelegate delegate, VariableSpace variableSpace) {
    checkNotNull(delegate.destinationName, getString(JmsConstants.PKG, "JmsWebsphereMQ.DestinationNameRequired"));
    String destName = variableSpace.environmentSubstitute(delegate.destinationName);
    return isQueue(delegate, variableSpace) ? new ActiveMQQueue(destName) : new ActiveMQTopic(destName);
}
Also used : ActiveMQTopic(org.apache.activemq.artemis.jms.client.ActiveMQTopic) ActiveMQQueue(org.apache.activemq.artemis.jms.client.ActiveMQQueue) BaseMessages.getString(org.pentaho.di.i18n.BaseMessages.getString)

Example 9 with ActiveMQQueue

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

the class HornetQProtocolManagerTest method testLegacy2.

/**
 * This test will use an ArtemisConnectionFactory with clientProtocolManager=
 */
@Test
public void testLegacy2() throws Exception {
    ConnectionFactoryConfiguration configuration = new ConnectionFactoryConfigurationImpl();
    configuration.setConnectorNames("legacy");
    configuration.setName("legacy");
    configuration.setProtocolManagerFactoryStr(HornetQClientProtocolManagerFactory.class.getName());
    embeddedJMS.getJMSServerManager().createConnectionFactory(false, configuration, "legacy");
    // WORKAROUND: the 2.0.0 broker introduced addressing change and the 2.2.0 broker added compatibility for old
    // client libraries relying on the legacy prefixes. The new client being used in this test needs prefix explicitly.
    Queue queue = new ActiveMQQueue("jms.queue.testQueue");
    ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) embeddedJMS.lookup("legacy");
    Connection connection = connectionFactory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(queue);
    TextMessage message = session.createTextMessage("Test");
    for (int i = 0; i < 5; i++) {
        message.setStringProperty(Message.HDR_DUPLICATE_DETECTION_ID.toString(), "duplicate");
        producer.send(message);
    }
    connection.start();
    MessageConsumer consumer = session.createConsumer(queue);
    TextMessage messageRec = (TextMessage) consumer.receive(5000);
    Assert.assertNotNull(messageRec);
    Assert.assertEquals("Test", messageRec.getText());
    Assert.assertNull(consumer.receiveNoWait());
    connection.close();
    connectionFactory.close();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) HornetQClientProtocolManagerFactory(org.apache.activemq.artemis.core.protocol.hornetq.client.HornetQClientProtocolManagerFactory) ConnectionFactoryConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.ConnectionFactoryConfigurationImpl) Connection(javax.jms.Connection) ActiveMQQueue(org.apache.activemq.artemis.jms.client.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) ConnectionFactoryConfiguration(org.apache.activemq.artemis.jms.server.config.ConnectionFactoryConfiguration) ActiveMQQueue(org.apache.activemq.artemis.jms.client.ActiveMQQueue) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Example 10 with ActiveMQQueue

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

the class ReferenceableTest method testReferenceQueue.

@Test
public void testReferenceQueue() throws Exception {
    Reference queueRef = ((Referenceable) queue1).getReference();
    String factoryName = queueRef.getFactoryClassName();
    Class<?> factoryClass = Class.forName(factoryName);
    ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
    Object instance = factory.getObjectInstance(queueRef, null, null, null);
    ProxyAssertSupport.assertTrue(instance instanceof ActiveMQDestination);
    ActiveMQQueue queue2 = (ActiveMQQueue) instance;
    ProxyAssertSupport.assertEquals(queue1.getQueueName(), queue2.getQueueName());
    simpleSendReceive(cf, queue2);
}
Also used : Referenceable(javax.naming.Referenceable) ObjectFactory(javax.naming.spi.ObjectFactory) Reference(javax.naming.Reference) ActiveMQQueue(org.apache.activemq.artemis.jms.client.ActiveMQQueue) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Test(org.junit.Test)

Aggregations

ActiveMQQueue (org.apache.activemq.artemis.jms.client.ActiveMQQueue)10 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 Test (org.junit.Test)3 Connection (javax.jms.Connection)2 MessageConsumer (javax.jms.MessageConsumer)2 MessageProducer (javax.jms.MessageProducer)2 Queue (javax.jms.Queue)2 Session (javax.jms.Session)2 TextMessage (javax.jms.TextMessage)2 Reference (javax.naming.Reference)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)2 ActiveMQTopic (org.apache.activemq.artemis.jms.client.ActiveMQTopic)2 BaseMessages.getString (org.pentaho.di.i18n.BaseMessages.getString)2 URI (java.net.URI)1 Properties (java.util.Properties)1 ConnectionFactory (javax.jms.ConnectionFactory)1 Referenceable (javax.naming.Referenceable)1 ObjectFactory (javax.naming.spi.ObjectFactory)1 Consumes (javax.ws.rs.Consumes)1