Skip to content

Commit 887d91f

Browse files
committed
rabbitmq-client README.md file added
1 parent 02caf26 commit 887d91f

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
HOW to send Message to RabbitMQ Broker.(First setup RabbitMQ broker and create exchange and queue using web console)
2+
--------------------------------------------------------------------------------------------------------------------
3+
step-1
4+
--------
5+
create spring boot project with RabbitMq dependency
6+
7+
Example:
8+
-------
9+
<dependency>
10+
<groupId>org.springframework.boot</groupId>
11+
<artifactId>spring-boot-starter-amqp</artifactId>
12+
</dependency>
13+
14+
15+
step-2
16+
----------
17+
create bean of ConnectionFactory using CachingConnectionFactory class for RabbitTemplate Bean.
18+
19+
Example
20+
--------
21+
22+
@Bean
23+
public ConnectionFactory connectionFactory() {
24+
CachingConnectionFactory factory = new CachingConnectionFactory("localhost");
25+
factory.setPort(5672);
26+
factory.setUsername("guest");
27+
factory.setPassword("guest");
28+
return factory;
29+
}
30+
31+
32+
step-3
33+
------
34+
Inject or Autowired RabbitTemplate Bean to call method of Rabbitemplate
35+
36+
@Autowired
37+
private RabbitTemplate rabbitTemplate;
38+
39+
calling using CommandLineRunner
40+
---------------------------
41+
42+
@Override
43+
public void run(String... args) throws Exception {
44+
System.out.println("message sending started.");
45+
rabbitTemplate.convertAndSend("ami.direct", "", "First Message from client code");
46+
System.out.println("message sending finished.");
47+
}
48+
49+
50+
"ami.direct"--> Exchanged name
51+
"First Message from client code"--> message to exchange
52+
53+
Notes:
54+
--------
55+
In RabbitMQ client cant send message direct to Queue(Topic not exist)..client can send message to exchange and exchange have binding to queue (one to one and one to many or many to one relations)
56+
57+
58+

0 commit comments

Comments
 (0)