0

I have created a new jhipster microservice. I have added the RabbitMQ module. It is functionnal. Nevertheless I wanted to create manually queue, I have tried to add it in CloudMessagingConfiguration but it does not go throw any of these methods. Do you have any idea how to do it?

It seems more relative to JHIPSTER configuration rather to RABBITMQ. Perhaps is it due to the difference between spring cloud messaging and spring amqp api ?

Thanks

@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.*");
}

}

1 Answer 1

1

You need to add a RabbitAdmin @Bean to the configuration and it will automatically detect and declare the exchange/queue/binding.

See the Spring AMQP documentation.

Sign up to request clarification or add additional context in comments.

2 Comments

I have added the following lines ` @Bean public ConnectionFactory rabbitFactory() { return connectionFactory().rabbitConnectionFactory(); } /** * Required for executing adminstration functions against an AMQP Broker */ @Bean public AmqpAdmin amqpAdmin() { return new RabbitAdmin(rabbitFactory()); } ` But it never go into the CloudMessagingConfiguration class Any idea why Jhipster do not load the file?
Don't put code in comments - it's unreadable; edit the question instead. Sorry - I don't know anything about JHipster.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.