Search in sources :

Example 11 with ActiveMQObjectMessage

use of org.apache.activemq.command.ActiveMQObjectMessage in project activemq-artemis by apache.

the class ObjectMessageNotSerializableTest method testSendNotSerializeableObjectMessage.

public void testSendNotSerializeableObjectMessage() throws Exception {
    final ActiveMQDestination destination = new ActiveMQQueue("testQ");
    final MyObject obj = new MyObject("A message");
    final CountDownLatch consumerStarted = new CountDownLatch(1);
    Thread vmConsumerThread = new Thread("Consumer Thread") {

        @Override
        public void run() {
            try {
                ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
                factory.setOptimizedMessageDispatch(true);
                factory.setObjectMessageSerializationDefered(true);
                factory.setCopyMessageOnSend(false);
                Connection connection = factory.createConnection();
                Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                MessageConsumer consumer = session.createConsumer(destination);
                connection.start();
                consumerStarted.countDown();
                ActiveMQObjectMessage message = (ActiveMQObjectMessage) consumer.receive(30000);
                if (message != null) {
                    MyObject object = (MyObject) message.getObject();
                    LOG.info("Got message " + object.getMessage());
                    numReceived.incrementAndGet();
                }
                consumer.close();
            } catch (Throwable ex) {
                exceptions.add(ex);
            }
        }
    };
    vmConsumerThread.start();
    Thread producingThread = new Thread("Producing Thread") {

        @Override
        public void run() {
            try {
                ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
                factory.setOptimizedMessageDispatch(true);
                factory.setObjectMessageSerializationDefered(true);
                factory.setCopyMessageOnSend(false);
                Connection connection = factory.createConnection();
                Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                MessageProducer producer = session.createProducer(destination);
                ActiveMQObjectMessage message = (ActiveMQObjectMessage) session.createObjectMessage();
                message.setObject(obj);
                producer.send(message);
                producer.close();
            } catch (Throwable ex) {
                exceptions.add(ex);
            }
        }
    };
    assertTrue("consumers started", consumerStarted.await(10, TimeUnit.SECONDS));
    producingThread.start();
    vmConsumerThread.join();
    producingThread.join();
    assertEquals("writeObject called", 0, obj.getWriteObjectCalled());
    assertEquals("readObject called", 0, obj.getReadObjectCalled());
    assertEquals("readObjectNoData called", 0, obj.getReadObjectNoDataCalled());
    assertEquals("Got expected messages", 1, numReceived.get());
    assertTrue("no unexpected exceptions: " + exceptions, exceptions.isEmpty());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) ActiveMQObjectMessage(org.apache.activemq.command.ActiveMQObjectMessage) Connection(javax.jms.Connection) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Session(javax.jms.Session)

Aggregations

ActiveMQObjectMessage (org.apache.activemq.command.ActiveMQObjectMessage)11 Connection (javax.jms.Connection)3 MessageConsumer (javax.jms.MessageConsumer)3 MessageProducer (javax.jms.MessageProducer)3 Session (javax.jms.Session)3 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)3 ActiveMQBytesMessage (org.apache.activemq.command.ActiveMQBytesMessage)3 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)3 ActiveMQMapMessage (org.apache.activemq.command.ActiveMQMapMessage)3 ActiveMQStreamMessage (org.apache.activemq.command.ActiveMQStreamMessage)3 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)2 EmailEvent (com.creditease.mspl.event.vo.EmailEvent)1 Vector (java.util.Vector)1 BytesMessage (javax.jms.BytesMessage)1 JMSException (javax.jms.JMSException)1 MapMessage (javax.jms.MapMessage)1 Message (javax.jms.Message)1 Queue (javax.jms.Queue)1