You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
0 commit comments