1) Below is the code for the configuration for rabbitMQ with Spring.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/rabbit
http://www.springframework.org/schema/rabbit/spring-rabbit-1.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">
<context:component-scan base-package="com.messaging.impl" />
<rabbit:connection-factory id="connectionFactory"
host="${rabbitmq.host}" port="${rabbitmq.port}"
username="${rabbitmq.username}" password="${rabbitmq.password}"
channel-cache-size="${rabbitmq.ChannelCacheSize}"
requested-heartbeat="${rabbitmq.requestedHeartBeat}" />
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"
exchange="${request.exchange}" queue="${request.out.queue}" />
<rabbit:admin id="rabbitAdmin" connection-factory="connectionFactory" />
<rabbit:queue name="${request.out.queue}"
declared-by="rabbitAdmin" />
<rabbit:listener-container
connection-factory="connectionFactory">
<rabbit:listener queues="${request.out.queue}"
ref="messageSender" />
</rabbit:listener-container>
<bean id="messageSender"
class="com.messaging.impl.MessageSenderImpl" />
<rabbit:topic-exchange name="${request.exchange}"
declared-by="rabbitAdmin">
<rabbit:bindings>
<rabbit:binding queue="${request.out.queue}"
pattern="routingkey.*" />
</rabbit:bindings>
</rabbit:topic-exchange>
</beans>
2) Below is the code for Java sender class.
@Service
public class MessageSenderImpl implements MessageSender {
@Autowired
private AmqpTemplate amqpTemplate;
public void sendMessage(String message){
amqpTemplate.convertAndSend(message);
System.out.println("message is" +message);
}
}
3) pom.xml has the below dependency
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-amqp</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
I did not find a complete example which can be used for this requirement.I came up with this configuration after checking various websites and selecting the ones I need for this setup. Please advise.
NOTE :- I have already implemented posting to the exchange and reading from the queue. However I need advise on how to implement failure scenarios. Please advise.