Search in sources :

Example 81 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class ConfigUsingDestinationOptionsTest method testInvalidSelectorConfig.

@Test(timeout = 60000)
public void testInvalidSelectorConfig() throws JMSException {
    ActiveMQQueue queue = new ActiveMQQueue("TEST.FOO?consumer.selector=test||1");
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
    Connection conn = factory.createConnection();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQMessageConsumer cons;
    // JMS selector should be priority
    try {
        cons = (ActiveMQMessageConsumer) sess.createConsumer(queue, "test||1");
        fail("Selector should be invalid" + cons);
    } catch (InvalidSelectorException e) {
    }
    // Test setting using JMS destinations
    try {
        cons = (ActiveMQMessageConsumer) sess.createConsumer(queue);
        fail("Selector should be invalid" + cons);
    } catch (InvalidSelectorException e) {
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) InvalidSelectorException(javax.jms.InvalidSelectorException) ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) Connection(javax.jms.Connection) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Session(javax.jms.Session) Test(org.junit.Test)

Example 82 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class AMQ3410Test method testNoFactorySet.

public void testNoFactorySet() throws Exception {
    AmqBrowseCommand command = new AmqBrowseCommand();
    CommandContext context = new CommandContext();
    context.setFormatter(new CommandShellOutputFormatter(System.out));
    command.setCommandContext(context);
    List<String> tokens = new ArrayList<>();
    tokens.addAll(DEFAULT_OPTIONS);
    tokens.addAll(DEFAULT_TOKENS);
    command.execute(tokens);
    assertNotNull(command.getConnectionFactory());
    assertTrue(command.getConnectionFactory() instanceof ActiveMQConnectionFactory);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) CommandContext(org.apache.activemq.console.CommandContext) CommandShellOutputFormatter(org.apache.activemq.console.formatter.CommandShellOutputFormatter) ArrayList(java.util.ArrayList)

Example 83 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class DefaultQueueSender method main.

public static void main(String[] args) {
    String uri = "tcp://localhost:61616";
    String text = "Hello World!";
    Connection connection = null;
    if (args.length < 1) {
        printUsage();
        System.exit(1);
    }
    int idx = 0;
    String arg = args[0];
    if (arg.equals("-uri")) {
        if (args.length == 1) {
            printUsage();
            System.exit(1);
        }
        uri = args[1];
        idx += 2;
    }
    String queueName = args[idx];
    LOG.info("Connecting to: " + uri);
    LOG.info("Queue name is " + queueName);
    if (++idx < args.length) {
        text = args[idx];
    }
    try {
        ConnectionFactory factory = new ActiveMQConnectionFactory(uri);
        connection = factory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination destination = session.createQueue(queueName);
        MessageProducer producer = session.createProducer(destination);
        Message message = session.createTextMessage(text);
        producer.send(message);
    } catch (JMSException e) {
        LOG.info("Exception occurred: " + e.toString());
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
            }
        }
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(javax.jms.Destination) ConnectionFactory(javax.jms.ConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Message(javax.jms.Message) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 84 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class CheckDuplicateMessagesOnDuplexTest method openLocalConnection.

private void openLocalConnection() throws JMSException {
    localFactory = new ActiveMQConnectionFactory(localBroker.getVmConnectorURI());
    // localFactory.setSendAcksAsync(false);
    localConnection = localFactory.createConnection();
    localConnection.start();
    localSession = localConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    consumer = localSession.createConsumer(localSession.createQueue("testqueue"));
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory)

Example 85 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class CheckDuplicateMessagesOnDuplexTest method openRemoteConnection.

private void openRemoteConnection() throws JMSException {
    remoteFactory = new ActiveMQConnectionFactory(remoteBroker.getVmConnectorURI());
    // remoteFactory.setSendAcksAsync(false);
    remoteConnection = remoteFactory.createConnection();
    remoteConnection.start();
    remoteSession = remoteConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    producer = remoteSession.createProducer(remoteSession.createQueue("testqueue"));
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory)

Aggregations

ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)436 Session (javax.jms.Session)148 Connection (javax.jms.Connection)144 Test (org.junit.Test)107 MessageConsumer (javax.jms.MessageConsumer)103 TextMessage (javax.jms.TextMessage)81 MessageProducer (javax.jms.MessageProducer)79 Message (javax.jms.Message)74 Queue (javax.jms.Queue)66 JMSException (javax.jms.JMSException)65 ActiveMQConnection (org.apache.activemq.ActiveMQConnection)51 ConnectionFactory (javax.jms.ConnectionFactory)48 Destination (javax.jms.Destination)42 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)36 BrokerService (org.apache.activemq.broker.BrokerService)32 CountDownLatch (java.util.concurrent.CountDownLatch)28 Before (org.junit.Before)27 MessageListener (javax.jms.MessageListener)26 CamelContext (org.apache.camel.CamelContext)26 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)23