messageIDInHeader(false);
}
private void messageIDInHeader(final boolean on) throws Exception
{
JMSBridgeImpl bridge = null;
Connection connSource = null;
Connection connTarget = null;
try
{
final int NUM_MESSAGES = 10;
bridge = new JMSBridgeImpl(cff0,
cff1,
sourceQueueFactory,
targetQueueFactory,
null,
null,
null,
null,
null,
5000,
10,
QualityOfServiceMode.AT_MOST_ONCE,
1,
-1,
null,
null,
on);
bridge.setTransactionManager(newTransactionManager());
bridge.start();
connSource = cf0.createConnection();
connTarget = cf1.createConnection();
JMSBridgeTest.log.trace("Sending " + NUM_MESSAGES + " messages");
List ids1 = new ArrayList();
Session sessSource = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sessSource.createProducer(sourceQueue);
for (int i = 0; i < NUM_MESSAGES; i++)
{
TextMessage tm = sessSource.createTextMessage("message" + i);
// We add some properties to make sure they get passed through ok
tm.setStringProperty("wib", "uhuh");
tm.setBooleanProperty("cheese", true);
tm.setIntProperty("Sausages", 23);
tm.setByteProperty("bacon", (byte)12);
tm.setDoubleProperty("toast", 17261762.12121d);
tm.setFloatProperty("orange", 1212.1212f);
tm.setLongProperty("blurg", 817217827l);
tm.setShortProperty("stst", (short)26363);
//Set some JMS headers too
//And also set a core props
((HornetQMessage)tm).getCoreMessage().putBytesProperty("bytes", new byte[] { 1, 2, 3});
// We add some JMSX ones too
tm.setStringProperty("JMSXGroupID", "mygroup543");
prod.send(tm);
ids1.add(tm.getJMSMessageID());
}
JMSBridgeTest.log.trace("Sent the first messages");
Session sessTarget = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sessTarget.createConsumer(targetQueue);
connTarget.start();
List msgs = new ArrayList();
for (int i = 0; i < NUM_MESSAGES; i++)
{
TextMessage tm = (TextMessage)cons.receive(5000);
Assert.assertNotNull(tm);
Assert.assertEquals("message" + i, tm.getText());
Assert.assertEquals("uhuh", tm.getStringProperty("wib"));
Assert.assertTrue(tm.getBooleanProperty("cheese"));
Assert.assertEquals(23, tm.getIntProperty("Sausages"));
assertEquals((byte)12, tm.getByteProperty("bacon"));
assertEquals(17261762.12121d, tm.getDoubleProperty("toast"));
assertEquals(1212.1212f, tm.getFloatProperty("orange"));
assertEquals(817217827l, tm.getLongProperty("blurg"));
assertEquals((short)26363, tm.getShortProperty("stst"));
assertEqualsByteArrays(new byte[] { 1,2, 3}, ((HornetQMessage)tm).getCoreMessage().getBytesProperty("bytes"));
Assert.assertEquals("mygroup543", tm.getStringProperty("JMSXGroupID"));
if (on)
{
String header = tm.getStringProperty(HornetQJMSConstants.JBOSS_MESSAGING_BRIDGE_MESSAGE_ID_LIST);
Assert.assertNotNull(header);
Assert.assertEquals(ids1.get(i), header);
msgs.add(tm);
}
}
if (on)
{
// Now we send them again back to the source
Iterator iter = msgs.iterator();
List ids2 = new ArrayList();
while (iter.hasNext())
{
Message msg = (Message)iter.next();
prod.send(msg);
ids2.add(msg.getJMSMessageID());
}
// And consume them again
for (int i = 0; i < NUM_MESSAGES; i++)
{
TextMessage tm = (TextMessage)cons.receive(5000);
Assert.assertNotNull(tm);
Assert.assertEquals("message" + i, tm.getText());
Assert.assertEquals("uhuh", tm.getStringProperty("wib"));
Assert.assertTrue(tm.getBooleanProperty("cheese"));
Assert.assertEquals(23, tm.getIntProperty("Sausages"));
assertEquals((byte)12, tm.getByteProperty("bacon"));
assertEquals(17261762.12121d, tm.getDoubleProperty("toast"));
assertEquals(1212.1212f, tm.getFloatProperty("orange"));
assertEquals(817217827l, tm.getLongProperty("blurg"));
assertEquals((short)26363, tm.getShortProperty("stst"));
assertEqualsByteArrays(new byte[] { 1,2, 3}, ((HornetQMessage)tm).getCoreMessage().getBytesProperty("bytes"));
Assert.assertEquals("mygroup543", tm.getStringProperty("JMSXGroupID"));
String header = tm.getStringProperty(HornetQJMSConstants.JBOSS_MESSAGING_BRIDGE_MESSAGE_ID_LIST);
Assert.assertNotNull(header);
Assert.assertEquals(ids1.get(i) + "," + ids2.get(i), header);
}
}
}
finally
{
if (bridge != null)
{
bridge.stop();
}
if (connSource != null)
{
connSource.close();