Search in sources :

Example 1 with UDPTraceBrokerPlugin

use of org.apache.activemq.broker.util.UDPTraceBrokerPlugin in project activemq-artemis by apache.

the class TimeStampTest method test.

public void test() throws Exception {
    BrokerService broker = new BrokerService();
    broker.setPersistent(false);
    broker.setUseJmx(true);
    broker.setPlugins(new BrokerPlugin[] { new ConnectionDotFilePlugin(), new UDPTraceBrokerPlugin() });
    TransportConnector tcpConnector = broker.addConnector("tcp://localhost:0");
    broker.addConnector("stomp://localhost:0");
    broker.start();
    // Create a ConnectionFactory
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(tcpConnector.getConnectUri());
    // Create a Connection
    Connection connection = connectionFactory.createConnection();
    connection.start();
    // Create a Session
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // Create the destination Queue
    Destination destination = session.createQueue("TEST.FOO");
    // Create a MessageProducer from the Session to the Topic or Queue
    MessageProducer producer = session.createProducer(destination);
    producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    // Create a messages
    Message sentMessage = session.createMessage();
    // Tell the producer to send the message
    long beforeSend = System.currentTimeMillis();
    producer.send(sentMessage);
    long afterSend = System.currentTimeMillis();
    // assert message timestamp is in window
    assertTrue(beforeSend <= sentMessage.getJMSTimestamp() && sentMessage.getJMSTimestamp() <= afterSend);
    // Create a MessageConsumer from the Session to the Topic or Queue
    MessageConsumer consumer = session.createConsumer(destination);
    // Wait for a message
    Message receivedMessage = consumer.receive(1000);
    // assert we got the same message ID we sent
    assertEquals(sentMessage.getJMSMessageID(), receivedMessage.getJMSMessageID());
    // assert message timestamp is in window
    assertTrue("JMS Message Timestamp should be set during the send method: \n" + "        beforeSend = " + beforeSend + "\n" + "   getJMSTimestamp = " + receivedMessage.getJMSTimestamp() + "\n" + "         afterSend = " + afterSend + "\n", beforeSend <= receivedMessage.getJMSTimestamp() && receivedMessage.getJMSTimestamp() <= afterSend);
    // assert message timestamp is unchanged
    assertEquals("JMS Message Timestamp of received message should be the same as the sent message\n        ", sentMessage.getJMSTimestamp(), receivedMessage.getJMSTimestamp());
    // Clean up
    producer.close();
    consumer.close();
    session.close();
    connection.close();
}
Also used : UDPTraceBrokerPlugin(org.apache.activemq.broker.util.UDPTraceBrokerPlugin) TransportConnector(org.apache.activemq.broker.TransportConnector) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) ConnectionDotFilePlugin(org.apache.activemq.broker.view.ConnectionDotFilePlugin) BrokerService(org.apache.activemq.broker.BrokerService) Session(javax.jms.Session)

Aggregations

Connection (javax.jms.Connection)1 Destination (javax.jms.Destination)1 Message (javax.jms.Message)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageProducer (javax.jms.MessageProducer)1 Session (javax.jms.Session)1 BrokerService (org.apache.activemq.broker.BrokerService)1 TransportConnector (org.apache.activemq.broker.TransportConnector)1 UDPTraceBrokerPlugin (org.apache.activemq.broker.util.UDPTraceBrokerPlugin)1 ConnectionDotFilePlugin (org.apache.activemq.broker.view.ConnectionDotFilePlugin)1