Exemplo n.º 1
0
        /// <summary>
        /// new
        /// </summary>
        /// <param name="queueName"></param>
        /// <param name="config"></param>
        /// <param name="callback"></param>
        public Consumer(string queueName, Config.RabbitMQ config,
                        Action <Messaging.Message> callback)
        {
            if (string.IsNullOrEmpty(queueName))
            {
                throw new ArgumentNullException("queueName");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            this.QueueName = queueName;
            this._callback = callback;
            this.Exchange  = config.Exchange;

            this._factory = new ConnectionFactory
            {
                HostName           = config.Host,
                Port               = config.Port,
                UserName           = config.UserName,
                Password           = config.Password,
                VirtualHost        = config.VHost,
                RequestedHeartbeat = 10,
            };

            this._server = GenServer.Start(this);
            this._server.Call(new ListenMessage());
        }
Exemplo n.º 2
0
        /// <summary>
        /// new
        /// </summary>
        /// <param name="config"></param>
        public Publisher(Config.RabbitMQ config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            this._factory = new ConnectionFactory
            {
                HostName    = config.Host,
                Port        = config.Port,
                UserName    = config.UserName,
                Password    = config.Password,
                VirtualHost = config.VHost
            };
            this._arrWorkers = Enumerable.Range(0, 4).Select(_ => new Worker(this, config.Exchange)).ToArray();
            this._server     = GenServer.Start(this);
        }