Skip to content

mohammad2java/rabbitmq-receiver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How To receive the message from RabbitMQ

step-1

create spring boot project with RabbitMQ dependency

Example:

	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-amqp</artifactId>
	</dependency>

step-2

create following beans

1-ConnectionFactory --- for the connection of rabbitmq
2-SimpleMessageListenerContainer --for listening the associated queue.
3-MessageListenerAdapter --for mapping the receiver method to receive message

Example:

@Bean
public ConnectionFactory connectionFactory() {
	CachingConnectionFactory factory =  new CachingConnectionFactory("localhost");
	factory.setPort(5672);
	factory.setUsername("guest");
	factory.setPassword("guest");
	return factory;
}

@Bean
SimpleMessageListenerContainer container(ConnectionFactory connectionFactory,
        MessageListenerAdapter listenerAdapter) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.setQueueNames("DIRECT-QUEUE");
    container.setMessageListener(listenerAdapter);
    return container;
}

@Bean
MessageListenerAdapter listenerAdapter(Receiver receiver) {
    return new MessageListenerAdapter(receiver, "receiveMessage");
}

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages