Search in sources :

Example 76 with Destination

use of javax.jms.Destination 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);
    }
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Serializable(java.io.Serializable) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TreeMap(java.util.TreeMap) ObjectMessage(javax.jms.ObjectMessage) MessageProducer(javax.jms.MessageProducer) Map(java.util.Map) TreeMap(java.util.TreeMap) Session(javax.jms.Session)

Example 77 with Destination

use of javax.jms.Destination 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"));
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) Session(javax.jms.Session)

Example 78 with Destination

use of javax.jms.Destination in project tomee by apache.

the class MdbFieldInjectionTests method setUp.

protected void setUp() throws Exception {
    super.setUp();
    final Destination destination = (Destination) initialContext.lookup("FieldInjectionMdbBean");
    ejbObject = MdbProxy.newProxyInstance(EncMdbObject.class, connectionFactory, destination);
    TestManager.getDatabase().createEntityTable();
}
Also used : Destination(javax.jms.Destination)

Example 79 with Destination

use of javax.jms.Destination in project tomee by apache.

the class MdbInterceptorTests method setUp.

protected void setUp() throws Exception {
    super.setUp();
    final Destination destination = (Destination) initialContext.lookup("InterceptorMdbBean");
    ejbObject = MdbProxy.newProxyInstance(InterceptorMdbObject.class, connectionFactory, destination);
    TestManager.getDatabase().createEntityTable();
}
Also used : Destination(javax.jms.Destination)

Example 80 with Destination

use of javax.jms.Destination in project tomee by apache.

the class MdbJndiEncTests method setUp.

protected void setUp() throws Exception {
    super.setUp();
    final Destination destination = (Destination) initialContext.lookup("EncMdbBean");
    ejbObject = MdbProxy.newProxyInstance(EncMdbObject.class, connectionFactory, destination);
    TestManager.getDatabase().createEntityTable();
}
Also used : Destination(javax.jms.Destination)

Aggregations

Destination (javax.jms.Destination)178 Test (org.junit.Test)51 TextMessage (javax.jms.TextMessage)47 Session (javax.jms.Session)46 JMSException (javax.jms.JMSException)45 Connection (javax.jms.Connection)32 MessageProducer (javax.jms.MessageProducer)31 Message (javax.jms.Message)30 ConnectionFactory (javax.jms.ConnectionFactory)24 MessageConsumer (javax.jms.MessageConsumer)24 JMSContext (javax.jms.JMSContext)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 ObjectMessage (javax.jms.ObjectMessage)12 StubTextMessage (org.springframework.jms.StubTextMessage)11 InitialContext (javax.naming.InitialContext)10 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)10 Queue (javax.jms.Queue)8 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)8 MapMessage (javax.jms.MapMessage)7 HashMap (java.util.HashMap)6