use of javax.jms.MessageConsumer in project cxf by apache.
the class TestReceiver method drainQueue.
private void drainQueue() {
try (ResourceCloser closer = new ResourceCloser()) {
Connection connection = closer.register(connectionFactory.createConnection());
connection.start();
Session session = closer.register(connection.createSession(false, Session.AUTO_ACKNOWLEDGE));
MessageConsumer consumer = closer.register(session.createConsumer(session.createQueue(receiveQueueName)));
javax.jms.Message message = null;
do {
message = consumer.receive(100);
} while (message != null);
} catch (JMSException e) {
throw JMSUtil.convertJmsException(e);
}
}
use of javax.jms.MessageConsumer in project cxf by apache.
the class PooledConnectionTempQueueTest method receiveAndRespondWithMessageIdAsCorrelationId.
public void receiveAndRespondWithMessageIdAsCorrelationId(ConnectionFactory connectionFactory, String queueName) throws JMSException {
Connection con = connectionFactory.createConnection();
Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(session.createQueue(queueName));
final javax.jms.Message inMessage = consumer.receive();
// String requestMessageId = inMessage.getJMSMessageID();
// System.out.println("Received message " + requestMessageId);
final TextMessage replyMessage = session.createTextMessage("Result");
replyMessage.setJMSCorrelationID(inMessage.getJMSMessageID());
final MessageProducer producer = session.createProducer(inMessage.getJMSReplyTo());
// System.out.println("Sending reply to " + inMessage.getJMSReplyTo());
producer.send(replyMessage);
producer.close();
consumer.close();
session.close();
con.close();
}
use of javax.jms.MessageConsumer in project tomee by apache.
the class JMSContextImpl method createDurableConsumer.
@Override
public JMSConsumer createDurableConsumer(final Topic topic, final String name) {
try {
// JMS 2 only: final JMSConsumerImpl consumer = new JMSConsumerImpl(this, session().createDurableConsumer(topic, name));
final MessageConsumer delegate = session().createDurableSubscriber(topic, name);
checkAutoStart();
return new JMSConsumerImpl(this, delegate);
} catch (final JMSException e) {
throw toRuntimeException(e);
}
}
use of javax.jms.MessageConsumer in project tomee by apache.
the class JmsTest method createSender.
@SuppressWarnings("unchecked")
private synchronized void createSender(final Connection connection, final Destination requestQueue) throws JMSException {
Session session = null;
MessageProducer producer = null;
MessageConsumer consumer = null;
try {
// create request
final Map<String, Object> request = new TreeMap<String, Object>();
request.put("args", new Object[] { "cheese" });
// create a new temp response queue
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final Destination responseQueue = session.createTemporaryQueue();
// Create a request messages
final ObjectMessage requestMessage = session.createObjectMessage();
requestMessage.setJMSReplyTo(responseQueue);
requestMessage.setObject((Serializable) request);
// Send the request message
producer = session.createProducer(requestQueue);
producer.send(requestMessage);
// wait for the response message
consumer = session.createConsumer(responseQueue);
final Message message = consumer.receive(30000);
// verify message
assertNotNull("Did not get a response message", message);
assertTrue("Response message is not an ObjectMessage", message instanceof ObjectMessage);
final ObjectMessage responseMessage = (ObjectMessage) message;
final Serializable object = responseMessage.getObject();
assertNotNull("Response ObjectMessage contains a null object");
assertTrue("Response ObjectMessage does not contain an instance of Map", object instanceof Map);
final Map<String, String> response = (Map<String, String>) object;
// process results
final String returnValue = response.get("return");
assertEquals("test-cheese", returnValue);
} finally {
MdbUtil.close(consumer);
MdbUtil.close(producer);
MdbUtil.close(session);
}
}
use of javax.jms.MessageConsumer 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"));
}
Aggregations