SimpleString ADDRESS = new SimpleString("some-queue");
session1.createQueue(ADDRESS, ADDRESS, true);
ClientConsumerInternal cons1 = (ClientConsumerInternal)session1.createConsumer(ADDRESS);
// Note we make sure we send the messages *before* cons2 is created
ClientProducer prod = session1.createProducer(ADDRESS);
for (int i = 0; i < numberOfMessages; i++)
{
ClientMessage msg = createTextMessage(session1, "Msg" + i);
if (largeMessages)
{
msg.getBodyBuffer().writeBytes(new byte[600]);
}
prod.send(msg);
}
ClientConsumerInternal cons2 = (ClientConsumerInternal)session2.createConsumer(ADDRESS);
for (int i = 0; i < numberOfMessages / 2; i++)
{
ClientMessage msg = cons1.receive(1000);
Assert.assertNotNull("expected message at i = " + i, msg);
String str = getTextMessage(msg);
Assert.assertEquals("Msg" + i, str);
msg.acknowledge();
Assert.assertEquals("A slow consumer shouldn't buffer anything on the client side!",
0,
cons1.getBufferSize());
}
for (int i = numberOfMessages / 2; i < numberOfMessages; i++)
{
ClientMessage msg = cons2.receive(1000);
Assert.assertNotNull("expected message at i = " + i, msg);
Assert.assertEquals("Msg" + i, msg.getBodyBuffer().readString());
msg.acknowledge();
Assert.assertEquals("A slow consumer shouldn't buffer anything on the client side!",
0,
cons2.getBufferSize());
}
session1.close(); // just to make sure everything is flushed and no pending packets on the sending buffer, or
// the getMessageCount would fail
session2.close();
session1 = sf.createSession(false, true, true);
session1.start();
session2 = sf.createSession(false, true, true);
session2.start();
prod = session1.createProducer(ADDRESS);
Assert.assertEquals(0, getMessageCount(server, ADDRESS.toString()));
// This should also work the other way around
cons1.close();
cons2.close();
cons1 = (ClientConsumerInternal)session1.createConsumer(ADDRESS);
// Note we make sure we send the messages *before* cons2 is created
for (int i = 0; i < numberOfMessages; i++)
{
ClientMessage msg = createTextMessage(session1, "Msg" + i);
if (largeMessages)
{
msg.getBodyBuffer().writeBytes(new byte[600]);
}
prod.send(msg);
}
cons2 = (ClientConsumerInternal)session2.createConsumer(ADDRESS);
// Now we receive on cons2 first
for (int i = 0; i < numberOfMessages / 2; i++)
{
ClientMessage msg = cons2.receive(1000);
Assert.assertNotNull("expected message at i = " + i, msg);
Assert.assertEquals("Msg" + i, msg.getBodyBuffer().readString());
msg.acknowledge();
Assert.assertEquals("A slow consumer shouldn't buffer anything on the client side!",
0,
cons2.getBufferSize());
}
for (int i = numberOfMessages / 2; i < numberOfMessages; i++)
{