开发者

RabbitMQ consumer

I have a Windows Service that retrieves messages from a RabbitMQ queue. The service works locally on a Windows 7 machine. When I install the service on a Windows 2008 server it does not work (and does not throw any errors). My ASP.net MVC app can publish messages to the same queue. Could there be a firewall or security issue here? Should I be retrieving messages from RabbitMQ differently than below?

    public void PullFromQueue()
    {
        var connectionFactory = new ConnectionFactory();

       开发者_开发百科 using (var connection = connectionFactory.CreateConnection())
        using (var channel = connection.CreateModel())
        {
            var consumer = new QueueingBasicConsumer(channel);
            channel.ExchangeDeclare(ExchangeName, ExchangeType.Direct, true);
            channel.QueueDeclare(QueueName, true);
            channel.QueueBind(QueueName, ExchangeName, RoutingKey, false, null);
            channel.BasicConsume(QueueName, null, consumer);
            while (true)
            {
                try
                {
                    var e = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
                    var props = e.BasicProperties;
                    props.DeliveryMode = PersistentDelivery;
                    var businessObject = DeserializeBusinessObject(e.DeliveryTag, e.Body);
                    processBusinessObject(businessObject);
                    channel.BasicAck(e.DeliveryTag, false);

                }
                catch (Exception ex)
                {
                    Log<RabbitMQWrapper>.Error("Error in pulling Business Object from Queue", ex);
                }

            }
        }
    } 


Forgot about the GAC. When I installed the RabbitMQ.Client locally, it was placed in the GAC. Did not set the RabbitMQ.Client DLL to copy local. I find it curious that it did not generate a runtime error. I feel dumb.


I do the same thing and it works for me. Ensure you are running the service under NetworkService. Also the firewall could be an issue.


If you service just fail to start check the Event Logs (Application Event Logs) with Event Log Viewer.

If there is no clue, you should first determine what issue you are having right now (log4net can be usefull or simply just write exception to eventlog):

EventLog.WriteEntry(ex.Message + ", " ex.StackTrace);

If you are using RabbitMQ on your local machine with quest user, quest user can only access via loop-back! In this case, you should add different user like:

rabbitmqctl add_user testuser testpassword
rabbitmqctl set_user_tags testuser administrator
rabbitmqctl set_permissions -p / testuser ".*" ".*" ".*"

Regards...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜