Ryan Stewart wrote:
>
> I'm trying to use an embedded ActiveMQ instance for some lightweight
> message handling...
>
Here is a simple test case that exhibits the problem. Unfortunately you'll
need some sort of profiler to see the actual problem. When I run this test,
I get 2001 ActiveMQTextMessages. If I use a normal consumer instead of a
durable subscriber (call session.createConsumer instead of
session.createDurableSubscriber), I only get 1001 messages.
Test code follows:
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class MessageByReferenceTest {
private ActiveMQConnection producerConnection;
private List<ActiveMQConnection> consumerConnections = new
ArrayList<ActiveMQConnection>();
private MessageProducer producer;
private TextMessage message;
@Before
public void setUp() throws JMSException {
ActiveMQConnectionFactory factory = new
ActiveMQConnectionFactory("vm://default");
producerConnection = (ActiveMQConnection)
factory.createConnection();
producerConnection.setCopyMessageOnSend(false);
Session producerSession = producerConnection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
Destination producerDestination =
producerSession.createTopic("test.topic");
producer = producerSession.createProducer(producerDestination);
message = producerSession.createTextMessage("some text");
for (int i = 0; i < 10; i++) {
ActiveMQConnection consumerConnection = (ActiveMQConnection)
factory.createConnection();
consumerConnections.add(consumerConnection);
consumerConnection.setCopyMessageOnSend(true);
consumerConnection.setClientID(Integer.toString(i));
Session consumerSession =
consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic consumerDestination =
consumerSession.createTopic("test.topic");
MessageConsumer consumer =
consumerSession.createDurableSubscriber(consumerDestination, "foo");
consumerConnection.start();
}
}
@After
public void tearDown() throws JMSException {
producerConnection.stop();
for (Connection connection : consumerConnections) {
connection.stop();
}
}
@Test
public void testPassingByReference() throws JMSException, IOException {
for (int i = 0; i < 100; i++) {
producer.send(message);
}
System.out.println("Check the number of ActiveMQTextMessage objects
in memory now; enter to exit");
System.in.read();
}
}
--
View this message in context:
http://www.nabble.com/VM-transport-not-using-pass-by-reference-tp17442075s2354p17444209.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.