Connection connection = factory.createConnection();
Session session = (ActiveMQSession)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") {
public void run() {
try {
ActiveMQConnectionFactory factory =
new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri());
factory.setOptimizedMessageDispatch(true);
Connection connection = factory.createConnection();
Session session = (ActiveMQSession)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") {
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 = (ActiveMQSession)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") {
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 = (ActiveMQSession)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);
}