activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From avin98 <avi...@yahoo.com>
Subject RE: ActiveMQ memory utilization
Date Fri, 16 Feb 2007 01:38:49 GMT

import java.io.IOException;
import java.util.Date;

import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class TestServlet extends HttpServlet{
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {
		doPost(request, response);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse
response)
    throws IOException, ServletException {
		
		String ttl = request.getParameter("TTL");
        String oper = request.getParameter("OPER");
        
//      Get the JMS Service Locator
        QueueLocator locator = QueueLocator.getInstance();

        QueueSender sender = null;
        QueueSession publishSession = null;
        QueueConnection connection = null;
        
        String str = "MESSAGE BODY";

        try {

            // create jms session
            boolean transacted = false;
            connection = (QueueConnection)
QueueLocator.getInstance().getConnectionFactory().createConnection();
            
            publishSession =
connection.createQueueSession(transacted,Session.AUTO_ACKNOWLEDGE);
            
            
            
            // Get the JMS Queue
            Queue queue;

            queue = locator.getMessageQueue();

            System.out.println("Queue is:" + queue);
            
            // Get a Queue Sender
            sender = publishSession.createSender(queue);
            // The Messages are set to be temporary
            sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

            TextMessage message = publishSession.createTextMessage();
            message.setText(str);
            //message.setJMSCorrelationID(corelationId);

            sender.setTimeToLive(300000);

            System.out.println("Message properties:"+
message.getJMSExpiration());
            System.out.println(new Date(sender.getTimeToLive()));
            
            sender.send(message);

            // log the stuff
            System.out.println("Message sent off successfully");

        } catch (JMSException e) {
            e.printStackTrace();
        } finally {
        	try{
        		sender.close();
        		publishSession.close();
        		connection.close();
            } catch(Exception e){
        		e.printStackTrace();
        	}
        }

	}
}

-- 
View this message in context: http://www.nabble.com/ActiveMQ-memory-utilization-tf3237215s2354.html#a8997556
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message