use of javax.jms.Connection in project camel by apache.
the class JmsProducer method testConnectionOnStartup.
/**
* Pre tests the connection before starting the listening.
* <p/>
* In case of connection failure the exception is thrown which prevents Camel from starting.
*
* @throws FailedToCreateProducerException is thrown if testing the connection failed
*/
protected void testConnectionOnStartup() throws FailedToCreateProducerException {
try {
CamelJmsTemplate template = (CamelJmsTemplate) getInOnlyTemplate();
if (log.isDebugEnabled()) {
log.debug("Testing JMS Connection on startup for destination: " + template.getDefaultDestinationName());
}
Connection conn = template.getConnectionFactory().createConnection();
JmsUtils.closeConnection(conn);
log.debug("Successfully tested JMS Connection on startup for destination: " + template.getDefaultDestinationName());
} catch (Exception e) {
throw new FailedToCreateProducerException(getEndpoint(), e);
}
}
use of javax.jms.Connection in project camel by apache.
the class JmsConsumer method testConnectionOnStartup.
/**
* Pre tests the connection before starting the listening.
* <p/>
* In case of connection failure the exception is thrown which prevents Camel from starting.
*
* @throws FailedToCreateConsumerException is thrown if testing the connection failed
*/
protected void testConnectionOnStartup() throws FailedToCreateConsumerException {
try {
log.debug("Testing JMS Connection on startup for destination: {}", getDestinationName());
Connection con = listenerContainer.getConnectionFactory().createConnection();
JmsUtils.closeConnection(con);
log.debug("Successfully tested JMS Connection on startup for destination: {}", getDestinationName());
} catch (Exception e) {
String msg = "Cannot get JMS Connection on startup for destination " + getDestinationName();
throw new FailedToCreateConsumerException(getEndpoint(), msg, e);
}
}
use of javax.jms.Connection in project hive by apache.
the class TestMsgBusConnection method connectClient.
private void connectClient() throws JMSException {
ConnectionFactory connFac = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection conn = connFac.createConnection();
conn.start();
Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
Destination hcatTopic = session.createTopic("planetlab.hcat");
consumer = session.createConsumer(hcatTopic);
}
use of javax.jms.Connection in project javaee7-samples by javaee-samples.
the class ClassicMessageReceiver method receiveMessage.
public String receiveMessage() {
String response = null;
Connection connection = null;
try {
connection = connectionFactory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer messageConsumer = session.createConsumer(demoQueue);
Message message = messageConsumer.receive(5000);
response = message.getBody(String.class);
} catch (JMSException ex) {
ex.printStackTrace();
} finally {
if (connection != null) {
try {
connection.close();
} catch (JMSException ex) {
ex.printStackTrace();
}
}
}
return response;
}
use of javax.jms.Connection in project quickstarts by jboss-switchyard.
the class CamelJMSBindingTest method sendTextToQueue.
private void sendTextToQueue(final String text, final String queueName) throws Exception {
InitialContext initialContext = null;
Connection connection = null;
Session session = null;
MessageProducer producer = null;
try {
initialContext = new InitialContext();
final Queue testQueue = (Queue) initialContext.lookup(queueName);
final ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup("ConnectionFactory");
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
producer = session.createProducer(testQueue);
producer.send(session.createTextMessage(text));
} finally {
if (producer != null) {
producer.close();
}
if (session != null) {
session.close();
}
if (connection != null) {
connection.close();
}
if (initialContext != null) {
initialContext.close();
}
}
}
Aggregations