use of javax.jms.Session in project storm by apache.
the class JmsSpoutTest method sendMessage.
public Message sendMessage(ConnectionFactory connectionFactory, Destination destination) throws JMSException {
Session mySess = connectionFactory.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
MessageProducer producer = mySess.createProducer(destination);
TextMessage msg = mySess.createTextMessage();
msg.setText("Hello World");
LOG.info("Sending Message: {}", msg.getText());
producer.send(msg);
return msg;
}
use of javax.jms.Session 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.Session 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.Session 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();
}
}
}
use of javax.jms.Session in project quickstarts by jboss-switchyard.
the class JMSClient method sendToActiveMQ.
private static void sendToActiveMQ() throws Exception {
ConnectionFactory cf = new ActiveMQConnectionFactory(AMQ_USER, AMQ_PASSWD, AMQ_BROKER_URL);
Connection conn = cf.createConnection();
try {
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
final MessageProducer producer = session.createProducer(session.createQueue(QUEUE_NAME));
BufferedReader reader = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(MESSAGE_PAYLOAD)));
StringBuilder buf = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
buf.append(line);
}
reader.close();
Message message = session.createTextMessage(buf.toString());
producer.send(message);
System.out.println("Message sent. Please see server console output");
} finally {
conn.close();
}
}
Aggregations