public void testReturnUnroutableMandatoryMessage_TOPIC() throws Exception
{
_bouncedMessageList.clear();
Connection con = getConnection();
AMQSession consumerSession = (AMQSession) con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
AMQTopic valid_topic = new AMQTopic(ExchangeDefaults.TOPIC_EXCHANGE_CLASS, "test.Return.Unroutable.Mandatory.Message.TOPIC");
AMQTopic invalid_topic = new AMQTopic(ExchangeDefaults.TOPIC_EXCHANGE_CLASS, "test.Return.Unroutable.Mandatory.Message.TOPIC.invalid");
MessageConsumer consumer = consumerSession.createConsumer(valid_topic);
//force synch to ensure the consumer has resulted in a bound queue
//((AMQSession) consumerSession).declareExchangeSynch(ExchangeDefaults.HEADERS_EXCHANGE_NAME, ExchangeDefaults.HEADERS_EXCHANGE_CLASS);
// This is the default now
Connection con2 = getConnection();
con2.setExceptionListener(this);
AMQSession producerSession = (AMQSession) con2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
// Need to start the "producer" connection in order to receive bounced messages
_logger.info("Starting producer connection");
con2.start();
MessageProducer nonMandatoryProducer = producerSession.createProducer(valid_topic, false, false);
MessageProducer mandatoryProducer = producerSession.createProducer(invalid_topic, false, true);
// First test - should be routed
_logger.info("Sending non-mandatory message");
TextMessage msg1 = producerSession.createTextMessage("msg1");
nonMandatoryProducer.send(msg1);
// Second test - should be bounced
_logger.info("Sending non-routable mandatory message");
TextMessage msg2 = producerSession.createTextMessage("msg2");
mandatoryProducer.send(msg2);
_logger.info("Starting consumer connection");
con.start();
TextMessage tm = (TextMessage) consumer.receive(1000L);