Announcement Announcement Module
Collapse
No announcement yet.
Duplicate Message using Asynchronous Consumer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Duplicate Message using Asynchronous Consumer

    Hi,

    I am having problem using the SimpleMessageListenerContainer. Everytime I send a message from the producer (A MVC Controller), the POJO Message Driven Bean receives the message 2 times (duplicate message). I am not sure if my configuration is wrong or if it is a concurrency problem is the SimpleMessageListenerContainer.

    I am using Virgo tomcat server 3.0.0.M4, spring-amqp 1.0.0.RC1, amqp-client 2.4.1, spring-rabbit 1.0.0.RC1.

    rabbitmq-config.xml
    ----------------------------------------------------------------------------------------------------------------------------
    <bean id="cachingConnectionFactory"
    class="org.springframework.amqp.rabbit.connection. CachingConnectionFactory">
    <constructor-arg value="localhost" />
    <property name="username" value="guest" />
    <property name="password" value="guest" />
    </bean>

    <rabbit:admin id="amqpAdmin" connection-factory="cachingConnectionFactory" />

    <rabbit:queue id="newMemberQueue" />

    <rabbit:fanout-exchange id="newMemberExchange"
    name="com.company.newmember">
    <rabbit:bindings>
    <rabbit:binding queue="newMemberQueue" />
    </rabbit:bindings>
    </rabbit:fanout-exchange>

    <bean id="newMemberMessageHandler" class="com.company.amqp.async.NewMemberHandler">
    </bean>

    <bean id="newMemberMessageListenerAdapter"
    class="org.springframework.amqp.rabbit.listener.ad apter.MessageListenerAdapter">
    <constructor-arg>
    <ref bean="newMemberMessageHandler" />
    </constructor-arg>
    <!-- <property name="messageConverter"> <null /> </property> -->
    </bean>

    <rabbit:listener-container connection-factory="cachingConnectionFactory">
    <rabbit:listener queues="newMemberQueue" ref="newMemberMessageListenerAdapter" />
    </rabbit:listener-container>

    <bean id="newMemberRabbitTemplate" class="org.springframework.amqp.rabbit.core.Rabbit Template">
    <property name="connectionFactory" ref="cachingConnectionFactory" />
    <property name="exchange" value="com.company.newmember" />
    </bean>
    ----------------------------------------------------------------------------------------------------------------

    public class NewMemberHandler {
    public void handleMessage(String text) {
    // do sth
    }
    }

    @Controller
    public class RegistrationController {
    @RequestMapping(value = "/registration/form", method = RequestMethod.POST)
    public String handleForm(
    HttpServletRequest request,
    HttpServletResponse response) {

    // do sth
    rabbitTemplate.convertAndSend("member id");

    }
    }

  • #2
    Looks OK on the face of it. Maybe you are loading rabbit-config.xml twice?

    Comment


    • #3
      I just check the web.xml to make sure rabbitmq-config.xml it is not declared under contextConfigLocation and test-servlet.xml doesn't include '<import resource="rabbitmq-config.xml" />' but NewMemberHandler still receive message twice.

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

      <context-param>
      <param-name>contextClass</param-name>
      <param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXml WebApplicationContext</param-value>
      </context-param>
      <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>
      /META-INF/spring/applicationContext.xml
      </param-value>
      </context-param>

      <listener>
      <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
      </listener>

      <servlet>
      <servlet-name>test</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
      </servlet>

      <servlet-mapping>
      <servlet-name>test</servlet-name>
      <url-pattern>/*</url-pattern>
      </servlet-mapping>

      </web-app>

      Comment


      • #4
        Maybe you could write an integration test that loads the context as if it was the web application? We could try and isolate the problem that way (and you will find the test saves you a lot of time in the future as well).

        I did notice that you are using Virgo and keeping your webapp context in META-INF/spring. Maybe the container is loading it as well via Spring DM naming conventions?

        Comment


        • #5
          Thankyou so much

          moving /META-INF/spring/applicationContext.xml to /WEB-INF does solve the problem.

          Comment

          Working...
          X