多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
###32.2.2 发送消息 Spring的`AmqpTemplate`和`AmqpAdmin`会被自动配置,你可以将它们直接注入beans中: ```java import org.springframework.amqp.core.AmqpAdmin; import org.springframework.amqp.core.AmqpTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class MyBean { private final AmqpAdmin amqpAdmin; private final AmqpTemplate amqpTemplate; @Autowired public MyBean(AmqpAdmin amqpAdmin, AmqpTemplate amqpTemplate) { this.amqpAdmin = amqpAdmin; this.amqpTemplate = amqpTemplate; } // ... } ``` **注** 可以使用相似方式注入`RabbitMessagingTemplate`,如果定义`MessageConverter` bean,它将自动关联到自动配置的`AmqpTemplate`。 如果需要的话,所有定义为bean的`org.springframework.amqp.core.Queue`将自动在RabbitMQ实例中声明相应的队列。你可以启用`AmqpTemplate`的重试选项,例如代理连接丢失时,重试默认不启用。