{
private static final Logger _logger = LoggerFactory.getLogger(StreamMessageTest.class);
public void testStreamMessageEOF() throws Exception
{
AMQConnection con = (AMQConnection) getConnection("guest", "guest");
AMQSession consumerSession = (AMQSession) con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
AMQHeadersExchange queue =
new AMQHeadersExchange(new AMQBindingURL(
ExchangeDefaults.HEADERS_EXCHANGE_CLASS + "://" + ExchangeDefaults.HEADERS_EXCHANGE_NAME
+ "/test/queue1?" + BindingURL.OPTION_ROUTING_KEY + "='F0000=1'"));
FieldTable ft = new FieldTable();
ft.setString("x-match", "any");
ft.setString("F1000", "1");
consumerSession.declareAndBind(queue, ft);
MessageConsumer consumer = consumerSession.createConsumer(queue);
// 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 = (AMQConnection) getConnection("guest", "guest");
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 mandatoryProducer = producerSession.createProducer(queue);
// Third test - should be routed
_logger.info("Sending isBound message");
StreamMessage msg = producerSession.createStreamMessage();
msg.setStringProperty("F1000", "1");
msg.writeByte((byte) 42);
mandatoryProducer.send(msg);
_logger.info("Starting consumer connection");
con.start();
StreamMessage msg2 = (StreamMessage) consumer.receive(2000);
assertNotNull(msg2);
msg2.readByte();
try
{
msg2.readByte();
fail("Expected exception not thrown");
}
catch (Exception e)
{
assertTrue("Expected MessageEOFException: " + e, e instanceof MessageEOFException);
}
con.close();
con2.close();
}