activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mparida <manojpari...@gmail.com>
Subject Re: 24 hours listener
Date Fri, 18 Dec 2009 07:41:45 GMT

I just do like this:

[code]package com.mindtree.ch07;

import javax.jms.ExceptionListener;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;

public class JMSReceiverTransacted implements MessageListener,
ExceptionListener {

	QueueSession session = null;

	public JMSReceiverTransacted() {

        try {
        	Context ctx = new InitialContext();
			QueueConnectionFactory factory = (QueueConnectionFactory)
			   ctx.lookup("QueueCF");
			QueueConnection connection = 
				factory.createQueueConnection();
			connection.start();
			connection.setExceptionListener(this);
			
			Queue queue = (Queue)ctx.lookup("queue1");
			
			session = 
				connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        	QueueReceiver receiver = session.createReceiver(queue);
			receiver.setMessageListener(this);			
        	
	    	//System.out.println("Waiting for messages...");
        } catch (Exception up) {
            up.printStackTrace();
        }
	}

	public void onMessage(Message message) {

        try {
        	TextMessage msg = (TextMessage)message;
        	System.out.println("Message: " + msg.getText());
        	//System.out.println("Waiting for messages...");
	    } catch (Exception up) {
	    	up.printStackTrace();
	    }
	}

	public static void main(String[] args) {
	
			try {
				new JMSReceiverTransacted();
			} catch (Exception up) {
				up.printStackTrace();
			}
		while(true){
			
		}
		
	}
	
    public void onException ( javax.jms.JMSException jmse)
	{
	}	
}
[/code]

rajdavies wrote:
> 
> Post the code you used please
> On 17 Dec 2009, at 15:12, Mparida wrote:
> 
>>
>> Hi,
>>
>> I want to configure a 24 hrs listener which shall listen to a queue  
>> through
>> out the day and listen if there are a ny messages in queue or not.
>>
>> I tried it through an infinite loop but as you know it creates high  
>> CPU.
>>
>> I do not want to use schedulers for this.
>>
>> If any one has done similar kind of thing (May be using thread or like
>> that), please suggest.
>>
>> Thank you,
>> Manoj
>>
>>
>> -- 
>> View this message in context:
>> http://old.nabble.com/24-hours-listener-tp26829469p26829469.html
>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>
> 
> Rob Davies
> http://twitter.com/rajdavies
> I work here: http://fusesource.com
> My Blog: http://rajdavies.blogspot.com/
> I'm writing this: http://www.manning.com/snyder/
> 
> 
> 
> 
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/24-hours-listener-tp26829469p26840148.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message