consumerSession.addMetaData("consumer", "consumer");
consumerSession.createTemporaryQueue("TestAD", "Q1");
ClientConsumer consumer = consumerSession.createConsumer("Q1");
consumerSession.start();
final ClientProducerImpl prod = (ClientProducerImpl)session.createProducer("TestAD");
final AtomicInteger errors = new AtomicInteger(0);
final AtomicInteger msgs = new AtomicInteger(0);
final int TOTAL_MSG = 1000;
Thread t = new Thread()
{
public void run()
{
try
{
for (int i = 0 ; i < TOTAL_MSG; i++)
{
ClientMessage msg = session.createMessage(false);
msg.getBodyBuffer().writeBytes(new byte[1024]);
prod.send(msg);
msgs.incrementAndGet();
}
}
catch (Throwable e)
{
e.printStackTrace();
errors.incrementAndGet();
}
System.out.println("done");
}
};
t.start();
while (msgs.get() == 0)
{
Thread.sleep(100);
}
while (t.isAlive() && errors.get() == 0 && !prod.getProducerCredits().isBlocked())
{
Thread.sleep(100);
}
assertEquals(0, errors.get());