Skip to content

Instantly share code, notes, and snippets.

@swapnonil
Last active December 14, 2015 03:59
Show Gist options
  • Save swapnonil/5025295 to your computer and use it in GitHub Desktop.
Save swapnonil/5025295 to your computer and use it in GitHub Desktop.
Rabbit MQ Test with Publisher Acknowledgements.
package rabbitmqclient;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.core.*;
import org.springframework.amqp.rabbit.support.*;
import org.springframework.context.support.*;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest(String testName)
{
super(testName);
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite(AppTest.class);
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationConfig.xml");
RabbitTemplate template = (RabbitTemplate) applicationContext.getBean("amqpTemplate");
template.setConfirmCallback(new RabbitTemplate.ConfirmCallback()
{
public void confirm(CorrelationData correlationData, boolean ack)
{
System.out.println("ack = " + ack);
System.out.println("correlationData = " + correlationData);
}
});
for (int i = 0; i < 1000; i++)
{
template.convertAndSend("ha.queue-1", (Object) ("Message "+i),new CorrelationData("Id ="+i));
try
{
Thread.sleep(100);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
while(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment