0

On Publishing the message to Rabbit MQ Exchange, few of the messages are getting lost. For example, posted 10 messages only five got delivered to the binded queue and the rest 5 messages are lost. Please advice.

Below is Spring XML configuration for connection

 <bean id="cachingConnectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory" destroy-method="destroy">
    <property name="addresses" value="example.com:8080"/>
    <property name="username" value="guest" />
    <property name="password" value="guest" />
    <property name="virtualHost" value="guest-app" />
    <property name="connectionTimeout" value="1000"/>
    <property name="cacheMode" value="#{T(org.springframework.amqp.rabbit.connection.CachingConnectionFactory.CacheMode).CONNECTION}"/>
    <property name="channelCacheSize" value="6000"/> 
    <property name="channelCheckoutTimeout" value="60000"/>
    <property name="requestedHeartBeat" value="30"/>
    <property name="publisherConfirms" value="true"/>
    <property name="publisherReturns" value="true"/>
</bean>

Below is Rabbit Template Config

    <rabbit:template id="amqpTemplate" connection-factory="cachingConnectionFactory" mandatory="true" retry-template="retryTemplate" /> 
<bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate">
    <property name="backOffPolicy">
        <bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
            <property name="initialInterval" value="500" />
            <property name="multiplier" value="10.0" />
            <property name="maxInterval" value="10000" />
        </bean>
    </property>
</bean>
<rabbit:admin connection-factory="cachingConnectionFactory" />

Below is for Publishing message

int:chain input-channel="output">
      <int:header-enricher>
            <int:header name="amqp_deliveryMode" value="PERSISTENT" type="org.springframework.amqp.core.MessageDeliveryMode"/>
    </int:header-enricher> 
    <int-amqp:outbound-channel-adapter id="outboundAmqp" amqp-template="amqpTemplate" exchange-name-expression="headers['exchange']" routing-key-expression="headers['routingKey']" mapped-request-headers="*" confirm-correlation-expression="payload" confirm-ack-channel="msgResponse" confirm-nack-channel="msgResponse" return-channel="msgResponse"/>                                   

  • And? Do you really don't have anything in the returnChannel? I don't believe that there is no any errors... – Artem Bilan Aug 25 '16 at 10:51
  • 1
    The fact that you "lost" exactly 50% of the messages is very suspicious - my best guess is you have 2 consumers running and 5 went to each of them. – Gary Russell Aug 25 '16 at 12:51
  • Thanks Artem and Gary for the quick response! – user6755410 Aug 25 '16 at 14:50
  • The issue here is when I run this as an standalone application using main method with a thread sleep upon posting the message just before context close It works fine! However, the same if I run on Spring XD, I see this issues happening without any error messages. I don't see anything on return channel too. – user6755410 Aug 25 '16 at 14:55
  • public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("config/applicationContext.xml"); String messageStr = "test" Message message = MessageBuilder.withPayload(messageStr).setHeader(EventMsgPubUtil.EVENT_TYPE, EventMsgPubUtil.OUTBOUND).build(); MessageChannel channel = context.getBean("input", MessageChannel.class); channel.send(message); try { Thread.sleep(60000); } catch (InterruptedException e) { e.printStackTrace(); } context.close(); } } – user6755410 Aug 25 '16 at 15:00
  • The issue got fixed after renaming, the output channel in Spring-XD config file of custom Sink module. I was using the channel to transform data using SI-transformer, where I used output-channel="output" and apparently, this added up to an extra queue on message bus and also some of the messages use to be routed to this queues inside the message bus instead of routing to actual Rabbit-MQ servers/exchanges and queues from the connection factory. – user6755410 Aug 27 '16 at 08:28

0 Answers0