activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From denez <iboud...@yahoo.fr>
Subject RE: Error on starting QueueConnection
Date Wed, 22 Aug 2007 06:51:36 GMT

Finally, i build a simple sample who works.
Then i include my entire old project in it step by step.
So, the main problem i think was due to a classpath eror.
Indeed, i have try a lot a thing in my project so include a lot of libraries
in the classpath.
No the problem is solved.
Thanks you for your help and answers.

Regards,
Denez



denez wrote:
> 
> New test done ! I have put this code into my first project.
> If i try to create a Connection, a Session and a Consumer there is no
> problem at all.
> But if i create a QueueConnection, a QueueSession and a QueueReceiver i
> got the "error".
> the QueueConnection is corretly create but the QueueSession not.
> What is the difference between Connection and QueueConnection ?
> What is the difference between Consumer and QueueReceiver ?
> 
> thanks in advance,
> Regards,
> 
> Denez
> 
> 
> denez wrote:
>> 
>> Here is my new investigation :
>> I create a new project!
>> I only implement one class which implements ServletContextListener and
>> MessageListener, and wrote this so simple code : 
>> 
>> public class ActiveMQBrokerStartListener implements
>> ServletContextListener, MessageListener {
>> 	BrokerService broker = new BrokerService();
>> 	private String url="tcp://localhost:61616";
>> 	private Connection connection;
>> 	private Session session;
>> 	private Queue aQueue ;
>> 	
>> 	public void contextInitialized(ServletContextEvent arg0) {
>> 		try {
>> 			broker.addConnector(url) ;
>> 			broker.start();
>> 			
>> 			ActiveMQConnectionFactory factory = new
>> ActiveMQConnectionFactory(url);
>> 			connection = factory.createConnection();    	
>> 			session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
>> 			aQueue = session.createQueue("test") ;
>> 			MessageConsumer consumer = session.createConsumer(aQueue);
>> 			consumer.setMessageListener(this) ;
>> 			
>> 			connection.start();
>> 			
>> 			Thread.sleep(10000) ;
>> 			
>> 			consumer = null ;
>> 			connection.stop() ;
>> 			
>> 		} catch (Exception e) {
>> 			System.err.println(e.getMessage());
>>         	e.printStackTrace();
>>         	throw new RuntimeException(e);
>> 		}
>> 	}
>> 
>> 	public void contextDestroyed(ServletContextEvent arg0) {
>> 		try {
>> 			broker.stop();
>> 			System.out.println("Connetor is stopped !");
>> 		} catch (Exception e) {
>> 			System.err.println(e.getMessage());
>> 			e.printStackTrace();
>> 			throw new RuntimeException(e);
>> 		}
>> 	}
>> 
>> 	public void onMessage(Message arg0) {
>> 		// TODO Auto-generated method stub
>> 		
>> 	}
>> }
>> 
>> I have no error at all.
>> therefore, there is it somebody who could tell me what occurs with my
>> jndi file because it seems that it is the cause of the problem.
>> Indeed, i probably miss to tell you that in the first version of my code
>> i can't put :
>> 
>> ActiveMQConnectionFactory cf =
>> ActiveMQConnectionFactory)ctx.lookup("jms/ConnectionFactory");
>> Conenction conn = cf.createQueueConnection();
>> 
>> This code produce a ClassCastException.
>> Could you give a explanation or something.
>> Probably too many time spent on this problem to have a clear and precise
>> vision of it.
>> Thanks in advance,
>> Regards,
>> 
>> Denez
>> 
>> 
>> denez wrote:
>>> 
>>> I try your both sample, but it still doesn't work.
>>> I try to move my project directory because originally contains space.
>>> but still have the same error.
>>> I probaly miss something in my configuration or someting is wrong in my
>>> code.
>>> I don't understand.
>>> So, could you give me or send me a sample web application that use
>>> ActiveMQ ?
>>> Thanks in advance.
>>> Regards,
>>> 
>>> Denez
>>> 
>>> 
>>> Suchitha Koneru (sukoneru) wrote:
>>>> 
>>>> The JMS  documentation suggests that we start the connection after
>>>> creating the receiver and registering it with a message listener.
>>>> Please
>>>> look at point no: 6 in the section "Client to Consume Messages"
>>>> http://java.sun.com/developer/technicalArticles/Ecommerce/jms/index.html
>>>>  
>>>> 
>>>> -----Original Message-----
>>>> From: Dave Carlson [mailto:gshpsrule@charter.net] 
>>>> Sent: Friday, August 17, 2007 7:58 AM
>>>> To: users@activemq.apache.org
>>>> Cc: Suchitha Koneru (sukoneru)
>>>> Subject: RE: Error on starting QueueConnection
>>>> 
>>>> Are you sure about the ordering? It seems odd that you would want to
>>>> start the flow of messages across the connection before you have
>>>> created
>>>> a receiver. Looking at ActiveMQ example code in ConsumerTool, they are
>>>> creating the receiver first...
>>>> 
>>>> 			ActiveMQConnectionFactory connectionFactory =
>>>> new ActiveMQConnectionFactory(user, password, url);
>>>> 			Connection connection =
>>>> connectionFactory.createConnection();
>>>> 			if (durable && clientId != null &&
>>>> clientId.length()>0 && !"null".equals(clientId) ) {
>>>> 				connection.setClientID(clientId);
>>>> 			}
>>>> 			connection.setExceptionListener(this);
>>>> 			connection.start();
>>>> 
>>>> 			session = connection.createSession(transacted,
>>>> ackMode);
>>>> 			if (topic) {
>>>> 				destination =
>>>> session.createTopic(subject);
>>>> 			} else {
>>>> 				destination =
>>>> session.createQueue(subject);
>>>> 			}
>>>> 
>>>> 			replyProducer = session.createProducer(null);
>>>> 	
>>>> replyProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
>>>> 
>>>> 			MessageConsumer consumer = null;
>>>> 			if (durable && topic) {
>>>> 				consumer =
>>>> session.createDurableSubscriber((Topic) destination, consumerName);
>>>> 			} else {
>>>> 				consumer =
>>>> session.createConsumer(destination);
>>>> 			}
>>>> 
>>>> ---- "Suchitha Koneru (sukoneru)" <sukoneru@cisco.com> wrote: 
>>>>> Start the queue connection after creating the receiver .  Change the

>>>>> order and see. It is always recommended that the connection is started
>>>> 
>>>>> after creating the receiver . The following should be the order. Give

>>>>> it a try.
>>>>> 
>>>>>   ActiveMQQueueReceiver aqr =
>>>>>  (ActiveMQQueueReceiver)qs.createReceiver(q) ; 
>>>>>                 aqr.setMessageListener(new
>>>>>  BatchReceiverTechnicalService()) ;
>>>>>   aqc.start() ;
>>>>> 
>>>>> Also I noticed that in the jndi resource for jms/Connectionfactory  
>>>>> you are not using max.Inactivity flag for the broker url.
>>>>> But while adding connector to the broker you are using this flag, 
>>>>> please use the same broker url through out for consistency.
>>>>> 
>>>>> 
>>>>> -----Original Message-----
>>>>> From: denez [mailto:ibouddha@yahoo.fr]
>>>>> Sent: Thursday, August 16, 2007 7:03 AM
>>>>> To: users@activemq.apache.org
>>>>> Subject: Re: Error on starting QueueConnection
>>>>> 
>>>>> 
>>>>> Do you already have this type of error ?
>>>>> Do i forget something in my configuration.
>>>>> I use :
>>>>> apache-activemq-4.1.1.jar
>>>>> Tomcat 5.5.23
>>>>> jdk1.5.0_07
>>>>> 
>>>>> Could you tell me if something is wrong !
>>>>> Here is my context declaration in Tomcat :
>>>>> 
>>>>> <Context path="/jms" reloadable="true" docBase="C:\myJMSApp"
>>>>> workDir="C:\myJMSApp\work" >
>>>>> 	<Resource
>>>>>         	name="jms/ConnectionFactory"
>>>>>         	auth="Container"
>>>>>         	type="org.apache.activemq.ActiveMQConnectionFactory"
>>>>>         	description="JMS Connection Factory"
>>>>>         	factory="org.apache.activemq.jndi.JNDIReferenceFactory"
>>>>>         	brokerURL="tcp://localhost:61616"
>>>>>         	brokerName="LocalActiveMQBroker"
>>>>> 	        useEmbeddedBroker="true"/>
>>>>> 
>>>>>     	<Resource name="jms/batch"
>>>>>         	auth="Container"
>>>>>         	type="org.apache.activemq.command.ActiveMQQueue"
>>>>>         	factory="org.apache.activemq.jndi.JNDIReferenceFactory"
>>>>>         	physicalName="batch"/>
>>>>> </Context>
>>>>> 
>>>>> Thanks in advance for all reply, help / answer.
>>>>> Regards,
>>>>> 
>>>>> Denez
>>>>> 
>>>>> 
>>>>> denez wrote:
>>>>> > 
>>>>> > Hi all,
>>>>> > 
>>>>> > I got the same error trying to create a sender !
>>>>> > A very strange thing appear because there is no exception throw
! 
>>>>> > Just
>>>>> 
>>>>> > nothing happened and the rest of my code is never (i suspect)
>>>>> excecuted.
>>>>> > 
>>>>> > Could you help me, or ask me if something is not clear.
>>>>> > Thanks in advance,
>>>>> > Regards,
>>>>> > 
>>>>> > Denez
>>>>> > 
>>>>> > 
>>>>> > denez wrote:
>>>>> >> 
>>>>> >> I search around to find my error and find that you should use

>>>>> >> ActiveMQConnection.
>>>>> >> Now i can start the connection but have a same problem will
trying 
>>>>> >> to
>>>>> 
>>>>> >> createReceiver.
>>>>> >> See the code below (previous + modification) :
>>>>> >> 
>>>>> >> public class ActiveMQBrokerStartListener implements 
>>>>> >> ServletContextListener {
>>>>> >> 	
>>>>> >>      BrokerService broker = new BrokerService();
>>>>> >>      ActiveMQConnection aqc = null ;
>>>>> >> 	
>>>>> >>      public void contextInitialized(ServletContextEvent arg0)
{
>>>>> >>         try{
>>>>> >>               
>>>>> >>
>>>>> broker.addConnector("tcp://localhost:61616?trace=true&wireFormat.maxIn
>>>>> ac
>>>>> tivityDuration=-1");
>>>>> >>                broker.start();
>>>>> >>                InitialContext ic = new InitialContext();
>>>>> >>                Context ctx = (Context) ic.lookup("java:comp/env");
>>>>> >>                ActiveMQConnectionFactory acf =
>>>>> >>                    
>>>>> >> (ActiveMQConnectionFactory)ctx.lookup("jms/ConnectionFactory");
>>>>> >>                aqc =
>>>> (ActiveMQConnection)acf.createQueueConnection();
>>>>> >>                aqc.start() ;
>>>>> >>                ActiveMQQueueSession qs =
>>>>> >>                     
>>>>> >> (ActiveMQQueueSession)aqc.createQueueSession(false,
>>>>> >> Session.CLIENT_ACKNOWLEDGE) ;
>>>>> >>                ActiveMQQueue q =
>>>>> (ActiveMQQueue)ctx.lookup("jms/batch");
>>>>> >>                ActiveMQQueueReceiver aqr =
>>>>> >> (ActiveMQQueueReceiver)qs.createReceiver(q) ; // ERROR LINE
>>>>> >>                aqr.setMessageListener(new
>>>>> >> BatchReceiverTechnicalService()) ;
>>>>> >>         }catch(Exception e){
>>>>> >>                System.err.println(e.getMessage());
>>>>> >>                e.printStackTrace();
>>>>> >>                throw new RuntimeException(e);
>>>>> >>         }
>>>>> >>      }
>>>>> >> 
>>>>> >>      public void contextDestroyed(ServletContextEvent arg0)
{
>>>>> >>                try{
>>>>> >>                               aqc.close() ;
>>>>> >>                               //qc.close() ;
>>>>> >>                               broker.stop();
>>>>> >>                }catch(Exception e){
>>>>> >>                               System.err.println(e.getMessage());
>>>>> >>                               e.printStackTrace();
>>>>> >>                               throw new RuntimeException(e);
>>>>> >>                }
>>>>> >>      }
>>>>> >> }
>>>>> >> 
>>>>> >> What is wrong ??
>>>>> >> Why i can not create a Receiver ?
>>>>> >> 
>>>>> >> Thanks in advance
>>>>> >> Regards,
>>>>> >> Denez
>>>>> >> 
>>>>> >> 
>>>>> >> 
>>>>> >> 
>>>>> >> denez wrote:
>>>>> >>> 
>>>>> >>> Hi all,
>>>>> >>> 
>>>>> >>> I would like to start a broker and Activate a MessageListener
on 
>>>>> >>> startup of my webApp.
>>>>> >>> I made all the needed configuration to have a
>>>>> ServletContextListener.
>>>>> >>> I can debug inside my ServletContextListener implementation
named
>>>> :
>>>>> >>> ActiveMQBrokerStartListener.
>>>>> >>> You can see the code of it below :
>>>>> >>> 
>>>>> >>> public class ActiveMQBrokerStartListener implements 
>>>>> >>> ServletContextListener {
>>>>> >>>      BrokerService broker = new BrokerService();
>>>>> >>>      QueueConnection qc = null ;
>>>>> >>> 	
>>>>> >>>      public void contextInitialized(ServletContextEvent
arg0) {
>>>>> >>>         try{
>>>>> >>>        	      
>>>>> >>>
>>>>> broker.addConnector("tcp://localhost:61616?trace=true&wireFormat.maxIn
>>>>> ac
>>>>> tivityDuration=-1");
>>>>> >>>                broker.start();
>>>>> >>>                InitialContext ic = new InitialContext();
>>>>> >>>                Context ctx = (Context) ic.lookup("java:comp/env");
>>>>> >>>                ActiveMQConnectionFactory cf =
>>>>> >>>                            
>>>>> >>> ActiveMQConnectionFactory)ctx.lookup("jms/ConnectionFactory");
>>>>> >>>                qc = (QueueConnection) cf.createQueueConnection();
>>>>> >>>                qc.start() ;
>>>>> >>>                QueueSession qs = qc.createQueueSession(false,
>>>>> >>> Session.CLIENT_ACKNOWLEDGE) ;
>>>>> >>>                Queue q = (Queue)ctx.lookup("jms/batch");
>>>>> >>>                QueueReceiver qr = qs.createReceiver(q) ;
>>>>> >>>                qr.setMessageListener(new Receiver()) ;
>>>>> >>>         }catch(Exception e){
>>>>> >>>                System.err.println(e.getMessage());
>>>>> >>>                e.printStackTrace();
>>>>> >>>                throw new RuntimeException(e);
>>>>> >>>         }
>>>>> >>>      }
>>>>> >>> 
>>>>> >>>      public void contextDestroyed(ServletContextEvent arg0)
{
>>>>> >>>         try{
>>>>> >>>                qc.close() ;
>>>>> >>>                broker.stop();
>>>>> >>>         }catch(Exception e){
>>>>> >>>                System.err.println(e.getMessage());
>>>>> >>>                e.printStackTrace();
>>>>> >>>                throw new RuntimeException(e);
>>>>> >>>         }
>>>>> >>>      }
>>>>> >>> }
>>>>> >>> 
>>>>> >>> I place a breakpoint on the line that should create a
>>>> QueueSession.
>>>>> >>> But never enter in it. If i place a breakpoint on the ligne
that 
>>>>> >>> createQueueConnection i have it.
>>>>> >>> So the problem is on the qc.start() ; If i inspect the 
>>>>> >>> QueueConnection i can see that the started=false as normal.
>>>>> >>> 
>>>>> >>> What is wrong on my code ?
>>>>> >>> Could you help me, or tell me what you think about this
?
>>>>> >>> 
>>>>> >>> Regards,
>>>>> >>> Denez
>>>>> >>> 
>>>>> >> 
>>>>> >> 
>>>>> > 
>>>>> > 
>>>>> 
>>>>> --
>>>>> View this message in context:
>>>>> http://www.nabble.com/Error-on-starting-QueueConnection-tf4278515s2354
>>>>> .h
>>>>> tml#a12182022
>>>>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>>> 
>>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Error-on-starting-QueueConnection-tf4278515s2354.html#a12269051
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message