Skip to content

basicConsume with no-local flag not working as intended #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jcoeltjen opened this issue Sep 14, 2017 · 1 comment
Closed

basicConsume with no-local flag not working as intended #303

jcoeltjen opened this issue Sep 14, 2017 · 1 comment
Labels

Comments

@jcoeltjen
Copy link
Contributor

When doing a channel.basicConsume() with the no-local flag set, no messages published by this connection should arrive in handleDelivery() of the Consumer.

But is seems that the flag is ignored as it does not make any difference if I set or unset it.

Affected versions: 4.2.0 and 4.2.1 (tested, maybe more)

Minimal example:

import com.rabbitmq.client.*;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class NoLocal {

    public static void main(String[] args) throws Exception {

        ConnectionFactory connectionFactory = new ConnectionFactory();
        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();

        channel.exchangeDeclare("test-e", BuiltinExchangeType.FANOUT, false, true, null);
        channel.queueDeclare("test-q", false, false, true, null);
        channel.queueBind("test-q", "test-e", "test-r");

        channel.basicConsume("test-q", true, "consumer-tag", true, false, null, new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("should not print this at all ");
                System.out.println("message: " + new String(body, StandardCharsets.UTF_8));
            }
        });

        channel.basicPublish("test-e", "test-r", null, "message".getBytes(StandardCharsets.UTF_8));

        Thread.sleep(5000);
    }
}

In my understanding the prints in the handleDelivery() method of the consumer should not be called as the noLocal flag if the basicConsume is set to true.

@jcoeltjen jcoeltjen changed the title basicConsume with noä-local flag not working as intended basicConsume with no-local flag not working as intended Sep 14, 2017
@sigiesec
Copy link

This is a restriction of the rabbitmq-server, not the rabbitmq-java-client, as described at https://www.rabbitmq.com/specification.html:

The no-local parameter is not implemented. The value of this parameter is ignored and no attempt is made to prevent a consumer from receiving messages that were published on the same connection.

jcoeltjen added a commit to jcoeltjen/rabbitmq-java-client that referenced this issue Sep 14, 2017
Add warning to Javadoc that the noLocal flag is not supported by the rabbitmq server.
This is the same as for the immediate flag for publishing.

References rabbitmq#303
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants