Search in sources :

Example 6 with ActiveMQObjectMessage

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

the class ActiveMQObjectMessageTest method createObject.

@Override
public Object createObject() throws Exception {
    ActiveMQObjectMessage info = new ActiveMQObjectMessage();
    populateObject(info);
    return info;
}
Also used : ActiveMQObjectMessage(org.apache.activemq.command.ActiveMQObjectMessage)

Example 7 with ActiveMQObjectMessage

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

the class ActiveMQObjectMessageTest method createObject.

@Override
public Object createObject() throws Exception {
    ActiveMQObjectMessage info = new ActiveMQObjectMessage();
    populateObject(info);
    return info;
}
Also used : ActiveMQObjectMessage(org.apache.activemq.command.ActiveMQObjectMessage)

Example 8 with ActiveMQObjectMessage

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

the class ActiveMQObjectMessageTest method populateObject.

@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ActiveMQObjectMessage info = (ActiveMQObjectMessage) object;
}
Also used : ActiveMQObjectMessage(org.apache.activemq.command.ActiveMQObjectMessage)

Example 9 with ActiveMQObjectMessage

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

the class ActiveMQObjectMessageTest method populateObject.

@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ActiveMQObjectMessage info = (ActiveMQObjectMessage) object;
}
Also used : ActiveMQObjectMessage(org.apache.activemq.command.ActiveMQObjectMessage)

Example 10 with ActiveMQObjectMessage

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

the class ObjectMessageNotSerializableTest method testSendNotSerializeableObjectMessageOverTcp.

public void testSendNotSerializeableObjectMessageOverTcp() throws Exception {
    final ActiveMQDestination destination = new ActiveMQTopic("testTopic");
    final MyObject obj = new MyObject("A message");
    final CountDownLatch consumerStarted = new CountDownLatch(3);
    final Vector<Throwable> exceptions = new Vector<>();
    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 tcpConsumerThread = new Thread("Consumer Thread") {

        @Override
        public void run() {
            try {
                ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri());
                factory.setOptimizedMessageDispatch(true);
                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();
                    assertEquals("readObject called", 1, object.getReadObjectCalled());
                }
                consumer.close();
            } catch (Throwable ex) {
                exceptions.add(ex);
            }
        }
    };
    tcpConsumerThread.start();
    Thread notherVmConsumerThread = 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);
            }
        }
    };
    notherVmConsumerThread.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();
    tcpConsumerThread.join();
    notherVmConsumerThread.join();
    producingThread.join();
    assertEquals("writeObject called", 1, obj.getWriteObjectCalled());
    assertEquals("readObject called", 0, obj.getReadObjectCalled());
    assertEquals("readObjectNoData called", 0, obj.getReadObjectNoDataCalled());
    assertEquals("Got expected messages", 3, numReceived.get());
    assertTrue("no unexpected exceptions: " + exceptions, exceptions.isEmpty());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ActiveMQObjectMessage(org.apache.activemq.command.ActiveMQObjectMessage) Connection(javax.jms.Connection) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) MessageProducer(javax.jms.MessageProducer) Vector(java.util.Vector) 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