How can read message from rabbit and return boolean value?

I have built this code to sender message from client Java and C# by using rabbit.
So I have this:

public Boolean isNaoConnect()
    bool isConnect = false;
    string azione = "{";
    //immetto i parametri di tipo stringa
    azione += "}&&{";
    //parametri di tipo int
    azione += "}&&";
    var messageBody = Encoding.UTF8.GetBytes(azione);
    channel.BasicPublish("", "ASTRO", null, messageBody);

    var consumer = new EventingBasicConsumer(channelResponse);
    consumer.Received += (model, ea) =>
    var body = ea.Body;
    var message = Encoding.UTF8.GetString(body);
    if (message != null && message.Equals("true"))
        isConnect= true;

    channelResponse.BasicConsume(queue: "ASTRO_RESPONSE", noAck: true, consumer: consumer);


    return isConnect;

I want this, if the client Java send the message true, the method isNaoConnect return true else false.
Now I can read the message but I can’t return true o false with this code.
How can I fix it?

Source: java

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.