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: Bug in createQueueSession ?
Date Wed, 31 May 2006 11:57:07 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);

        _qcon.start();
       
        _msg = _qsession.createObjectMessage();
        _msg.setObject(foo);
       
        _qsender.send(_msg);
       
 }
 
 
 Receiver/Consumer
  
 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);
       
         _qcon.start();

        _qsession = _qcon.createQueueSession(true,
Session.AUTO_ACKNOWLEDGE);
       
        _queue = (Queue) _ic.lookup(queueName);
     
        QueueReceiver _qreceiver = _qsession.createReceiver(_queue);
        _qreceiver.setMessageListener(listener);
       
       
 }
 
 
 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/Bug+in+createQueueSession+--t1710085.html#a4643025
Sent from the ActiveMQ - User forum at Nabble.com.


Mime
View raw message