예제 #1
0
  public void testSendMessageWithLongHeaders() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);

    String frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n\n" + Stomp.NULL;
    sendFrame(frame);

    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("CONNECTED"));

    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 1024; i++) {
      buffer.append("a");
    }
    String longHeader = "longHeader:" + buffer.toString() + "\n";

    frame =
        "SEND\n"
            + "correlation-id:c123\n"
            + "persistent:true\n"
            + "priority:3\n"
            + "type:t345\n"
            + "JMSXGroupID:abc\n"
            + "foo:abc\n"
            + longHeader
            + "destination:"
            + getQueuePrefix()
            + getQueueName()
            + "\n\n"
            + "Hello World"
            + Stomp.NULL;

    sendFrame(frame);

    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    Assert.assertEquals("JMSCorrelationID", "c123", message.getJMSCorrelationID());
    Assert.assertEquals("getJMSType", "t345", message.getJMSType());
    Assert.assertEquals("getJMSPriority", 3, message.getJMSPriority());
    Assert.assertEquals(DeliveryMode.PERSISTENT, message.getJMSDeliveryMode());
    Assert.assertEquals("foo", "abc", message.getStringProperty("foo"));
    Assert.assertEquals("longHeader", 1024, message.getStringProperty("longHeader").length());

    Assert.assertEquals("JMSXGroupID", "abc", message.getStringProperty("JMSXGroupID"));
  }
예제 #2
0
  @Test
  public void testDeliveryMode() throws Exception {
    JMSProducer producer = context.createProducer();

    JMSConsumer consumer = context.createConsumer(queue1);

    producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

    String strRandom = newXID().toString();

    producer.send(queue1, context.createTextMessage(strRandom));

    TextMessage msg = (TextMessage) consumer.receiveNoWait();

    assertNotNull(msg);

    assertEquals(DeliveryMode.NON_PERSISTENT, msg.getJMSDeliveryMode());
  }
예제 #3
0
  public void testSendMessageWithStandardHeaders() throws Exception {

    MessageConsumer consumer = session.createConsumer(queue);

    String frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n\n" + Stomp.NULL;
    sendFrame(frame);

    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("CONNECTED"));

    frame =
        "SEND\n"
            + "correlation-id:c123\n"
            + "persistent:true\n"
            + "priority:3\n"
            + "type:t345\n"
            + "JMSXGroupID:abc\n"
            + "foo:abc\n"
            + "bar:123\n"
            + "destination:"
            + getQueuePrefix()
            + getQueueName()
            + "\n\n"
            + "Hello World"
            + Stomp.NULL;

    sendFrame(frame);

    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    Assert.assertEquals("JMSCorrelationID", "c123", message.getJMSCorrelationID());
    Assert.assertEquals("getJMSType", "t345", message.getJMSType());
    Assert.assertEquals("getJMSPriority", 3, message.getJMSPriority());
    Assert.assertEquals(DeliveryMode.PERSISTENT, message.getJMSDeliveryMode());
    Assert.assertEquals("foo", "abc", message.getStringProperty("foo"));
    Assert.assertEquals("bar", "123", message.getStringProperty("bar"));

    Assert.assertEquals("JMSXGroupID", "abc", message.getStringProperty("JMSXGroupID"));
    // FIXME do we support it?
    // Assert.assertEquals("GroupID", "abc", amqMessage.getGroupID());
  }
예제 #4
0
  private void propertiesPreserved(boolean persistent, boolean messageIDInHeader) throws Exception {
    BridgeImpl bridge = null;

    Connection connSource = null;

    Connection connTarget = null;

    try {
      final int NUM_MESSAGES = 10;

      bridge =
          new BridgeImpl(
              cff0,
              cff1,
              sourceQueueFactory,
              targetQueueFactory,
              null,
              null,
              null,
              null,
              null,
              5000,
              10,
              QualityOfServiceMode.AT_MOST_ONCE,
              1,
              -1,
              null,
              null,
              messageIDInHeader);

      bridge.start();

      connSource = cf0.createConnection();

      connTarget = cf1.createConnection();

      log.trace("Sending " + NUM_MESSAGES + " messages");

      Session sessSource = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Session sessTarget = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);

      MessageConsumer cons = sessTarget.createConsumer(targetQueue);

      connTarget.start();

      MessageProducer prod = sessSource.createProducer(sourceQueue);

      prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);

      TextMessage tm = sessSource.createTextMessage("blahmessage");

      prod.setPriority(7);

      prod.setTimeToLive(1 * 60 * 60 * 1000);

      prod.send(tm);

      long expiration = tm.getJMSExpiration();

      assertEquals(
          persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT,
          tm.getJMSDeliveryMode());

      tm = (TextMessage) cons.receive(1000);

      assertNotNull(tm);

      assertEquals("blahmessage", tm.getText());

      assertEquals(
          persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT,
          tm.getJMSDeliveryMode());

      assertEquals(7, tm.getJMSPriority());

      assertTrue(Math.abs(expiration - tm.getJMSExpiration()) < 100);

      Message m = cons.receive(5000);

      assertNull(m);

      // Now do one with expiration = 0

      tm = sessSource.createTextMessage("blahmessage2");

      prod.setPriority(7);

      prod.setTimeToLive(0);

      prod.send(tm);

      assertEquals(
          persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT,
          tm.getJMSDeliveryMode());

      tm = (TextMessage) cons.receive(1000);

      assertNotNull(tm);

      assertEquals("blahmessage2", tm.getText());

      assertEquals(
          persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT,
          tm.getJMSDeliveryMode());

      assertEquals(7, tm.getJMSPriority());

      assertEquals(0, tm.getJMSExpiration());

      m = cons.receive(5000);

      assertNull(m);

      tm = sessSource.createTextMessage("blahmessage3");

      final boolean myBool = false;
      final byte myByte = (byte) 23;
      final double myDouble = 17625765d;
      final float myFloat = 87127.23f;
      final int myInt = 123;
      final long myLong = 81728712;
      final short myShort = (short) 88;
      final String myString = "ojweodewj";
      final String myJMSX = "aardvark";

      tm.setBooleanProperty("mybool", myBool);
      tm.setByteProperty("mybyte", myByte);
      tm.setDoubleProperty("mydouble", myDouble);
      tm.setFloatProperty("myfloat", myFloat);
      tm.setIntProperty("myint", myInt);
      tm.setLongProperty("mylong", myLong);
      tm.setShortProperty("myshort", myShort);
      tm.setStringProperty("mystring", myString);

      tm.setStringProperty("JMSXMyNaughtyJMSXProperty", myJMSX);

      prod.send(tm);

      tm = (TextMessage) cons.receive(1000);

      assertNotNull(tm);

      assertEquals("blahmessage3", tm.getText());

      assertEquals(myBool, tm.getBooleanProperty("mybool"));
      assertEquals(myByte, tm.getByteProperty("mybyte"));
      assertEquals(myDouble, tm.getDoubleProperty("mydouble"));
      assertEquals(myFloat, tm.getFloatProperty("myfloat"));
      assertEquals(myInt, tm.getIntProperty("myint"));
      assertEquals(myLong, tm.getLongProperty("mylong"));
      assertEquals(myShort, tm.getShortProperty("myshort"));
      assertEquals(myString, tm.getStringProperty("mystring"));
      assertEquals(myJMSX, tm.getStringProperty("JMSXMyNaughtyJMSXProperty"));

      m = cons.receive(5000);

    } finally {
      if (bridge != null) {
        bridge.stop();
      }

      if (connSource != null) {
        connSource.close();
      }

      if (connTarget != null) {
        connTarget.close();
      }
    }
  }