示例#1
0
        public RabbitPublisher()
        {
            var config = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed);
            var conn   = config[MessagePublisherLocalConfig.HostConnectionString];

            _exchangeName = config[MessagePublisherLocalConfig.ExchangeName];

            _cf = new ConnectionFactory {
                Uri = conn
            };
            _connection = _cf.CreateConnection();
            _channel    = _connection.CreateModel();

            var specifier = new MessageBusTopologySpecifier();
            var spex      = specifier.SpecifyExchange(_exchangeName);

            if (spex == null)
            {
                throw new ArgumentException(_exchangeName);
            }

            _channel.ExchangeDeclare(_exchangeName, MessageBusTopologySpecifier.Translate(spex.ExchangeType));
            _props = _channel.CreateBasicProperties();
            _props.DeliveryMode = 2;
        }
示例#2
0
        public RabbitListener()
        {
            var config = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed);

            _exchangeName = config[MessageListenerLocalConfig.ExchangeName];
            _queueName    = config[MessageListenerLocalConfig.QueueName];
            var conn = config[MessageListenerLocalConfig.HostConnectionString];

            _cf = new ConnectionFactory {
                Uri = conn
            };
            _connection = _cf.CreateConnection();
            _channel    = _connection.CreateModel();

            var specifier = new MessageBusTopologySpecifier();
            var spex      = specifier.SpecifyExchange(_exchangeName);

            if (spex == null)
            {
                throw new ArgumentException(_exchangeName);
            }

            _channel.ExchangeDeclare(_exchangeName, MessageBusTopologySpecifier.Translate(spex.ExchangeType));
            _cts = new CancellationTokenSource();
        }