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());
}
Aggregations