Search in sources :

Example 66 with Connection

use of javax.jms.Connection in project tomee by apache.

the class MdbTestClient method createConnection.

protected Connection createConnection() throws JMSException {
    final Connection connection = connectionFactory.createConnection();
    connection.start();
    return connection;
}
Also used : Connection(javax.jms.Connection)

Example 67 with Connection

use of javax.jms.Connection in project tomee by apache.

the class ChatBeanTest method test.

public void test() throws Exception {
    EJBContainer.createEJBContainer().getContext().bind("inject", this);
    final Connection connection = connectionFactory.createConnection();
    connection.start();
    final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final MessageProducer questions = session.createProducer(questionQueue);
    final MessageConsumer answers = session.createConsumer(answerQueue);
    sendText("Hello World!", questions, session);
    assertEquals("Hello, Test Case!", receiveText(answers));
    sendText("How are you?", questions, session);
    assertEquals("I'm doing well.", receiveText(answers));
    sendText("Still spinning?", questions, session);
    assertEquals("Once every day, as usual.", receiveText(answers));
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 68 with Connection

use of javax.jms.Connection in project tomee by apache.

the class ChatBean method respond.

private void respond(String text) throws JMSException {
    Connection connection = null;
    Session session = null;
    try {
        connection = connectionFactory.createConnection();
        connection.start();
        // Create a Session
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // Create a MessageProducer from the Session to the Topic or Queue
        MessageProducer producer = session.createProducer(answerQueue);
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        // Create a message
        TextMessage message = session.createTextMessage(text);
        // Tell the producer to send the message
        producer.send(message);
    } finally {
        // Clean up
        if (session != null) {
            session.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 69 with Connection

use of javax.jms.Connection in project qpid by apache.

the class ConnectionHelper method createConnection.

/**
     * Creates a JMS Connection from one of the supported URL formats plus options.
     *
     * @param url an AMQP 0.10 URL, an extended AMQP 0-10 URL, a Broker URL or a Connection URL.
     * @param opts a String containing the options encoded using the same form as the C++ qpid::messaging
     *        Connection class.
     * @return a javax.jms.Connection.
     */
public static Connection createConnection(String url, String opts) {
    String connectionUrl = createConnectionURL(url, opts);
    _log.info("ConnectionHelper.createConnection() {}", connectionUrl);
    // Initialise JNDI names etc into properties
    Properties props = new Properties();
    props.setProperty("java.naming.factory.initial", "org.apache.qpid.jndi.PropertiesFileInitialContextFactory");
    props.setProperty("connectionfactory.ConnectionFactory", connectionUrl);
    Connection connection = null;
    try {
        Context jndi = new InitialContext(props);
        ConnectionFactory connectionFactory = (ConnectionFactory) jndi.lookup("ConnectionFactory");
        connection = connectionFactory.createConnection();
    } catch (NamingException ne) {
        _log.info("NamingException {} caught in createConnection()", ne.getMessage());
    } catch (JMSException jmse) {
        _log.info("JMSException {} caught in createConnection()", jmse.getMessage());
    }
    return connection;
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) ConnectionFactory(javax.jms.ConnectionFactory) Connection(javax.jms.Connection) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext)

Example 70 with Connection

use of javax.jms.Connection in project hive by apache.

the class TestNotificationListener method setUp.

@Before
public void setUp() throws Exception {
    System.setProperty("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
    System.setProperty("java.naming.provider.url", "vm://localhost?broker.persistent=false");
    ConnectionFactory connFac = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
    Connection conn = connFac.createConnection();
    conn.start();
    // We want message to be sent when session commits, thus we run in
    // transacted mode.
    Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
    Destination hcatTopic = session.createTopic(HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX);
    MessageConsumer consumer1 = session.createConsumer(hcatTopic);
    consumer1.setMessageListener(this);
    Destination tblTopic = session.createTopic(HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX + ".mydb.mytbl");
    MessageConsumer consumer2 = session.createConsumer(tblTopic);
    consumer2.setMessageListener(this);
    Destination dbTopic = session.createTopic(HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX + ".mydb");
    MessageConsumer consumer3 = session.createConsumer(dbTopic);
    consumer3.setMessageListener(this);
    setUpHiveConf();
    hiveConf.set(ConfVars.METASTORE_EVENT_LISTENERS.varname, NotificationListener.class.getName());
    hiveConf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory");
    SessionState.start(new CliSessionState(hiveConf));
    driver = new Driver(hiveConf);
    client = new HiveMetaStoreClient(hiveConf);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(javax.jms.Destination) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) HiveMetaStoreClient(org.apache.hadoop.hive.metastore.HiveMetaStoreClient) Connection(javax.jms.Connection) Driver(org.apache.hadoop.hive.ql.Driver) CliSessionState(org.apache.hadoop.hive.cli.CliSessionState) Session(javax.jms.Session) Before(org.junit.Before)

Aggregations

Connection (javax.jms.Connection)124 Session (javax.jms.Session)88 Test (org.junit.Test)62 MessageProducer (javax.jms.MessageProducer)46 ConnectionFactory (javax.jms.ConnectionFactory)44 Message (javax.jms.Message)38 MessageConsumer (javax.jms.MessageConsumer)38 JMSException (javax.jms.JMSException)32 TextMessage (javax.jms.TextMessage)32 QueueConnection (javax.jms.QueueConnection)22 TopicConnection (javax.jms.TopicConnection)22 Destination (javax.jms.Destination)15 Queue (javax.jms.Queue)12 QueueConnectionFactory (javax.jms.QueueConnectionFactory)11 TopicConnectionFactory (javax.jms.TopicConnectionFactory)11 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)7 JmsTemplate (org.springframework.jms.core.JmsTemplate)7 TransactionStatus (org.springframework.transaction.TransactionStatus)7 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)7 TransactionAttribute (javax.ejb.TransactionAttribute)4