Hi all,
I'm a newbie about JMS, I've issues with this easy JMS sample, receiver waits the message and then goes to timeout. Who knows if sender has sent it correctly, maybe yes because I don't have error on sender which ends correctly.
Of course JMS Broker is up and running.
Fragment codes:
jms_test.xml
TestJMSSender.javaCode:... <!-- Broker JMS --> <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://127.0.0.1:61616"/> </bean> <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> <property name="connectionFactory" ref="connectionFactory" /> <property name="receiveTimeout" value="60000"/> <!-- attesa max del msg in ms da parte del ricevente --> <!-- <property name="defaultDestination" ref="testTopic" /> destinazione di defualt, evitiamo di inserirla nel metodo send()--> </bean> <bean id="testTopic" class="org.apache.activemq.command.ActiveMQTopic"> <constructor-arg index="0" value="test.topic"/> </bean> <!-- Broker JMS --> <!-- SENDER --> <bean id="mySender" class="TestJMSSender"> <property name="jmsTemplate" ref="jmsTemplate" /> <property name="dest" ref="testTopic" /> </bean> <!-- SENDER --> <!-- RECEIVER --> <bean id="myReceiver" class="TestJMSReceiver"> <property name="jmsTemplate" ref="jmsTemplate" /> <property name="dest" ref="testTopic" /> </bean> <!-- RECEIVER -->
TestJMSReceiver.javaCode:public class TestJMSSender { public static Logger log=Logger.getRootLogger(); public static ApplicationContext context; private JmsTemplate jmsTemplate; private Destination dest; public static void main(String[] args) { context=new FileSystemXmlApplicationContext("jms_test.xml"); log.info("Start appl"); TestJMSSender sender=(TestJMSSender)context.getBean("mySender"); sender.send(); System.out.println("Message sent !"); log.info("End appl"); } /** * Creazione messaggio JMS ed invio */ private void send(){ jmsTemplate.send( dest, new MessageCreator(){ public Message createMessage(Session session) throws JMSException { MapMessage message = session.createMapMessage(); message.setString("first", "alex"); message.setString("last", "black"); message.setString("text", "Hello"); return message; } } ); } public void setJmsTemplate(JmsTemplate jmsTemplate) { this.jmsTemplate = jmsTemplate; } public void setDest(Destination dest) { this.dest = dest; } }
Log fileCode:public class TestJMSReceiver { public static Logger log=Logger.getRootLogger(); public static ApplicationContext context; private JmsTemplate jmsTemplate; private Destination dest; public static void main(String[] args){ context=new FileSystemXmlApplicationContext("jms_test.xml"); log.info("Start appl"); TestJMSReceiver receiv=(TestJMSReceiver)context.getBean("myReceiver"); System.out.println("Retrieve message"); MapMessage message =receiv.receive(); System.out.println("Received message:"); try { System.out.println(message.getString("first")); System.out.println(message.getString("last")); System.out.println(message.getString("text")); } catch (JMSException e) { throw JmsUtils.convertJmsAccessException(e); } log.info("End appl"); } private MapMessage receive() { //return (MapMessage)jmsTemplate.receive(); return (MapMessage)jmsTemplate.receive(dest); } public void setJmsTemplate(JmsTemplate jmsTemplate) { this.jmsTemplate = jmsTemplate; } public void setDest(Destination dest) { this.dest = dest; } }
Thanks all and BR,Code:2010-Jun-03 17:37:59 INFO TestJMSSender (line:38) - Start appl 2010-Jun-03 17:37:59 DEBUG org.apache.activemq.transport.WireFormatNegotiator (line:82) - Sending: WireFormatInfo { version=5, properties={CacheSize=1024, CacheEnabled=true, SizePrefixDisabled=false, MaxInactivityDurationInitalDelay=10000, TcpNoDelayEnabled=true, MaxInactivityDuration=30000, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]} 2010-Jun-03 17:37:59 DEBUG org.apache.activemq.transport.WireFormatNegotiator (line:118) - Received WireFormat: WireFormatInfo { version=5, properties={CacheSize=1024, CacheEnabled=true, SizePrefixDisabled=false, MaxInactivityDurationInitalDelay=10000, TcpNoDelayEnabled=true, MaxInactivityDuration=30000, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]} 2010-Jun-03 17:37:59 DEBUG org.apache.activemq.transport.WireFormatNegotiator (line:125) - tcp:///127.0.0.1:61616 before negotiation: OpenWireFormat{version=5, cacheEnabled=false, stackTraceEnabled=false, tightEncodingEnabled=false, sizePrefixDisabled=false} 2010-Jun-03 17:37:59 DEBUG org.apache.activemq.transport.WireFormatNegotiator (line:140) - tcp:///127.0.0.1:61616 after negotiation: OpenWireFormat{version=5, cacheEnabled=true, stackTraceEnabled=true, tightEncodingEnabled=true, sizePrefixDisabled=false} 2010-Jun-03 17:37:59 DEBUG org.apache.activemq.transport.tcp.TcpTransport (line:459) - Stopping transport tcp:///127.0.0.1:61616 2010-Jun-03 17:37:59 INFO TestJMSSender (line:44) - End appl 2010-Jun-03 17:38:03 INFO TestJMSReceiver (line:22) - Start appl 2010-Jun-03 17:38:03 DEBUG org.apache.activemq.transport.WireFormatNegotiator (line:82) - Sending: WireFormatInfo { version=5, properties={CacheSize=1024, CacheEnabled=true, SizePrefixDisabled=false, MaxInactivityDurationInitalDelay=10000, TcpNoDelayEnabled=true, MaxInactivityDuration=30000, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]} 2010-Jun-03 17:38:03 DEBUG org.apache.activemq.transport.WireFormatNegotiator (line:118) - Received WireFormat: WireFormatInfo { version=5, properties={CacheSize=1024, CacheEnabled=true, SizePrefixDisabled=false, MaxInactivityDurationInitalDelay=10000, TcpNoDelayEnabled=true, MaxInactivityDuration=30000, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]} 2010-Jun-03 17:38:03 DEBUG org.apache.activemq.transport.WireFormatNegotiator (line:125) - tcp:///127.0.0.1:61616 before negotiation: OpenWireFormat{version=5, cacheEnabled=false, stackTraceEnabled=false, tightEncodingEnabled=false, sizePrefixDisabled=false} 2010-Jun-03 17:38:03 DEBUG org.apache.activemq.transport.WireFormatNegotiator (line:140) - tcp:///127.0.0.1:61616 after negotiation: OpenWireFormat{version=5, cacheEnabled=true, stackTraceEnabled=true, tightEncodingEnabled=true, sizePrefixDisabled=false}
Ale


Reply With Quote