Search in sources :

Example 26 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class ConnectionAbstract method createAMQPConnectionFactory.

private ConnectionFactory createAMQPConnectionFactory() {
    if (brokerURL.startsWith("tcp://")) {
        // replacing tcp:// by amqp://
        brokerURL = "amqp" + brokerURL.substring(3);
    }
    JmsConnectionFactory cf = new JmsConnectionFactory(user, password, brokerURL);
    if (clientID != null) {
        cf.setClientID(clientID);
    }
    try {
        Connection connection = cf.createConnection();
        connection.close();
        return cf;
    } catch (JMSSecurityException e) {
        // if a security exception will get the user and password through an input
        context.err.println("Connection failed::" + e.getMessage());
        userPassword();
        return new JmsConnectionFactory(user, password, brokerURL);
    } catch (JMSException e) {
        // if a connection exception will ask for the URL, user and password
        context.err.println("Connection failed::" + e.getMessage());
        brokerURL = input("--url", "Type in the broker URL for a retry (e.g. tcp://localhost:61616)", brokerURL);
        userPassword();
        return new JmsConnectionFactory(user, password, brokerURL);
    }
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) JMSSecurityException(javax.jms.JMSSecurityException) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException)

Example 27 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class JMSWebSocketConnectionTest method testSendReceiveOverWS.

@Test(timeout = 30000)
public void testSendReceiveOverWS() throws Exception {
    JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
    JmsConnection connection = (JmsConnection) factory.createConnection();
    try {
        Session session = connection.createSession();
        Queue queue = session.createQueue(getQueueName());
        MessageProducer producer = session.createProducer(queue);
        producer.send(session.createMessage());
        producer.close();
        connection.start();
        MessageConsumer consumer = session.createConsumer(queue);
        Message message = consumer.receive(1000);
        assertNotNull(message);
    } finally {
        connection.close();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) JmsConnection(org.apache.qpid.jms.JmsConnection) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) Session(javax.jms.Session) Test(org.junit.Test)

Example 28 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class JMSWebSocketConnectionTest method sendLargeMessageViaAMQP.

protected void sendLargeMessageViaAMQP() throws Exception {
    JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
    doSendLargeMessageViaOpenWire(factory.createConnection());
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory)

Example 29 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class SyncSendTest method newCF.

// this will set ack as synchronous, to make sure we make proper measures against the sync on disk
private ConnectionFactory newCF() {
    if (protocol.equals("core")) {
        ConnectionFactory factory = new ActiveMQConnectionFactory();
        ((ActiveMQConnectionFactory) factory).setBlockOnAcknowledge(true);
        return factory;
    } else if (protocol.equals("amqp")) {
        final JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:61616");
        factory.setForceAsyncAcks(true);
        return factory;
    } else {
        org.apache.activemq.ActiveMQConnectionFactory cf = new org.apache.activemq.ActiveMQConnectionFactory("tcp://localhost:61616?wireFormat.cacheEnabled=true");
        cf.setSendAcksAsync(false);
        return cf;
    }
}
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) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory)

Example 30 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class ProtonCPPExample method main.

public static void main(final String[] args) throws Exception {
    Connection connection = null;
    InitialContext initialContext = null;
    try {
        // Create an initial context to perform the JNDI lookup.
        initialContext = new InitialContext();
        // if you wanted to use Core JMS, use this line instead.
        // ConnectionFactory cf = new ActiveMQConnectionFactory();
        ConnectionFactory cf = new JmsConnectionFactory("amqp://localhost:61616");
        // Create a the JMS objects
        connection = cf.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // Perform the look-ups
        Queue queue = session.createQueue("exampleQueue");
        MessageConsumer messageConsumer = session.createConsumer(queue);
        MessageProducer producerAnswer = session.createProducer(queue);
        // Start the connection
        connection.start();
        System.out.println("On a shell script, execute the following:");
        System.out.println("./compile.sh");
        System.out.println("./hello");
        for (int i = 0; i < 10; i++) {
            try {
                // Step 5. Finally, receive the message
                TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
                if (messageReceived == null) {
                    System.out.println("No messages");
                // We are not going to issue this as an error because
                // we also use this example as part of our tests on artemis
                // this is not considered an error, just that no messages arrived (i.e. hello wasn't called)
                } else {
                    System.out.println("message received: " + messageReceived.getText());
                    // Sending message back to client
                    producerAnswer.send(session.createTextMessage("HELLO from Apache ActiveMQ Artemis " + i + "!!"));
                }
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    } finally {
        // Step 9. Be sure to close our resources!
        if (initialContext != null) {
            initialContext.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) InitialContext(javax.naming.InitialContext) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Aggregations

JmsConnectionFactory (org.apache.qpid.jms.JmsConnectionFactory)40 Connection (javax.jms.Connection)19 Session (javax.jms.Session)19 MessageConsumer (javax.jms.MessageConsumer)17 MessageProducer (javax.jms.MessageProducer)17 Test (org.junit.Test)17 TextMessage (javax.jms.TextMessage)14 ConnectionFactory (javax.jms.ConnectionFactory)10 Queue (javax.jms.Queue)10 Message (javax.jms.Message)8 BytesMessage (javax.jms.BytesMessage)4 JmsConnection (org.apache.qpid.jms.JmsConnection)4 JMSException (javax.jms.JMSException)3 Topic (javax.jms.Topic)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 AMQPComponent (org.apache.camel.component.amqp.AMQPComponent)3 URI (java.net.URI)2 JMSSecurityException (javax.jms.JMSSecurityException)2 InitialContext (javax.naming.InitialContext)2 Configuration (org.apache.activemq.artemis.core.config.Configuration)2