Can't publish the message into queue and no error message

2,744 views
Skip to first unread message

nate

unread,
Mar 23, 2017, 2:20:32 PM3/23/17
to rabbitmq-users
I have created a new queue using the management interface. I am trying to publish the "hello" message but the following code doesn't work. Also it doesn't show any error message while running either. I don't see any queued message in the queue. What could be wrong? Please let me know.

       static void Main(string[] args)
        {
            var connectionFactory = new ConnectionFactory
            {
                HostName = "servername",
                Port = 5672,
                UserName = "guest",
                Password = "guest",
                VirtualHost = "/"
            };
            using (IConnection connection = connectionFactory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                     channel.QueueDeclare("test-queue", true, false, false, null);
     
                    string message = "Hello World!";
                    var body = Encoding.UTF8.GetBytes(message);

                    channel.BasicPublish(exchange: "",
                                         routingKey: "",
                                         basicProperties: null,
                                         body: body);
                    Console.WriteLine(" [x] Sent {0}", message);

                }
            }
            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadLine();
        }

Michael Klishin

unread,
Mar 23, 2017, 2:47:33 PM3/23/17
to rabbitm...@googlegroups.com
Your are trying to use the default exchange (exchange: "") but routing key is set to a blank string,
not queue name.

I suggest getting started with the tutorials and protocol concepts overview:

If you want the publisher to see when a message isn't routed, publish them with the mandatory
flag set to true and register a return listener, then messages will be returned to you.



--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
MK

Staff Software Engineer, Pivotal/RabbitMQ

nate

unread,
Mar 23, 2017, 3:23:34 PM3/23/17
to rabbitmq-users
The code works after using the queue name for routing key, deliveryMode = 2 and setting persistent.

But the same code doesn't work for 'user_b' on queue 'group_b.test-11'

Here are the permissions I have set. Thanks so much for the help. I appreciate it.

rabbitmqctl set_permissions -p / user_b "group_b\.*" "group_b\.*" "group_b\.*"

       static void Main(string[] args)
        {
            var connectionFactory = new ConnectionFactory
            {
                HostName = "servername",
                Port = 5672,
                UserName = "user_b",
                Password = "user_b",
                VirtualHost = "/"
            };
            using (IConnection connection = connectionFactory.
CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                     channel.QueueDeclare("group_b.test-11", true, false, false, null);

                    IBasicProperties props = channel.CreateBasicProperties();
                     props.ContentType = "text/plain";
                     props.SetPersistent(true);
                    props.DeliveryMode = 2;


                    string message = "Hello World!";
                    var body = Encoding.UTF8.GetBytes(message);
                    channel.BasicPublish("", "group_b.test-11", true, props, body);
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Michael Klishin

unread,
Mar 23, 2017, 3:49:05 PM3/23/17
to rabbitm...@googlegroups.com
Your permissions only allow publishing via exchanges whose name begins with a `group_b\.`.

You are publishing to the default exchange (which in permission settings uses the name of `amq.default`,
as mentioned in the docs at http://www.rabbitmq.com/access-control.html.

To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

nate

unread,
Mar 24, 2017, 3:33:35 PM3/24/17
to rabbitmq-users
I am working on adding a new group_b queue and user_b to access to this queue on existing Production server.
1. Currently we don't have any exchanges on the server and already a Queue(group_a) running with default admin privileges. If I add any  exchange(groub_b) does it cause any issues for the existing Queue(group_a)?
2. My requirement is simple. Add a new Queue(group_b) and restrict(user_b) to post messages to this Queue. I went through the documentation but still not clear. Please clarify. I might add (group_c) Queue and (User_c) user in near future. Please suggest.

Michael Klishin

unread,
Mar 24, 2017, 3:41:12 PM3/24/17
to rabbitm...@googlegroups.com
I'm sorry but I don't have much to add to this thread and the original
one where you or your colleague were asking about how to separate
permissions for 2 users.

You are asking members of this list to do your job for you by posting a step
by step instruction.

Your next course of action should be understanding how publishing and routing
works (hint: messages are NOT published to queues). It should be reasonably easy
then to come up with permission patterns for your case. Also note that you are trying
to publish over the default exchange which is NOT the only way to publish and when it
comes to restricting access, its convenience is annoying and counterproductive. So consider
using a separate exchange, there's nothing wrong with using more than one or even one per
user (until you go into 100s of thousands or more, at least).


To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

nate

unread,
Mar 24, 2017, 5:01:06 PM3/24/17
to rabbitmq-users
Sorry about it. I was the one asking on previous thread how to separate permissions for 2 users. In the previous thread you mentioned:
  "Since you are looking to limit consumption and deletion, I don't see a real need
   for a separate exchange."

This sentence confused me since I am a beginner to this concept. I will go through more documentation. thanks for your help.

Michael Klishin

unread,
Mar 24, 2017, 6:32:42 PM3/24/17
to rabbitm...@googlegroups.com
You can set it up in such a way that default exchange access is restricted. But it
may be more straightforward using 2 separate exchanges first.

To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages