activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Suchitha Koneru \(sukoneru\)" <sukon...@cisco.com>
Subject RE: ActiveMQ memory utilization
Date Fri, 16 Feb 2007 02:08:35 GMT
On the Receiver side , make sure that  you start the queue connection ,
after you  create the active MQ receiver . Some times the messages might
be lost , if we start the queue connection , before creating the
receiver.

-----Original Message-----
From: avin98 [mailto:avin98@yahoo.com] 
Sent: Thursday, February 15, 2007 5:39 PM
To: users@activemq.apache.org
Subject: RE: ActiveMQ memory utilization


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#a8
997556
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Mime
View raw message