@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(); } } }
@Override public JmsRecord mapMessage(Message message) throws Exception { TextMessage textMessage = (TextMessage) message; Map<String, Object> properties = new HashMap<>(); @SuppressWarnings("rawtypes") Enumeration propertyNames = textMessage.getPropertyNames(); while (propertyNames.hasMoreElements()) { String propertyName = (String) propertyNames.nextElement(); properties.put(propertyName, textMessage.getObjectProperty(propertyName)); } JmsRecord jmsRecord = new JmsRecord( textMessage.getJMSMessageID(), textMessage.getJMSTimestamp(), textMessage.getJMSCorrelationID(), textMessage.getJMSReplyTo(), textMessage.getJMSDestination(), textMessage.getJMSDeliveryMode(), textMessage.getJMSRedelivered(), textMessage.getJMSType(), textMessage.getJMSExpiration(), textMessage.getJMSPriority(), properties, textMessage.getText()); return jmsRecord; } })
@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); }
@Test(timeout = 30000) public void testSelectorsWithJMSTimestampOnQueue() throws Exception { final Connection connection = createConnection(); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue(getQueueName()); MessageProducer producer = session.createProducer(destination); TextMessage message1 = session.createTextMessage(); message1.setText("filtered"); producer.send(message1, DeliveryMode.PERSISTENT, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); // short delay to prevent the timestamps from being the same Thread.sleep(2); TextMessage message2 = session.createTextMessage(); message2.setText("expected"); producer.send(message2, DeliveryMode.PERSISTENT, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); MessageConsumer consumer = session.createConsumer(destination, "JMSTimestamp = " + message2.getJMSTimestamp()); connection.start(); Message msg = consumer.receive(2000); assertNotNull(msg); assertTrue(msg instanceof TextMessage); assertEquals("Unexpected JMSTimestamp value", message2.getJMSTimestamp(), msg.getJMSTimestamp()); assertEquals("Unexpected message content", "expected", ((TextMessage) msg).getText()); } finally { connection.close(); } }
@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(); }
@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(); }
@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); }
@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); }
@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); }
@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(); }
@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.receive(1000)); conn.disconnect(); }
@Test public void testSendMessageWithLeadingNewLine() throws Exception { conn.connect(defUser, defPass); ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND) .addHeader(Stomp.Headers.Send.DESTINATION, getQueuePrefix() + getQueueName()) .setBody("Hello World"); conn.sendWickedFrame(frame); MessageConsumer consumer = session.createConsumer(queue); TextMessage message = (TextMessage) consumer.receive(1000); Assert.assertNotNull(message); Assert.assertEquals("Hello World", message.getText()); send(conn, getQueuePrefix() + getQueueName(), null, "Hello World"); 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); }
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))); }
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(); assertNull(server.getPostOffice().getBinding(new SimpleString(queue))); }
@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); } }