File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change 1
- ###32 .2.2 Sending a message
1
+ ###32 .2.2 发送消息
2
+ Spring的` AmqpTemplate ` 和` AmqpAdmin ` 会被自动配置,你可以将它们直接注入beans中:
3
+ ``` java
4
+ import org.springframework.amqp.core.AmqpAdmin ;
5
+ import org.springframework.amqp.core.AmqpTemplate ;
6
+ import org.springframework.beans.factory.annotation.Autowired ;
7
+ import org.springframework.stereotype.Component ;
8
+
9
+ @Component
10
+ public class MyBean {
11
+
12
+ private final AmqpAdmin amqpAdmin;
13
+ private final AmqpTemplate amqpTemplate;
14
+
15
+ @Autowired
16
+ public MyBean (AmqpAdmin amqpAdmin , AmqpTemplate amqpTemplate ) {
17
+ this . amqpAdmin = amqpAdmin;
18
+ this . amqpTemplate = amqpTemplate;
19
+ }
20
+
21
+ // ...
22
+
23
+ }
24
+ ```
25
+ ** 注** 可以使用相似方式注入` RabbitMessagingTemplate ` ,如果定义` MessageConverter ` bean,它将自动关联到自动配置的` AmqpTemplate ` 。
26
+
27
+ 如果需要的话,所有定义为bean的` org.springframework.amqp.core.Queue ` 将自动在RabbitMQ实例中声明相应的队列。你可以启用` AmqpTemplate ` 的重试选项,例如代理连接丢失时,重试默认不启用。
You can’t perform that action at this time.
0 commit comments