use of javax.jms.Connection in project sling by apache.
the class JMSQueueManagerTest method checkMessagesInQueue.
private void checkMessagesInQueue(String name, int expected) throws JMSException {
Connection connection = amqConnectionFactoryService.getConnectionFactory().createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(name);
QueueBrowser browser = session.createBrowser(queue);
int n = 0;
for (Enumeration e = browser.getEnumeration(); e.hasMoreElements(); ) {
Message m = (Message) e.nextElement();
LOGGER.info("Message at {} is {} ", n, m);
n++;
}
browser.close();
session.close();
connection.stop();
assertEquals(expected, n);
}
use of javax.jms.Connection in project tomee by apache.
the class JmsMdbContainerTest method sendMessage.
private void sendMessage(final ConnectionFactory connectionFactory, final String bean, final String text) throws JMSException, InterruptedException {
WidgetBean.lock.lock();
try {
final Connection connection = connectionFactory.createConnection();
connection.start();
// Create a Session
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final Queue queue = session.createQueue(bean);
// Create a MessageProducer from the Session to the Topic or Queue
final MessageProducer producer = session.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// Create a message
final TextMessage message = session.createTextMessage(text);
// Tell the producer to send the message
producer.send(message);
WidgetBean.messageRecieved.await();
} finally {
WidgetBean.lock.unlock();
}
}
use of javax.jms.Connection in project tomee by apache.
the class JmsProxyTest method testProxy.
public void testProxy() throws Exception {
// create reciever object
final JmsProxyTest.TestObject testObject = new JmsProxyTest.TestObject("foo");
final MdbInvoker mdbInvoker = new MdbInvoker(connectionFactory, testObject);
// Create a Session
final Connection connection = connectionFactory.createConnection();
connection.start();
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the request Queue
final Destination requestQueue = session.createQueue(REQUEST_QUEUE_NAME);
final MessageConsumer consumer = session.createConsumer(requestQueue);
consumer.setMessageListener(mdbInvoker);
// create in invoker
final JmsProxyTest.TestInterface testInterface = MdbProxy.newProxyInstance(JmsProxyTest.TestInterface.class, connectionFactory, REQUEST_QUEUE_NAME);
assertEquals("foobar", testInterface.echo("bar"));
assertEquals("foobar", testInterface.echo("bar"));
assertEquals("foobar", testInterface.echo("bar"));
assertEquals("foobar", testInterface.echo("bar"));
assertEquals("foobar", testInterface.echo("bar"));
}
use of javax.jms.Connection in project tomee by apache.
the class JmsTest method testProxy.
public void testProxy() throws Exception {
// Create a Session
final Connection connection = connectionFactory.createConnection();
try {
connection.start();
final Destination requestQueue = createListener(connection);
createSender(connection, requestQueue);
} finally {
MdbUtil.close(connection);
}
}
use of javax.jms.Connection in project tomee by apache.
the class Messages method receiveMessage.
public String receiveMessage() throws JMSException {
Connection connection = null;
Session session = null;
MessageConsumer consumer = null;
try {
connection = connectionFactory.createConnection();
connection.start();
// Create a Session
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create a MessageConsumer from the Session to the Topic or Queue
consumer = session.createConsumer(chatQueue);
// Wait for a message
TextMessage message = (TextMessage) consumer.receive(1000);
return message.getText();
} finally {
if (consumer != null) {
consumer.close();
}
if (session != null) {
session.close();
}
if (connection != null) {
connection.close();
}
}
}
Aggregations