Exemple #1
0
        public void Setup()
        {
            _routeFinder.FindExchangeName <Customer>().Returns("Exchange.Customer");
            _routeFinder.FindQueueName <Customer>(null).ReturnsForAnyArgs("Queue.Customer");
            _routeFinder.FindRoutingKey <Customer>().Returns("Customer");

            _routeSetupData = new RouteSetupData
            {
                RouteFinder       = _routeFinder,
                ExchangeSetupData = new ExchangeSetupData(),
                QueueSetupData    = new QueueSetupData()
            };
        }
        public void Setup()
        {
            _routeFinder.FindExchangeName <Customer>().Returns("Exchange.Customer");
            _routeFinder.FindQueueName <Customer>(null).ReturnsForAnyArgs("Queue.Customer");
            _routeFinder.FindRoutingKey <Customer>().Returns("Customer");

            _routeSetupData = new RouteSetupData
            {
                RouteFinder       = _routeFinder,
                ExchangeSetupData = new ExchangeSetupData(),
                QueueSetupData    = new QueueSetupData
                {
                    AutoExpire        = 10000,
                    MessageTimeToLive = 10000000
                }
            };
        }
Exemple #3
0
        private void Publish <T>(T rabbit, string routingKey, IDictionary customHeaders)
        {
            lock (_tunnelGate)
            {
                EnsurePublishChannelIsCreated();
            }

            try
            {
                byte[] msgBody = _serializer.Serialize(rabbit);

                IBasicProperties properties = CreateBasicPropertiesForPublishing <T>();
                if (customHeaders != null)
                {
                    properties.Headers = new HybridDictionary();
                    foreach (var key in customHeaders.Keys)
                    {
                        if (key == null || customHeaders[key] == null)
                        {
                            continue;
                        }
                        properties.Headers.Add(key.ToString(), customHeaders[key].ToString());
                    }
                }

                var exchangeName = _routeFinder.FindExchangeName <T>();
                lock (_tunnelGate)
                {
                    _dedicatedPublishingChannel.BasicPublish(exchangeName, routingKey, properties, msgBody);
                }

                if (_watcher.IsDebugEnable)
                {
                    _watcher.DebugFormat("Published to {0}, CorrelationId {1}", exchangeName, properties.CorrelationId);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Publish failed: '{0}'", ex.Message), ex);
            }
        }
        public virtual void Publish <T>(T rabbit, string routingKey)
        {
            lock (_tunnelGate)
            {
                EnsurePublishChannelIsCreated();
            }

            try
            {
                byte[]           msgBody    = _serializer.Serialize(rabbit);
                IBasicProperties properties = CreateBasicPropertiesForPublish <T>();
                var exchangeName            = _routeFinder.FindExchangeName <T>();
                lock (_tunnelGate)
                {
                    _dedicatedPublishingChannel.BasicPublish(exchangeName, routingKey, properties, msgBody);
                }
                _watcher.DebugFormat("Published to {0}, CorrelationId {1}", exchangeName, properties.CorrelationId);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Publish failed: '{0}'", ex.Message), ex);
            }
        }