Java Code Examples for javax.jms.TextMessage#getJMSTimestamp()

The following examples show how to use javax.jms.TextMessage#getJMSTimestamp() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StompTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendMessage() throws Exception {

   MessageConsumer consumer = session.createConsumer(queue);

   conn.connect(defUser, defPass);

   send(conn, getQueuePrefix() + getQueueName(), null, "Hello World");

   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);
}
 
Example 2
Source File: StompTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void sendMessageToNonExistentQueue(String queuePrefix, String queue, RoutingType routingType) throws Exception {
   conn.connect(defUser, defPass);
   send(conn, queuePrefix + queue, null, "Hello World", true, routingType);

   MessageConsumer consumer = session.createConsumer(ActiveMQJMSClient.createQueue(queue));
   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) < 1500);

   // closing the consumer here should trigger auto-deletion
   assertNotNull(server.getPostOffice().getBinding(new SimpleString(queue)));
   consumer.close();
   Wait.assertTrue(() -> server.getPostOffice().getBinding(new SimpleString(queue)) == null);
}
 
Example 3
Source File: StompTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendMessageWithReceipt() throws Exception {
   MessageConsumer consumer = session.createConsumer(queue);

   conn.connect(defUser, defPass);

   send(conn, getQueuePrefix() + getQueueName(), null, "Hello World", true);

   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);
}
 
Example 4
Source File: StompV11Test.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendMessage() throws Exception {
   MessageConsumer consumer = session.createConsumer(queue);

   conn.connect(defUser, defPass);

   send(conn, getQueuePrefix() + getQueueName(), null, "Hello World");

   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);
}
 
Example 5
Source File: StompV11Test.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendMessageWithReceipt() throws Exception {
   MessageConsumer consumer = session.createConsumer(queue);

   conn.connect(defUser, defPass);


   send(conn, getQueuePrefix() + getQueueName(), null, "Hello World", true);

   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);

   conn.disconnect();
}
 
Example 6
Source File: StompV12Test.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendMessage() throws Exception {
   MessageConsumer consumer = session.createConsumer(queue);

   conn.connect(defUser, defPass);

   send(conn, getQueuePrefix() + getQueueName(), null, "Hello World");

   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);
}
 
Example 7
Source File: StompV12Test.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendMessageWithLeadingNewLine() throws Exception {
   MessageConsumer consumer = session.createConsumer(queue);

   conn.connect(defUser, defPass);

   ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND)
                                .addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName())
                                .setBody("Hello World");

   conn.sendWickedFrame(frame);

   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);

   Assert.assertNull(consumer.receiveNoWait());

   conn.disconnect();
}
 
Example 8
Source File: StompV12Test.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendMessageWithReceipt() throws Exception {
   MessageConsumer consumer = session.createConsumer(queue);

   conn.connect(defUser, defPass);

   send(conn, getQueuePrefix() + getQueueName(), null, "Hello World", true);

   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);

   conn.disconnect();
}
 
Example 9
Source File: StompTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void sendMessageToNonExistentTopic(String topicPrefix, String topic, RoutingType routingType) throws Exception {
   conn.connect(defUser, defPass);

   // first send a message to ensure that sending to a non-existent topic won't throw an error
   send(conn, topicPrefix + topic, null, "Hello World", true, routingType);

   // create a subscription on the topic and send/receive another message
   MessageConsumer consumer = session.createConsumer(ActiveMQJMSClient.createTopic(topic));
   send(conn, topicPrefix + topic, null, "Hello World", true, routingType);
   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) < 1500);

   assertNotNull(server.getAddressInfo(new SimpleString(topic)));

   // closing the consumer here should trigger auto-deletion of the subscription queue and address
   consumer.close();
   Thread.sleep(200);
   assertNull(server.getAddressInfo(new SimpleString(topic)));
}
 
Example 10
Source File: StompV11Test.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendMessageWithLeadingNewLine() throws Exception {
   MessageConsumer consumer = session.createConsumer(queue);
   Thread.sleep(1000);

   conn.connect(defUser, defPass);

   ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND)
                                .addHeader(Stomp.Headers.Send.DESTINATION, getQueuePrefix() + getQueueName())
                                .setBody("Hello World");

   conn.sendWickedFrame(frame);

   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);

   assertNull(consumer.receive(1000));

   conn.disconnect();
}
 
Example 11
Source File: StompWithSecurityTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testJMSXUserID() throws Exception {
   server.getConfiguration().setPopulateValidatedUser(true);

   MessageConsumer consumer = session.createConsumer(queue);

   StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
   conn.connect(defUser, defPass);

   ClientStompFrame frame = conn.createFrame("SEND");
   frame.addHeader("destination", getQueuePrefix() + getQueueName());
   frame.setBody("Hello World");
   conn.sendFrame(frame);

   conn.disconnect();

   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());
   Assert.assertEquals("JMSXUserID", "brianm", message.getStringProperty("JMSXUserID"));

   // 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);
}
 
Example 12
Source File: SelectorTest.java    From activemq-artemis with Apache License 2.0 3 votes vote down vote up
@Test
public void testJMSTimestampOnSelector() throws Exception {
   Connection conn = null;

   try {
      conn = getConnectionFactory().createConnection();
      conn.start();

      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      MessageProducer prod = session.createProducer(queue1);

      TextMessage msg1 = session.createTextMessage("msg1");
      prod.send(msg1);

      Thread.sleep(2);

      TextMessage msg2 = session.createTextMessage("msg2");
      prod.send(msg2);

      String selector = "JMSTimestamp = " + msg2.getJMSTimestamp();

      MessageConsumer cons = session.createConsumer(queue1, selector);

      conn.start();

      TextMessage rec = (TextMessage) cons.receive(10000);

      assertNotNull(rec);

      Assert.assertEquals("msg2", rec.getText());

      assertNull(cons.receiveNoWait());

   } finally {
      if (conn != null) {
         conn.close();
      }
   }
}