Skip to content

Commit bb96c92

Browse files
authored
Update 32.2.2 Sending a message.md
1 parent 1fb03a5 commit bb96c92

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,27 @@
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`的重试选项,例如代理连接丢失时,重试默认不启用。

0 commit comments

Comments
 (0)