Announcement Announcement Module
Collapse
No announcement yet.
JMS Async receive problem. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JMS Async receive problem.

    Hello. I want to write simple application which would receive some JMS messages from Queue. I'm using Spring and Sonic MQ. It works great when i use sync receive() method from my JMSTemplate object, but nothing work async.
    This is my Spring xml.

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:osgi="http://www.springframework.org/schema/osgi"
    xmlns:jms="http://www.springframework.org/schema/jms"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...ring-beans.xsd
    http://www.springframework.org/schema/osgi
    http://www.springframework.org/schem...pring-osgi.xsd
    http://www.springframework.org/schema/jms
    http://www.springframework.org/schema/jms/spring-jms.xsd">

    <!--
    <bean id = "jmsConnectionFactory" class = "org.apache.activemq.spring.ActiveMQConnectionFact ory">
    <property name ="brokerURL" value="tcp://localhost:61617"/>
    </bean>
    <bean id="connectionFactory" class="org.springframework.jms.connection.CachingC onnectionFactory">
    <constructor-arg ref="jmsConnectionFactory" />
    <property name="exceptionListener" ref="ExceptionListener" />
    <property name="sessionCacheSize" value="100" />

    </bean>
    -->
    <!-- Connection factories -->
    <bean id = "sonicConnectionFactory" class = "progress.message.jclient.QueueConnectionFacto ry">
    <property name = "BrokerURL" value = "sonic:2506"/>
    <property name = "DefaultUser" value = "Administrator"/>
    <property name = "DefaultPassword" value = "password"/>
    <property name = "ReconnectInterval" value = "30"/>
    <property name = "ReconnectTimeout" value = "0"/>
    </bean>


    <!-- Connection factory cached decorators -->
    <bean id = "cachedSonicFactoryDecorator" class = "org.springframework.jms.connection.CachingConnect ionFactory" >
    <constructor-arg ref = "sonicConnectionFactory"/>
    <property name="SessionCacheSize" value="1"/>
    </bean>

    <!-- Transaction managers -->
    <bean id = "transactionManager" class = "org.springframework.jms.connection.JmsTransaction Manager">
    <property name = "ConnectionFactory" ref = "cachedActiveMQFactoryDecorator"/>
    </bean>


    <!-- Destinations -->
    <bean id = "sonicQueue" class= "progress.message.jclient.Queue">
    <property name="QueueName" value="test.m1"/>
    </bean>

    <!-- JMSTempates -->
    <bean id = "JMSReceiverTemplate" class = "org.springframework.jms.core.JmsTemplate">
    <constructor-arg ref = "cachedSonicFactoryDecorator"/>
    <property name = "DefaultDestination" ref = "sonicQueue"/>
    <property name = "SessionTransacted" value = "true"/>
    <property name = "SessionAcknowledgeModeName" value = "SESSION_TRANSACTED"/>
    </bean>


    <!-- My POJOs -->

    <bean id = "MessageRecieveService" class="com.tander.receiver.MessageReceiver" init-method="loadPropertiesAndStart" destroy-method="stop" >
    <property name = "jmsTemplate" ref = "JMSReceiverTemplate"/>
    <property name = "transactionManager" ref = "transactionManager"/>
    <property name = "messageProcessor" ref = "ActiveMQMessageProcessor"/>
    </bean>

    <bean id="myJmsContainer" class="org.springframework.jms.listener.DefaultMes sageListenerContainer">
    <property name="connectionFactory" ref="cachedSonicFactoryDecorator"/>
    <property name="destinationName" value="sonicQueue"/>
    <property name="sessionTransacted" value="true"/>
    <property name="messageListener" ref="MessageRecieveService" />
    <property name="concurrentConsumers" value="1" />
    <property name="receiveTimeout" value="30000" />
    </bean>

    </beans>




    My listener:

    public void onMessage(javax.jms.Message arg0) {
    System.out.println("IM A RAINBOW !!!");
    }

    my main class:

    Resource res = new FileSystemResource("bin/META-INF/spring/MessageReciever.xml");
    XmlBeanFactory factory = new XmlBeanFactory(res);
    factory.getBean("myJmsContainer");


    Queue is full of msgs but listener doesn't hear anything

    Im try to call onMessage from Session callback, but this:

    public Object doInJms(Session arg0) throws JMSException {
    System.out.println(arg0.getMessageListener()); // NULL
    arg0.setMessageListener(this);
    System.out.println(arg0.getMessageListener()); //MYCLASS
    arg0.getMessageListener().onMessage(null); // Works
    return null;
    }

    Im read a lot of posts but cant find any solution or even any direction to find it. May be here someone can give me advice ?

    Sry me for my bad english and my propably stupid question.

  • #2
    JMS Async receive

    Hi,
    i cant find your code for sending message on queue,which further will be consumed by messageListner using onMessage().
    your deployed container and listner looks good but you need to write code for sending side.
    for a typical Async scenario you can use
    Code:
    jmsTemplate.send(msg,Queue)

    Comment

    Working...
    X