Ejemplo n.º 1
0
  public static Map<String, Object> parse(Message message) throws JMSException {
    if (message instanceof TextMessage) {
      TextMessage msg = (TextMessage) message;
      String text = msg.getText();
      Date date = msg.getJMSTimestamp() == 0 ? new Date() : new Date(msg.getJMSTimestamp());

      Map<String, Object> m = new HashMap<String, Object>();
      m.put("_time", date);
      m.put("_msg_id", msg.getJMSMessageID());
      m.put("line", text);

      return m;
    } else if (message instanceof MapMessage) {
      MapMessage msg = (MapMessage) message;
      Date date = msg.getJMSTimestamp() == 0 ? new Date() : new Date(msg.getJMSTimestamp());

      Map<String, Object> m = new HashMap<String, Object>();
      m.put("_time", date);
      m.put("_msg_id", msg.getJMSMessageID());

      @SuppressWarnings("unchecked")
      Enumeration<String> e = msg.getPropertyNames();
      while (e.hasMoreElements()) {
        String key = e.nextElement();
        Object val = msg.getObjectProperty(key);
        m.put(key, val);
      }

      return m;
    }

    return null;
  }
Ejemplo n.º 2
0
  public void testSendMessageWithReceipt() 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"
            + "destination:"
            + getQueuePrefix()
            + getQueueName()
            + "\n"
            + "receipt: 1234\n\n"
            + "Hello World"
            + Stomp.NULL;

    sendFrame(frame);

    String f = receiveFrame(10000);
    Assert.assertTrue(f.startsWith("RECEIPT"));
    Assert.assertTrue(f.indexOf("receipt-id:1234") >= 0);

    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());

    // Make sure that the timestamp is valid - should
    // be very close to the current time.
    long tnow = System.currentTimeMillis();
    long tmsg = message.getJMSTimestamp();
    Assert.assertTrue(Math.abs(tnow - tmsg) < 1000);
  }
Ejemplo n.º 3
0
  public void testSendMessage() 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"
            + "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 default priority 4 is used when priority header is not set
    Assert.assertEquals("getJMSPriority", 4, message.getJMSPriority());

    // Make sure that the timestamp is valid - should
    // be very close to the current time.
    long tnow = System.currentTimeMillis();
    long tmsg = message.getJMSTimestamp();
    Assert.assertTrue(Math.abs(tnow - tmsg) < 1000);
  }