0

I am trying to get the Broker Acknowledgement using RabbitMQ in Micronaut.

Listener

@RabbitListener
public class ProductListener {

    @Queue(ProductTopicConstants.GET_PRODUCTS)
    public String find(String text) {
        return text.toUpperCase();
    }
}

Controller

@Get(value = "/{text}", single = true)
    public Maybe<String> Find(String text) {
        iproductProducer.find(text).subscribe(item ->{
            System.out.println(item);
        });
        return null;
    }

Producer

@RabbitClient(ProductTopicConstants.FETE_BIRD_EXCHANGE)
public interface IProductProducer {
    @Binding(ProductTopicConstants.GET_PRODUCTS)
    Maybe<String> find(String text);
}

UPDATE - #1

@RabbitClient(ProductTopicConstants.FETE_BIRD_EXCHANGE)
    public interface IProductProducer {
        @Binding(ProductTopicConstants.GET_PRODUCTS)
        Completable find(String text);
    }

As per the documentation

Client methods support two return types, void and a reactive type. If the method returns void, the message will be published and the method will return without acknowledgement. If a reactive type is the return type, a "cold" publisher will be returned that can be subscribed to.

But in the controller System.out.println(item); the acknowledgment never gets.

San Jaisy
  • 15,327
  • 34
  • 171
  • 290

1 Answers1

0

You aren't looking for broker acknowledgement. You are describing RPC. The documentation clearly states how to set this up. From what I can tell, it seems you are missing @RabbitProperty(name = "replyTo", value = "amq.rabbitmq.reply-to") on the client.

James Kleeh
  • 12,094
  • 5
  • 34
  • 61
  • How do I get the broker acknowledgment? – San Jaisy Dec 11 '20 at 14:51
  • If you really only care about acknowledgement then you should return a `Completable`. There are no items emitted for just an acknowledgement so it makes sense your println is not happening – James Kleeh Dec 11 '20 at 16:12