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;
}
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));
}
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();
}
}
}
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;
}
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);
}
Aggregations