如何使用带有Jhipster的RabbitMQ创建新的队列?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用带有Jhipster的RabbitMQ创建新的队列?相关的知识,希望对你有一定的参考价值。

我创建了一个新的jhipster微服务。我添加了RabbitMQ模块。它是功能性的。不过我想创建手动队列,我试图在CloudMessagingConfiguration中添加它,但它不会抛出任何这些方法。你知道怎么做吗?

它似乎与JHIPSTER配置相关,而不是RABBITMQ。也许是因为spring cloud messaging和spring amqp api之间存在差异?

谢谢

@Configuration
@Profile(JHipsterConstants.SPRING_PROFILE_CLOUD)
@EnableRabbit
public class CloudMessagingConfiguration extends AbstractCloudConfig {

private final Logger log = LoggerFactory.getLogger(CloudMessagingConfiguration.class); 

@Bean
public ConnectionFactory rabbitFactory() {
    return connectionFactory().rabbitConnectionFactory();
}

   /**
   * Added thanks to the comment of Gary Russell
   * Required for executing adminstration functions against an AMQP Broker 
   */ 
   @Bean
   public AmqpAdmin amqpAdmin() {
     return new RabbitAdmin(rabbitFactory()); 
   } 

/**
 * This queue will be declared. This means it will be created if it does not exist. Once declared, you can do something
 * like the following:
 * 
 * @RabbitListener(queues = "#{@myDurableQueue}")
 * @Transactional
 * public void handleMyDurableQueueMessage(CustomDurableDto myMessage) {
 *    // Anything you wanenter code heret! This can also return a non-void which will queue it back in to the queue attached to @RabbitListener
 * }
 */
@Bean
public Queue myDurableQueue() {
    // This queue has the following properties:
    // name: my_durable
    // durable: true
    // exclusive: false
    // auto_delete: false
    return new Queue("my_durable", true, false, false);
}

/**
 * The following is a complete declaration of an exchange, a queue and a exchange-queue binding
 */
@Bean
public TopicExchange emailExchange() {
    return new TopicExchange("email", true, false);
}

@Bean
public Queue inboundEmailQueue() {
    return new Queue("email_inbound", true, false, false);
}

@Bean
public Binding inboundEmailExchangeBinding() {
    // Important part is the routing key -- this is just an example
    return BindingBuilder.bind(inboundEmailQueue()).to(emailExchange()).with("from.*");
}

}

答案

您需要在配置中添加RabbitAdmin @Bean,它将自动检测并声明交换/队列/绑定。

Spring AMQP documentation

以上是关于如何使用带有Jhipster的RabbitMQ创建新的队列?的主要内容,如果未能解决你的问题,请参考以下文章

JHipster - 网关如何在微服务中进行身份验证?

JHipster - 如何在 Eclipse 中仅调试微服务架构中的一个网关(或微服务)?

jHipster:对于生产中的简单用户,新用户模块如何与 Keycloak 一起工作?

无法创建新的 jhipster 项目

如何在 Jhipster 中配置热重载?

如何使用 JHipster 和 Liquibase 更新现有数据库? [复制]