activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From klate <Klaus.Terj...@bank-verlag.de>
Subject Re: Message is read but not removed.
Date Mon, 22 May 2006 08:00:48 GMT

Hi,

Here a Code Fragment of my Message-Service

Regards 
Klaus Terjung

Producer


public void send() throws NamingException, JMSException {

        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
        env.put(Context.PROVIDER_URL, "tcp://ws-0148:61616");
        
        InitialContext ctx = new InitialContext(env)

        QueueConnectionFactory  _qconFactory = (QueueConnectionFactory)
ctx.lookup("ConnectionFactory");
        QueueConnection         _qcon        =
_qconFactory.createQueueConnection();
        QueueSession            _qsession    =
_qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        
        
        Queue _queue = (Queue) ctx.lookup(queueName);
        
        QueueSender _qsender = _qsession.createSender(_queue);
        _msg = _qsession.createObjectMessage();
        _msg.setObject(foo);
       
        _qsender.send(_msg);
        _qcon.start();
 }
 
 
 Receiver
 
 
 public void initReceiver() throws NamingException, JMSException {

        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
        env.put(Context.PROVIDER_URL, "tcp://ws-0148:61616");
        
        InitialContext ctx = new InitialContext(env)

        QueueConnectionFactory  _qconFactory = (QueueConnectionFactory)
ctx.lookup("ConnectionFactory");
        QueueConnection         _qcon        =
_qconFactory.createQueueConnection();
        QueueSession            _qsession    =
_qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        
        
        Queue _queue = (Queue) ctx.lookup(queueName);
        
        QueueSender _qsender = _qsession.createSender(_queue);
        
        _qsession = _qcon.createQueueSession(true,
Session.AUTO_ACKNOWLEDGE);
       
        _queue = (Queue) _ic.lookup(queueName);
      
        QueueReceiver _qreceiver = _qsession.createReceiver(_queue);
        _qreceiver.setMessageListener(listener);
        
        _qcon.start();
 }
 
 
 public void onMessage(Message message) {
        if (message != null) {
            try {
                if (message instanceof ObjectMessage) {
                    
                    Foo foo = (Foo) ((ObjectMessage) message)
                            .getObject();
                            //do something

                    }
                } 
                
                
                if (session().getTransacted()) {
                    session().commit();
                }
                
                

            } catch (JMSException e) {
                throw new FaxServiceException(e);
            }  
  
        
        }
 }
--
View this message in context: http://www.nabble.com/Message+is+read+but+not+removed.-t1649736.html#a4501354
Sent from the ActiveMQ - User forum at Nabble.com.


Mime
View raw message