| Author |
Need help with JMS+ Spring + ActiveMQ
|
luo luo
Ranch Hand
Joined: Dec 09, 2003
Posts: 36
|
|
Hi... I'm learning to using JMS + Spring + ActiveMQ for a simple application. The following is my configs and MD Pojo. My question is that when I tried to send <300 messages, it gave me java out of memory error and it seems so slow. Please tell me what's wrong with it... it's kind of urgent, much apprecicated!!! Server-side config: <beans> <bean id="activeMQContainer" class="org.activemq.jca.JCAContainer"> <property name="workManager"> <bean id="workManager" class="org.activemq.work.SpringWorkManager"/> </property> <property name="resourceAdapter"> <bean id="activeMQResourceAdapter" class="org.activemq.ra.ActiveMQResourceAdapter"> <property name="serverUrl" value="tcp://localhost:61616"/> </bean> </property> </bean> <bean id="HelloMDP" factory-method="addConnector" factory-bean="activeMQContainer"> <property name="activationSpec"> <bean class="org.activemq.ra.ActiveMQActivationSpec"> <property name="destination" value="Hello.Queue"/> <property name="destinationType" value="javax.jms.Queue"/> </bean> </property> <property name="ref" value="helloBean" /> </bean> <bean id="helloBean" class="com.icrossing.mdpojo.lingo.impl.HelloBean"> </bean> </beans> client-side <beans> <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> <property name="defaultDestinationName" value="Hello.Queue" /> <property name="connectionFactory" ref="connectionFactory" /> </bean> <bean id="connectionFactory" class="org.activemq.ActiveMQConnectionFactory" init-method="start"> <property name="brokerURL" value="tcp://localhost:61616" /> </bean> </beans> My java code: code snippet for producing Messages: for (int i = 0; i < messageCount ; i++) { final String text = "Text for message: " + i; template.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { TextMessage message = session.createTextMessage(text); message.setStringProperty("next", "foo"); return message; } }); } // Consumer public class HelloBean extends implements MessageListener { private String myId = "foo"; private Connection connection; private Session session; private MessageConsumer consumer; private Destination destination; private ActiveMQQueue queue; private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(Hello Bean.class); public void start(JmsTemplate template) { String myId ="foo"; ConnectionFactory factory = template.getConnectionFactory(); try{ connection = factory.createConnection(); connection.setClientID(myId); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); queue = (org.activemq.message.ActiveMQQueue)session.create Queue(template.getDefaultDestinationName().toStrin g()); consumer = session.createConsumer(queue); consumer.setMessageListener(this); /*QueueBrowser qb= session.createBrowser(queue);*/ log.info("The default destination is " + template.getDefaultDestinationName().toString()); } catch(JMSException e) { log.info("In the customer start error" + e.getMessage()); } } public void destroy() throws JMSException { consumer.setMessageListener(null); consumer.close(); consumer = null; connection.close(); connection = null; } public void onMessage(Message message) { super.onMessage(message); try { //log.info("receiving message :" + ((ObjectMessage)message).getObject().toString()); if(message instanceof TextMessage){ log.info("The txt msg is: " + ((TextMessage)message).getText()); } if(message instanceof ObjectMessage){ //log.info("The object msg is: " + ((ObjectMessage)message).getObject().toString()); } message.acknowledge(); } catch (JMSException e) { log.info("Failed to acknowledge: " ); } } }
|
Let it snow~
|
 |
 |
|
|
subject: Need help with JMS+ Spring + ActiveMQ
|
|
|