public void FuturePublish <T>(DateTime futurePublishDate, T message, string cancellationKey = null) where T : class
        {
            Preconditions.CheckNotNull(message, "message");
            var scheduleMeType      = typeof(ScheduleMe);
            var scheduleMeExchange  = publishExchangeDeclareStrategy.DeclareExchange(advancedBus, scheduleMeType, ExchangeType.Topic);
            var baseMessageType     = typeof(T);
            var concreteMessageType = message.GetType();
            var serializedMessage   = messageSerializationStrategy.SerializeMessage(new Message <T>(message)
            {
                Properties =
                {
                    DeliveryMode = messageDeliveryModeStrategy.GetDeliveryMode(concreteMessageType)
                }
            });
            var scheduleMe = new ScheduleMe
            {
                WakeTime          = futurePublishDate,
                CancellationKey   = cancellationKey,
                InnerMessage      = serializedMessage.Body,
                MessageProperties = serializedMessage.Properties,
                BindingKey        = typeNameSerializer.Serialize(typeof(T)),
                ExchangeType      = ExchangeType.Topic,
                Exchange          = conventions.ExchangeNamingConvention(baseMessageType),
                RoutingKey        = "#"
            };
            var easyNetQMessage = new Message <ScheduleMe>(scheduleMe)
            {
                Properties =
                {
                    DeliveryMode = messageDeliveryModeStrategy.GetDeliveryMode(scheduleMeType)
                }
            };

            advancedBus.Publish(scheduleMeExchange, conventions.TopicNamingConvention(scheduleMeType), false, easyNetQMessage);
        }
Exemple #2
0
        public void Should_declare_exchange_the_first_time_declare_is_called()
        {
            var declaredExchange = publishExchangeDeclareStrategy.DeclareExchange(advancedBus, exchangeName, ExchangeType.Topic);

            advancedBus.AssertWasCalled(x => x.ExchangeDeclare(exchangeName, "topic"));
            declaredExchange.ShouldBeTheSameAs(exchange);
            exchangeDeclareCount.ShouldEqual(1);
        }
Exemple #3
0
        public virtual void Publish <T>(T message, Action <IPublishConfiguration> configure) where T : class
        {
            Preconditions.CheckNotNull(message, "message");
            Preconditions.CheckNotNull(configure, "configure");

            var configuration = new PublishConfiguration(conventions.TopicNamingConvention(typeof(T)));

            configure(configuration);

            var messageType     = typeof(T);
            var easyNetQMessage = new Message <T>(message)
            {
                Properties =
                {
                    DeliveryMode = messageDeliveryModeStrategy.GetDeliveryMode(messageType)
                }
            };

            if (configuration.Priority != null)
            {
                easyNetQMessage.Properties.Priority = configuration.Priority.Value;
            }
            if (configuration.Expires != null)
            {
                easyNetQMessage.Properties.Expiration = configuration.Expires.ToString();
            }

            var exchange = publishExchangeDeclareStrategy.DeclareExchange(advancedBus, messageType, ExchangeType.Topic);

            advancedBus.Publish(exchange, configuration.Topic, false, easyNetQMessage);
        }
Exemple #4
0
        protected virtual void RequestPublish <TRequest>(TRequest request, string routingKey, string returnQueueName, Guid correlationId)
            where TRequest : class
        {
            var exchange       = publishExchangeDeclareStrategy.DeclareExchange(advancedBus, conventions.RpcExchangeNamingConvention(), ExchangeType.Direct);
            var requestType    = typeof(TRequest);
            var requestMessage = new Message <TRequest>(request)
            {
                Properties =
                {
                    ReplyTo       = returnQueueName,
                    CorrelationId = correlationId.ToString(),
                    Expiration    = (timeoutStrategy.GetTimeoutSeconds(requestType) * 1000).ToString(),
                    DeliveryMode  = messageDeliveryModeStrategy.GetDeliveryMode(requestType)
                }
            };

            advancedBus.Publish(exchange, routingKey, false, requestMessage);
        }
Exemple #5
0
 private IExchange DeclareRpcExchange(string exchangeName)
 {
     if (exchangeName != Exchange.GetDefault().Name)
     {
         return(publishExchangeDeclareStrategy.DeclareExchange(exchangeName, ExchangeType.Direct));
     }
     else
     {
         return(Exchange.GetDefault());
     }
 }
Exemple #6
0
        public void Publish <T>(T message, string topic) where T : class
        {
            GuardHelper.ArgumentNotNull(() => message);

            var         messageType   = typeof(T);
            Message <T> rabbitMessage = GetRabbitMessage(message, messageType);
            var         exchange      = publishExchangeDeclareStrategy.DeclareExchange(
                advancedBus, messageType, ExchangeType.Topic);

            advancedBus.Publish(exchange, topic, rabbitMessage);
        }
Exemple #7
0
        public Task PublishAsync <T>(T message, string topic) where T : class
        {
            Preconditions.CheckNotNull(message, "message");
            Preconditions.CheckNotNull(topic, "topic");

            var exchange        = publishExchangeDeclareStrategy.DeclareExchange(advancedBus, typeof(T), ExchangeType.Topic);
            var easyNetQMessage = new Message <T>(message);

            easyNetQMessage.Properties.DeliveryMode = (byte)(connectionConfiguration.PersistentMessages ? 2 : 1);

            return(advancedBus.PublishAsync(exchange, topic, false, false, easyNetQMessage));
        }
Exemple #8
0
        private void RequestPublish <TRequest>(TRequest request, string returnQueueName, Guid correlationId) where TRequest : class
        {
            var routingKey = conventions.RpcRoutingKeyNamingConvention(typeof(TRequest));
            var exchange   = publishExchangeDeclareStrategy.DeclareExchange(
                advancedBus, conventions.RpcExchangeNamingConvention(), ExchangeType.Direct);

            var requestMessage = new Message <TRequest>(request);

            requestMessage.Properties.ReplyTo       = returnQueueName;
            requestMessage.Properties.CorrelationId = correlationId.ToString();

            advancedBus.Publish(exchange, routingKey, false, false, requestMessage);
        }
Exemple #9
0
        public Task PublishAsync <T>(T message, string topic) where T : class
        {
            Preconditions.CheckNotNull(message, "message");
            Preconditions.CheckNotNull(topic, "topic");

            var exchangeName    = conventions.ExchangeNamingConvention(typeof(T));
            var exchange        = publishExchangeDeclareStrategy.DeclareExchange(advancedBus, exchangeName);
            var easyNetQMessage = new Message <T>(message);

            // by default publish persistent messages
            easyNetQMessage.Properties.DeliveryMode = 2;

            return(advancedBus.PublishAsync(exchange, topic, false, false, easyNetQMessage));
        }
Exemple #10
0
        public virtual void Publish <T>(T message, string topic) where T : class
        {
            Preconditions.CheckNotNull(message, "message");
            Preconditions.CheckNotNull(topic, "topic");
            var messageType     = typeof(T);
            var easyNetQMessage = new Message <T>(message)
            {
                Properties =
                {
                    DeliveryMode = messageDeliveryModeStrategy.GetDeliveryMode(messageType)
                }
            };
            var exchange = publishExchangeDeclareStrategy.DeclareExchange(advancedBus, messageType, ExchangeType.Topic);

            advancedBus.Publish(exchange, topic, false, easyNetQMessage);
        }
Exemple #11
0
        protected virtual void RequestPublish <TRequest>(TRequest request, string routingKey, string returnQueueName, Guid correlationId)
            where TRequest : class
        {
            var exchange = publishExchangeDeclareStrategy.DeclareExchange(
                advancedBus, conventions.RpcExchangeNamingConvention(), ExchangeType.Direct);

            var messageType    = typeof(TRequest);
            var requestMessage = new Message <TRequest>(request);

            requestMessage.Properties.ReplyTo       = returnQueueName;
            requestMessage.Properties.CorrelationId = correlationId.ToString();
            requestMessage.Properties.Expiration    = (configuration.Timeout * 1000).ToString();
            requestMessage.Properties.DeliveryMode  = (byte)(messageDeliveryModeStrategy.IsPersistent(messageType) ? 2 : 1);

            advancedBus.Publish(exchange, routingKey, false, false, requestMessage);
        }